mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 08:07:12 +01:00
Convert /api/users.
This commit is contained in:
parent
090abcff81
commit
baa3851fb4
61 changed files with 1064 additions and 70 deletions
29
src/app/api/users/[userId]/websites/route.ts
Normal file
29
src/app/api/users/[userId]/websites/route.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { z } from 'zod';
|
||||
import { unauthorized, json, badRequest } from 'lib/response';
|
||||
import { getUserWebsites } from 'queries/prisma/website';
|
||||
import { pagingParams } from 'lib/schema';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { checkAuth } from 'lib/auth';
|
||||
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
export async function GET(request: Request, { params }: { params: Promise<{ userId: string }> }) {
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { userId } = await params;
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || (!auth.user.isAdmin && auth.user.id !== userId)) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const websites = await getUserWebsites(userId, query);
|
||||
|
||||
return json(websites);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue