Deleting a collection should detach associated drafts from it (#5082)

Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
Apoorv Mishra
2023-04-24 00:50:44 +05:30
committed by GitHub
parent 7250c0ed64
commit 86062f396d
39 changed files with 363 additions and 112 deletions

View File

@@ -18,7 +18,7 @@ describe("documents.publish", () => {
await processor.perform({
name: "documents.publish",
documentId: document.id,
collectionId: document.collectionId,
collectionId: document.collectionId!,
teamId: document.teamId,
actorId: document.createdById,
data: { title: document.title },
@@ -46,7 +46,7 @@ describe("documents.publish", () => {
await processor.perform({
name: "documents.publish",
documentId: document.id,
collectionId: document.collectionId,
collectionId: document.collectionId!,
teamId: document.teamId,
actorId: document.createdById,
data: { title: document.title },
@@ -72,7 +72,7 @@ describe("documents.update", () => {
await processor.perform({
name: "documents.update",
documentId: document.id,
collectionId: document.collectionId,
collectionId: document.collectionId!,
teamId: document.teamId,
actorId: document.createdById,
createdAt: new Date().toISOString(),
@@ -100,7 +100,7 @@ describe("documents.update", () => {
await processor.perform({
name: "documents.update",
documentId: document.id,
collectionId: document.collectionId,
collectionId: document.collectionId!,
teamId: document.teamId,
actorId: document.createdById,
createdAt: new Date().toISOString(),
@@ -125,7 +125,7 @@ describe("documents.update", () => {
await processor.perform({
name: "documents.update",
documentId: document.id,
collectionId: document.collectionId,
collectionId: document.collectionId!,
teamId: document.teamId,
actorId: document.createdById,
createdAt: new Date().toISOString(),
@@ -153,7 +153,7 @@ describe("documents.update", () => {
await processor.perform({
name: "documents.publish",
documentId: document.id,
collectionId: document.collectionId,
collectionId: document.collectionId!,
teamId: document.teamId,
actorId: document.createdById,
data: { title: document.title },
@@ -167,7 +167,7 @@ describe("documents.update", () => {
await processor.perform({
name: "documents.update",
documentId: document.id,
collectionId: document.collectionId,
collectionId: document.collectionId!,
teamId: document.teamId,
actorId: document.createdById,
createdAt: new Date().toISOString(),
@@ -195,7 +195,7 @@ describe("documents.delete", () => {
await processor.perform({
name: "documents.update",
documentId: document.id,
collectionId: document.collectionId,
collectionId: document.collectionId!,
teamId: document.teamId,
actorId: document.createdById,
createdAt: new Date().toISOString(),
@@ -206,7 +206,7 @@ describe("documents.delete", () => {
await processor.perform({
name: "documents.delete",
documentId: document.id,
collectionId: document.collectionId,
collectionId: document.collectionId!,
teamId: document.teamId,
actorId: document.createdById,
data: { title: document.title },

View File

@@ -0,0 +1,23 @@
import { CollectionEvent, Event } from "@server/types";
import DetachDraftsFromCollectionTask from "../tasks/DetachDraftsFromCollectionTask";
import BaseProcessor from "./BaseProcessor";
export default class CollectionsProcessor extends BaseProcessor {
static applicableEvents: Event["name"][] = ["collections.delete"];
async perform(event: CollectionEvent) {
switch (event.name) {
case "collections.delete":
return this.collectionDeleted(event);
default:
}
}
async collectionDeleted(event: CollectionEvent) {
await DetachDraftsFromCollectionTask.schedule({
collectionId: event.collectionId,
actorId: event.actorId,
ip: event.ip,
});
}
}

View File

@@ -15,7 +15,7 @@ describe("documents.update.debounced", () => {
await processor.perform({
name: "documents.update.debounced",
documentId: document.id,
collectionId: document.collectionId,
collectionId: document.collectionId!,
teamId: document.teamId,
actorId: document.createdById,
createdAt: new Date().toISOString(),
@@ -38,7 +38,7 @@ describe("documents.update.debounced", () => {
await processor.perform({
name: "documents.update.debounced",
documentId: document.id,
collectionId: document.collectionId,
collectionId: document.collectionId!,
teamId: document.teamId,
actorId: document.createdById,
createdAt: new Date().toISOString(),