change strike layout and add outlawed option
All checks were successful
delpoy / build-and-deploy (push) Successful in 1m21s

This commit is contained in:
2023-12-21 15:02:29 +01:00
parent 8a5eed787a
commit 2a9869ca7d
3 changed files with 43 additions and 74 deletions

View File

@ -1,6 +1,7 @@
import type { RequestHandler } from '@sveltejs/kit';
import { Strike, User } from '$lib/server/database';
import { Report, sequelize, StrikePunishment, StrikeReason, User } from '$lib/server/database';
import { env } from '$env/dynamic/private';
import { Op } from 'sequelize';
export const GET = (async ({ url }) => {
if (env.REPORT_SECRET && url.searchParams.get('secret') !== env.REPORT_SECRET)
@ -12,7 +13,28 @@ export const GET = (async ({ url }) => {
const user = await User.findOne({ where: { uuid: uuid } });
if (user == null) return new Response(null, { status: 400 });
const strike = await Strike.findOne({ where: { user_id: user.id } });
const query = (await Report.findOne({
where: { reported_id: user.id },
attributes: [
[sequelize.fn('SUM', sequelize.col('strike_reason.weight')), 'weight'],
'striked_at'
],
include: { model: StrikeReason, as: 'strike_reason' }
})) as { dataValues: { weight: number; striked_at: Date } } | null;
const ban_time = (
await StrikePunishment.findOne({
attributes: ['punishment_in_seconds'],
where: { type: ['ban'], weight: { [Op.lte]: query?.dataValues.weight } },
order: [['weight', 'DESC']]
})
)?.punishment_in_seconds;
const outlawed_time = (
await StrikePunishment.findOne({
attributes: ['punishment_in_seconds'],
where: { type: ['outlawed'], weight: { [Op.lte]: query?.dataValues.weight } },
order: [['weight', 'DESC']]
})
)?.punishment_in_seconds;
return new Response(
JSON.stringify({
@ -20,9 +42,14 @@ export const GET = (async ({ url }) => {
username: user.username,
firstname: user.firstname,
lastname: user.lastname,
banned:
new Date(new Date(Date.now()).toUTCString()) <
new Date((strike?.ban_until ?? new Date(0)).toUTCString())
banned_until:
query && ban_time
? Math.round(query.dataValues.striked_at.getTime() / 1000 + ban_time!)
: null,
outlawed_until:
query && outlawed_time
? Math.round(query.dataValues.striked_at.getTime() / 1000 + outlawed_time!)
: null
}),
{ status: 200 }
);