2020-08-07 05:17:49 +03:00
|
|
|
import * as Utilities from "~/node_common/utilities";
|
|
|
|
import * as Data from "~/node_common/data";
|
|
|
|
import * as Strings from "~/common/strings";
|
|
|
|
|
|
|
|
export default async (req, res) => {
|
|
|
|
const id = Utilities.getIdFromCookie(req);
|
|
|
|
if (!id) {
|
|
|
|
return res
|
|
|
|
.status(500)
|
2020-09-03 03:21:29 +03:00
|
|
|
.send({ decorator: "SERVER_DELETE_SLATE", error: true });
|
2020-08-07 05:17:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const user = await Data.getUserById({
|
|
|
|
id,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!user) {
|
2020-09-03 03:21:29 +03:00
|
|
|
return res.status(404).send({
|
2020-08-07 05:17:49 +03:00
|
|
|
decorator: "SERVER_DELETE_SLATE_USER_NOT_FOUND",
|
|
|
|
error: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user.error) {
|
2020-09-03 03:21:29 +03:00
|
|
|
return res.status(500).send({
|
2020-08-07 05:17:49 +03:00
|
|
|
decorator: "SERVER_DELETE_SLATE_USER_NOT_FOUND",
|
|
|
|
error: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const slate = await Data.getSlateById({ id: req.body.data.id });
|
|
|
|
|
|
|
|
if (!slate) {
|
|
|
|
return res
|
|
|
|
.status(404)
|
2020-09-03 03:21:29 +03:00
|
|
|
.send({ decorator: "SERVER_DELETE_SLATE_SLATE_NOT_FOUND", error: true });
|
2020-08-07 05:17:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (slate.error) {
|
|
|
|
return res
|
|
|
|
.status(500)
|
2020-09-03 03:21:29 +03:00
|
|
|
.send({ decorator: "SERVER_DELETE_SLATE_SLATE_NOT_FOUND", error: true });
|
2020-08-07 05:17:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const deleteResponse = await Data.deleteSlateById({ id: slate.id });
|
|
|
|
|
|
|
|
if (!deleteResponse) {
|
|
|
|
return res
|
|
|
|
.status(404)
|
2020-09-03 03:21:29 +03:00
|
|
|
.send({ decorator: "SERVER_DELETE_SLATE", error: true });
|
2020-08-07 05:17:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (deleteResponse.error) {
|
|
|
|
return res
|
|
|
|
.status(500)
|
2020-09-03 03:21:29 +03:00
|
|
|
.send({ decorator: "SERVER_DELETE_SLATE", error: true });
|
2020-08-07 05:17:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
.status(200)
|
2020-09-03 03:21:29 +03:00
|
|
|
.send({ decorator: "SERVER_DELETE_SLATE", error: false });
|
2020-08-07 05:17:49 +03:00
|
|
|
};
|