slate/pages/api/support-message.js

70 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-09-17 02:26:15 +03:00
import * as Environment from "~/node_common/environment";
import * as Data from "~/node_common/data";
import * as Utilities from "~/node_common/utilities";
import * as Serializers from "~/node_common/serializers";
import * as Support from "~/node_common/support";
export default async (req, res) => {
const id = Utilities.getIdFromCookie(req);
if (!id) {
return res.status(500).send({ decorator: "SERVER_SUPPORT", error: true });
}
const user = await Data.getUserById({
id,
});
if (!user) {
return res
.status(404)
.send({ decorator: "SERVER_SUPPORT_USER_NOT_FOUND", error: true });
}
if (user.error) {
return res
.status(500)
.send({ decorator: "SERVER_SUPPORT_USER_NOT_FOUND", error: true });
}
if (!req.body.data) {
return res.status(500).send({
decorator: "SERVER_SUPPORT_NO_DATA_PROVIDED",
error: true,
});
}
if (!req.body.data.email) {
return res.status(500).send({
decorator: "SERVER_SUPPORT_MUST_PROVIDE_EMAIL",
error: true,
});
}
if (!req.body.data.message) {
return res.status(500).send({
decorator: "SERVER_SUPPORT_MUST_PROVIDE_MESSAGE",
error: true,
});
}
if (!req.body.data.username) {
return res.status(500).send({
decorator: "SERVER_SUPPORT_NO_DATA_PROVIDED",
error: true,
});
}
let status = await Support.sendSlackMessage(req.body.data);
if (status) {
return res.status(200).send({
decorator: "SERVER_SUPPORT",
data: true,
});
} else {
return res.status(500).send({
decorator: "SERVER_SUPPORT",
error: true,
});
}
};