slate/pages/api/support-message.js

58 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-09-17 02:26:15 +03:00
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) => {
2021-05-06 03:08:14 +03:00
// const id = Utilities.getIdFromCookie(req);
// if (!id) {
// return res.status(401).send({ decorator: "SERVER_NOT_AUTHENTICATED", error: true });
// }
2020-09-17 02:26:15 +03:00
2021-05-06 03:08:14 +03:00
// const user = await Data.getUserById({
// id,
// });
2020-09-17 02:26:15 +03:00
2021-05-06 03:08:14 +03:00
// if (!user) {
// return res.status(404).send({ decorator: "SERVER_USER_NOT_FOUND", error: true });
// }
2020-09-17 02:26:15 +03:00
2021-05-06 03:08:14 +03:00
// if (user.error) {
// return res.status(500).send({ decorator: "SERVER_USER_NOT_FOUND", error: true });
// }
2020-09-17 02:26:15 +03:00
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,
});
}
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,
});
}
};