mirror of
https://github.com/filecoin-project/slate.git
synced 2024-09-11 22:07:08 +03:00
fixed bug with removing from slates already deleted
This commit is contained in:
parent
a20f2d9967
commit
d13e480e1a
@ -1,3 +1,5 @@
|
||||
import * as Data from "~/node_common/data";
|
||||
|
||||
import { runQuery } from "~/node_common/data/utilities";
|
||||
|
||||
export default async ({ slateId }) => {
|
||||
@ -5,15 +7,19 @@ export default async ({ slateId }) => {
|
||||
label: "RECALC_SLATE_FILECOUNT",
|
||||
queryFn: async (DB) => {
|
||||
const fileCountFields = ["id", "slate_files", "slateId", slateId];
|
||||
const fileCount = `(SELECT COUNT(??) FROM ?? WHERE ?? = ?)`;
|
||||
|
||||
const updateFields = ["slates", "fileCount", ...fileCountFields, "id", slateId];
|
||||
const update = await DB.raw(
|
||||
`UPDATE ?? SET ?? = ${fileCount} WHERE ?? = ? RETURNING *`,
|
||||
updateFields
|
||||
const selectFileCount = await DB.raw(
|
||||
`SELECT COUNT(??) FROM ?? WHERE ?? = ?`,
|
||||
fileCountFields
|
||||
);
|
||||
|
||||
return true;
|
||||
const fileCount = Number.parseInt(selectFileCount.rows[0].count);
|
||||
if (fileCount === 0) {
|
||||
await Data.deleteSlateById({ id: slateId });
|
||||
return true;
|
||||
} else {
|
||||
const updateFields = ["slates", "fileCount", fileCount, "id", slateId];
|
||||
const update = await DB.raw(`UPDATE ?? SET ?? = ? WHERE ?? = ? RETURNING *`, updateFields);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
errorFn: async (e) => {
|
||||
return {
|
||||
|
@ -51,6 +51,9 @@ export default async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
//NOTE(martina): if slate was auto-deleted b/c there were no files left in it, updatedSlate will be null
|
||||
let updatedSlate = await Data.getSlateById({ id: req.body.data.slateId });
|
||||
|
||||
if (slate.isPublic) {
|
||||
let updatedFiles = await Utilities.removeFromPublicCollectionUpdatePrivacy({
|
||||
files: slate.objects,
|
||||
@ -60,26 +63,30 @@ export default async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
Utilities.removeFromSlateCheckCoverImage(slate, fileIds);
|
||||
|
||||
if (fileIds.length >= slate.objects.length) {
|
||||
let updatedSlate = await Data.getSlateById({ id: req.body.data.slateId, includeFiles: true });
|
||||
|
||||
if (!updatedSlate.objects.length) {
|
||||
const deleteResponse = await Data.deleteSlateById({ id: slate.id });
|
||||
|
||||
if (!deleteResponse) {
|
||||
return res.status(404).send({ decorator: "SERVER_DELETE_SLATE_FAILED", error: true });
|
||||
}
|
||||
|
||||
if (deleteResponse.error) {
|
||||
return res.status(500).send({ decorator: "SERVER_DELETE_SLATE_FAILED", error: true });
|
||||
}
|
||||
|
||||
SearchManager.deleteSlate(slate);
|
||||
}
|
||||
if (updatedSlate) {
|
||||
Utilities.removeFromSlateCheckCoverImage(slate, fileIds);
|
||||
} else {
|
||||
SearchManager.deleteSlate(slate);
|
||||
}
|
||||
|
||||
// if (fileIds.length >= slate.objects.length) {
|
||||
// let updatedSlate = await Data.getSlateById({ id: req.body.data.slateId, includeFiles: true });
|
||||
|
||||
// if (!updatedSlate.objects.length) {
|
||||
// const deleteResponse = await Data.deleteSlateById({ id: slate.id });
|
||||
|
||||
// if (!deleteResponse) {
|
||||
// return res.status(404).send({ decorator: "SERVER_DELETE_SLATE_FAILED", error: true });
|
||||
// }
|
||||
|
||||
// if (deleteResponse.error) {
|
||||
// return res.status(500).send({ decorator: "SERVER_DELETE_SLATE_FAILED", error: true });
|
||||
// }
|
||||
|
||||
// SearchManager.deleteSlate(slate);
|
||||
// }
|
||||
// }
|
||||
|
||||
ViewerManager.hydratePartial(id, { slates: true });
|
||||
|
||||
return res.status(200).send({
|
||||
|
Loading…
Reference in New Issue
Block a user