Compare commits

..

2 Commits

Author SHA1 Message Date
3dd56bc471 fix strike date not set if status changed but strike reason not
All checks were successful
delpoy / build-and-deploy (push) Successful in 40s
2024-12-20 20:56:38 +01:00
8e60f83b6f fix crashing webhook sending 2024-12-20 20:46:48 +01:00

View File

@ -50,12 +50,7 @@ export const POST = (async ({ request, cookies }) => {
let reports = await Report.findAll({
where: reportFindOptions,
include: [
{ model: User, as: 'reporter' },
{ model: User, as: 'reported' },
{ model: Admin, as: 'auditor' },
{ model: StrikeReason, as: 'strike_reason' }
],
include: [{ all: true }],
order: [['created_at', 'DESC']],
offset: data.from || 0,
limit: data.limit || 100
@ -139,7 +134,10 @@ export const PATCH = (async ({ request, cookies }) => {
} else if (data.strike_reason == -1 && report.strike_reason_id != null) {
report.strike_reason_id = null;
report.striked_at = null;
} else if (data.strike_reason != -1 && data.strike_reason != report.strike_reason_id) {
} else if (
data.strike_reason != -1 &&
(data.strike_reason != report.strike_reason_id || data.status != report.status)
) {
if (!report.reported_id) return new Response(null, { status: 400 });
const strike_reason = await StrikeReason.findByPk(data.strike_reason);
if (strike_reason == null) return new Response(null, { status: 400 });
@ -153,12 +151,10 @@ export const PATCH = (async ({ request, cookies }) => {
if (webhookTriggerUsers.length > 0 && data.status == 'reviewed' && env.REPORTED_WEBHOOK) {
for (const webhookTriggerUser of webhookTriggerUsers) {
try {
// no `await` to avoid blocking
webhookUserReported(env.REPORTED_WEBHOOK, webhookTriggerUser);
} catch (e) {
console.error(`failed to send reported webhook: ${e}`);
}
// no `await` to avoid blocking
webhookUserReported(env.REPORTED_WEBHOOK, webhookTriggerUser).catch((e) =>
console.error(`failed to send reported webhook: ${e}`)
);
}
}