exploring/fighting is functional
[sketchy-heroes.git] / src / routes / player / info.ts
diff --git a/src/routes/player/info.ts b/src/routes/player/info.ts
new file mode 100644 (file)
index 0000000..06e1ddc
--- /dev/null
@@ -0,0 +1,30 @@
+import { server } from '../../lib/server';
+import { Static, Type } from '@sinclair/typebox';
+import { prisma } from '../../lib/db';
+import { ForbiddenError } from '../../lib/http-errors';
+import {Player} from '@prisma/client';
+
+const PlayerInput = Type.Object({
+  params: Type.Object({
+    playerId: Type.String()
+  })
+});
+
+type PlayerInputType = Static<typeof PlayerInput>;
+
+export const playerInfo = server.get<PlayerInputType, Player>('/v1/accounts/:playerId', {
+  schema: PlayerInput,
+  authenicated: true
+}, async req => {
+  const player = await prisma.player.findUnique({
+    where: {
+      id: req.params.playerId
+    }
+  });
+
+  if(!player) {
+    throw new ForbiddenError('Not allowed');
+  }
+
+  return player;
+});