Files
outline/server/queues/processors/CollectionsProcessor.ts
codegen-sh[bot]andTom Moor a226889143 Update task scheduling to use instance method (#9092)
* Update task scheduling to use instance method

* Delete update_task_schedule.sh

* Applied automatic fixes

* tsc

---------

Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
Co-authored-by: Tom Moor <tom@getoutline.com>
2025-04-29 06:47:51 -04:00

46 lines
1.3 KiB
TypeScript

import teamUpdater from "@server/commands/teamUpdater";
import { Team, User } from "@server/models";
import { sequelize } from "@server/storage/database";
import { Event as TEvent, CollectionEvent } from "@server/types";
import DetachDraftsFromCollectionTask from "../tasks/DetachDraftsFromCollectionTask";
import BaseProcessor from "./BaseProcessor";
export default class CollectionsProcessor extends BaseProcessor {
static applicableEvents: TEvent["name"][] = [
"collections.delete",
"collections.archive",
];
async perform(event: CollectionEvent) {
await new DetachDraftsFromCollectionTask().schedule({
collectionId: event.collectionId,
actorId: event.actorId,
ip: event.ip,
});
await sequelize.transaction(async (transaction) => {
const team = await Team.findByPk(event.teamId, {
rejectOnEmpty: true,
transaction,
lock: transaction.LOCK.UPDATE,
});
if (team?.defaultCollectionId === event.collectionId) {
const user = await User.findByPk(event.actorId, {
rejectOnEmpty: true,
paranoid: false,
transaction,
});
await teamUpdater({
params: { defaultCollectionId: null },
user,
team,
transaction,
ip: event.ip,
});
}
});
}
}