exploring/fighting is functional
[sketchy-heroes.git] / src / routes / player / info.ts
1 import { server } from '../../lib/server';
2 import { Static, Type } from '@sinclair/typebox';
3 import { prisma } from '../../lib/db';
4 import { ForbiddenError } from '../../lib/http-errors';
5 import {Player} from '@prisma/client';
6
7 const PlayerInput = Type.Object({
8   params: Type.Object({
9     playerId: Type.String()
10   })
11 });
12
13 type PlayerInputType = Static<typeof PlayerInput>;
14
15 export const playerInfo = server.get<PlayerInputType, Player>('/v1/accounts/:playerId', {
16   schema: PlayerInput,
17   authenicated: true
18 }, async req => {
19   const player = await prisma.player.findUnique({
20     where: {
21       id: req.params.playerId
22     }
23   });
24
25   if(!player) {
26     throw new ForbiddenError('Not allowed');
27   }
28
29   return player;
30 });