From ae4a7d7166aa5d3e43d5b79fd69099f45974b8c8 Mon Sep 17 00:00:00 2001 From: hmacr Date: Thu, 16 Jan 2025 07:47:26 +0530 Subject: [PATCH] handle reactions --- server/models/Reaction.ts | 6 +++--- server/routes/api/comments/comments.ts | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/server/models/Reaction.ts b/server/models/Reaction.ts index 119ea47ce8..51f7905be1 100644 --- a/server/models/Reaction.ts +++ b/server/models/Reaction.ts @@ -18,10 +18,10 @@ import { Table, } from "sequelize-typescript"; import { createContext } from "@server/context"; +import { APIContext } from "@server/types"; import Comment from "./Comment"; import User from "./User"; import IdModel from "./base/IdModel"; -import { type HookContext } from "./base/Model"; import Fix from "./decorators/Fix"; import Length from "./validators/Length"; @@ -57,7 +57,7 @@ class Reaction extends IdModel< @AfterCreate public static async addReactionToCommentCache( model: Reaction, - ctx: HookContext & + ctx: APIContext["context"] & FindOrCreateOptions, CreationAttributes> ) { const { transaction } = ctx; @@ -109,7 +109,7 @@ class Reaction extends IdModel< @AfterDestroy public static async removeReactionFromCommentCache( model: Reaction, - ctx: HookContext & InstanceDestroyOptions + ctx: APIContext["context"] & InstanceDestroyOptions ) { const { transaction } = ctx; diff --git a/server/routes/api/comments/comments.ts b/server/routes/api/comments/comments.ts index 916732bfcf..89aec024c6 100644 --- a/server/routes/api/comments/comments.ts +++ b/server/routes/api/comments/comments.ts @@ -375,12 +375,13 @@ router.post( authorize(user, "comment", document); authorize(user, "addReaction", comment); - await Reaction.findOrCreateWithCtx(ctx, { + await Reaction.findOrCreate({ where: { emoji, userId: user.id, commentId: id, }, + ...ctx.context, }); ctx.body = { @@ -423,7 +424,7 @@ router.post( }); authorize(user, "delete", reaction); - await reaction.destroyWithCtx(ctx); + await reaction.destroy(ctx.context); ctx.body = { success: true,