mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
5a14944d0c
* Initial plan * Add DocumentArchivedProcessor to remove archived documents from actor's stars Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Fix unused variable in test Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Remove unnecessary transaction wrapper for single operation Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Add JSDoc documentation to perform method Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Address code review: add @throws annotation and fix spacing Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Fix TypeScript errors in test file - add non-null assertions for collectionId Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Use ctx method for events --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com>
31 lines
1012 B
TypeScript
31 lines
1012 B
TypeScript
import { createContext } from "@server/context";
|
|
import { Star, User } from "@server/models";
|
|
import type { DocumentEvent, Event } from "@server/types";
|
|
import BaseProcessor from "./BaseProcessor";
|
|
|
|
export default class DocumentArchivedProcessor extends BaseProcessor {
|
|
static applicableEvents: Event["name"][] = ["documents.archive"];
|
|
|
|
/**
|
|
* Performs the processor action when a document is archived.
|
|
* Removes the document from the actor's starred documents.
|
|
*
|
|
* @param event The document archive event.
|
|
* @returns A promise that resolves when the operation is complete.
|
|
* @throws {Error} If the database operation fails.
|
|
*/
|
|
async perform(event: DocumentEvent) {
|
|
const star = await Star.findOne({
|
|
where: {
|
|
documentId: event.documentId,
|
|
userId: event.actorId,
|
|
},
|
|
});
|
|
|
|
if (star) {
|
|
const user = await User.findByPk(event.actorId, { rejectOnEmpty: true });
|
|
await star.destroyWithCtx(createContext({ user, ip: event.ip }));
|
|
}
|
|
}
|
|
}
|