add option to create a report via the admin panel
All checks were successful
delpoy / build-and-deploy (push) Successful in 47s
All checks were successful
delpoy / build-and-deploy (push) Successful in 47s
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { getSession } from '$lib/server/session';
|
||||
import { Permissions } from '$lib/permissions';
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import { Admin, User } from '$lib/server/database';
|
||||
import { User } from '$lib/server/database';
|
||||
import { type Attributes, Op } from 'sequelize';
|
||||
|
||||
export const POST = (async ({ request, cookies }) => {
|
||||
if (getSession(cookies, { permissions: [Permissions.UserRead] }) == null) {
|
||||
@@ -10,11 +11,28 @@ export const POST = (async ({ request, cookies }) => {
|
||||
});
|
||||
}
|
||||
|
||||
const data = await request.json();
|
||||
const limit = data['limit'] || 100;
|
||||
const from = data['from'] || 0;
|
||||
const data: {
|
||||
limit: number | null;
|
||||
from: number | null;
|
||||
search: string | null;
|
||||
slim: boolean | null;
|
||||
} = await request.json();
|
||||
|
||||
const users = await User.findAll({ offset: from, limit: limit });
|
||||
const usersFindOptions: Attributes<User> = {};
|
||||
if (data.search) {
|
||||
Object.assign(usersFindOptions, {
|
||||
[Op.or]: {
|
||||
username: { [Op.like]: `%${data.search}%` },
|
||||
uuid: { [Op.like]: `%${data.search}%` }
|
||||
}
|
||||
});
|
||||
}
|
||||
const users = await User.findAll({
|
||||
where: usersFindOptions,
|
||||
attributes: data.slim ? ['username', 'uuid'] : undefined,
|
||||
offset: data.from || 0,
|
||||
limit: data.limit || 100
|
||||
});
|
||||
|
||||
return new Response(JSON.stringify(users));
|
||||
}) satisfies RequestHandler;
|
||||
|
||||
Reference in New Issue
Block a user