feat: Allow deletion of imports (#5907)
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user