Deleting a collection should detach associated drafts from it (#5082)
Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@@ -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 },
|
||||
|
||||
23
server/queues/processors/CollectionsProcessor.ts
Normal file
23
server/queues/processors/CollectionsProcessor.ts
Normal 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,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user