slate/node_common/data/methods/delete-slate-files.js
2021-10-02 14:38:54 -07:00

36 lines
851 B
JavaScript

import * as Data from "~/node_common/data";
import { runQuery } from "~/node_common/data/utilities";
export default async ({ slateId, ids }) => {
return await runQuery({
label: "DELETE_SLATE_FILES",
queryFn: async (DB) => {
const slateFiles = await DB("slate_files")
.where("slateId", slateId)
.whereIn("fileId", ids)
.del()
.returning("*");
for (let id of ids) {
await Data.updateFileTags({ fileId: id });
}
const activityQuery = await DB("activity")
.where({ slateId, type: "CREATE_SLATE_OBJECT" })
.whereIn("fileId", ids)
.del();
await Data.recalcSlateFilecount({ slateId });
return slateFiles;
},
errorFn: async (e) => {
return {
error: true,
decorator: "DELETE_SLATE_FILES",
};
},
});
};