minecraft-docker/backend/src/routes/user/get.ts

12 lines
480 B
TypeScript

import { FastifyInstance } from 'fastify';
export default async (server: FastifyInstance) =>
server.get<{ Params: { id: string } }>('/:id', (req, reply) =>
server.db.user
.findFirstOrThrow({ where: { id: req.params.id }, select: {} })
.then(user => reply.send(user))
.catch(() => server.db.user.findFirstOrThrow({ where: { nickname: req.params.id } }))
.then(user => reply.send(user))
.catch(() => reply.code(404).send('User not found'))
);