Files
outline/server/queues/tasks/DetachDraftsFromCollectionTask.ts
T
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

54 lines
1.2 KiB
TypeScript

import { Op } from "sequelize";
import documentMover from "@server/commands/documentMover";
import { Collection, Document, User } from "@server/models";
import { sequelize } from "@server/storage/database";
import BaseTask from "./BaseTask";
type Props = {
collectionId: string;
actorId: string;
ip: string | null;
};
export default class DetachDraftsFromCollectionTask extends BaseTask<Props> {
async perform(props: Props) {
const [collection, actor] = await Promise.all([
Collection.findByPk(props.collectionId, {
paranoid: false,
}),
User.findByPk(props.actorId),
]);
if (
!actor ||
!collection ||
!(collection.deletedAt || collection.archivedAt)
) {
return;
}
const documents = await Document.scope("withDrafts").findAll({
where: {
collectionId: props.collectionId,
template: false,
publishedAt: {
[Op.is]: null,
},
},
paranoid: false,
});
return sequelize.transaction(async (transaction) => {
for (const document of documents) {
await documentMover({
document,
user: actor,
ip: props.ip,
collectionId: null,
transaction,
});
}
});
}
}