diff --git a/src/actions/report.ts b/src/actions/report.ts index a33c21a..4f89ed0 100644 --- a/src/actions/report.ts +++ b/src/actions/report.ts @@ -189,29 +189,29 @@ export const report = { Session.actionSessionFromCookies(context.cookies, Permissions.Reports); const report = await db.getReportById({ id: input.reportId }); + const strike = await db.getStrikeByReportId({ reportId: input.reportId }); let reportCreatedAt = undefined; if (input.status !== null && report.createdAt === null) reportCreatedAt = new Date(); - let preReportStrike; - if (input.status === 'closed') preReportStrike = await db.getStrikeByReportId({ reportId: input.reportId }); - await db.transaction(async (tx) => { if (reportCreatedAt) await tx.editReport({ id: input.reportId, createdAt: reportCreatedAt }); await tx.editReportStatus(input); - if (input.strikeReasonId) { - await db.editStrike({ - reportId: input.reportId, - strikeReasonId: input.strikeReasonId - }); - } else { - await db.deleteStrike({ reportId: input.reportId }); + if (strike?.strikeReason?.id != input.strikeReasonId) { + if (input.strikeReasonId) { + await db.editStrike({ + reportId: input.reportId, + strikeReasonId: input.strikeReasonId + }); + } else { + await db.deleteStrike({ reportId: input.reportId }); + } } }); - if (input.status === 'closed' && preReportStrike?.strikeReason?.id != input.strikeReasonId) { + if (input.status === 'closed' && strike?.strikeReason?.id != input.strikeReasonId) { if (report.reported) { const user = await db.getUserById({ id: report.reported.id });