feat: Allow deletion of imports (#5907)

This commit is contained in:
Tom Moor
2023-10-01 21:24:50 -04:00
committed by GitHub
parent 16cd82a732
commit e7b7032284
24 changed files with 304 additions and 184 deletions

View File

@@ -29,6 +29,7 @@ import {
Scopes,
DataType,
Length as SimpleLength,
BeforeDestroy,
} from "sequelize-typescript";
import isUUID from "validator/lib/isUUID";
import type { CollectionSort } from "@shared/types";
@@ -37,6 +38,7 @@ import { sortNavigationNodes } from "@shared/utils/collections";
import slugify from "@shared/utils/slugify";
import { SLUG_URL_REGEX } from "@shared/utils/urlHelpers";
import { CollectionValidation } from "@shared/validations";
import { ValidationError } from "@server/errors";
import Document from "./Document";
import FileOperation from "./FileOperation";
import Group from "./Group";
@@ -265,6 +267,18 @@ class Collection extends ParanoidModel {
}
}
@BeforeDestroy
static async checkLastCollection(model: Collection) {
const total = await this.count({
where: {
teamId: model.teamId,
},
});
if (total === 1) {
throw ValidationError("Cannot delete last collection");
}
}
@AfterDestroy
static async onAfterDestroy(model: Collection) {
await Document.destroy({