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";
|
2020-10-31 02:12:20 +03:00
|
|
|
import * as ViewerManager from "~/node_common/managers/viewer";
|
2021-11-01 23:38:47 +03:00
|
|
|
import SearchManager from "~/node_common/managers/search";
|
2021-07-14 01:52:21 +03:00
|
|
|
import * as RequestUtilities from "~/node_common/request-utilities";
|
2020-08-07 05:17:49 +03:00
|
|
|
|
|
|
|
export default async (req, res) => {
|
2021-07-14 01:52:21 +03:00
|
|
|
const userInfo = await RequestUtilities.checkAuthorizationInternal(req, res);
|
|
|
|
if (!userInfo) return;
|
|
|
|
const { id, user } = userInfo;
|
2020-08-07 05:17:49 +03:00
|
|
|
|
2021-03-07 23:53:54 +03:00
|
|
|
const slate = await Data.getSlateById({ id: req.body.data.id, includeFiles: true });
|
2020-08-07 05:17:49 +03:00
|
|
|
|
|
|
|
if (!slate) {
|
2020-10-29 21:39:40 +03:00
|
|
|
return res.status(404).send({ decorator: "SERVER_DELETE_SLATE_SLATE_NOT_FOUND", error: true });
|
2020-08-07 05:17:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (slate.error) {
|
2020-10-29 21:39:40 +03:00
|
|
|
return res.status(500).send({ decorator: "SERVER_DELETE_SLATE_SLATE_NOT_FOUND", error: true });
|
2020-08-07 05:17:49 +03:00
|
|
|
}
|
|
|
|
|
2021-10-13 23:39:01 +03:00
|
|
|
if (slate.ownerId !== id) {
|
|
|
|
return res.status(403).send({ decorator: "SERVER_DELETE_SLATE_NOT_ALLOWED", error: true });
|
|
|
|
}
|
|
|
|
|
2020-08-07 05:17:49 +03:00
|
|
|
const deleteResponse = await Data.deleteSlateById({ id: slate.id });
|
|
|
|
|
|
|
|
if (!deleteResponse) {
|
2021-03-07 23:53:54 +03:00
|
|
|
return res.status(404).send({ decorator: "SERVER_DELETE_SLATE_FAILED", error: true });
|
2020-08-07 05:17:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (deleteResponse.error) {
|
2021-03-07 23:53:54 +03:00
|
|
|
return res.status(500).send({ decorator: "SERVER_DELETE_SLATE_FAILED", error: true });
|
2020-08-07 05:17:49 +03:00
|
|
|
}
|
|
|
|
|
2021-03-07 23:53:54 +03:00
|
|
|
ViewerManager.hydratePartial(id, { slates: true });
|
|
|
|
|
2021-10-19 00:06:27 +03:00
|
|
|
SearchManager.deleteSlate(slate);
|
2021-03-07 23:53:54 +03:00
|
|
|
|
|
|
|
if (slate.isPublic) {
|
2021-11-03 20:56:42 +03:00
|
|
|
let updatedFiles = await Utilities.removeFromPublicCollectionUpdatePrivacy({
|
|
|
|
files: slate.objects,
|
|
|
|
});
|
|
|
|
SearchManager.updateFile(updatedFiles);
|
2020-11-10 00:20:38 +03:00
|
|
|
}
|
|
|
|
|
2020-10-29 21:39:40 +03:00
|
|
|
return res.status(200).send({ decorator: "SERVER_DELETE_SLATE", error: false });
|
2020-08-07 05:17:49 +03:00
|
|
|
};
|