(fastify: FastifyInstance)
| 6 | import { prisma } from "../prisma"; |
| 7 | |
| 8 | export function userRoutes(fastify: FastifyInstance) { |
| 9 | // All users |
| 10 | fastify.get( |
| 11 | "/api/v1/users/all", |
| 12 | |
| 13 | async (request: FastifyRequest, reply: FastifyReply) => { |
| 14 | const users = await prisma.user.findMany({ |
| 15 | where: { |
| 16 | external_user: false, |
| 17 | }, |
| 18 | select: { |
| 19 | id: true, |
| 20 | name: true, |
| 21 | email: true, |
| 22 | isAdmin: true, |
| 23 | createdAt: true, |
| 24 | updatedAt: true, |
| 25 | language: true, |
| 26 | }, |
| 27 | }); |
| 28 | |
| 29 | reply.send({ |
| 30 | users, |
| 31 | success: true, |
| 32 | }); |
| 33 | } |
| 34 | ); |
| 35 | |
| 36 | // New user |
| 37 | fastify.post( |
| 38 | "/api/v1/user/new", |
| 39 | |
| 40 | async (request: FastifyRequest, reply: FastifyReply) => { |
| 41 | const session = await checkSession(request); |
| 42 | |
| 43 | if (session!.isAdmin) { |
| 44 | const { email, password, name, admin }: any = request.body; |
| 45 | |
| 46 | const e = email.toLowerCase(); |
| 47 | |
| 48 | const hash = await bcrypt.hash(password, 10); |
| 49 | |
| 50 | await prisma.user.create({ |
| 51 | data: { |
| 52 | name, |
| 53 | email: e, |
| 54 | password: hash, |
| 55 | isAdmin: admin, |
| 56 | }, |
| 57 | }); |
| 58 | |
| 59 | const client = track(); |
| 60 | |
| 61 | client.capture({ |
| 62 | event: "user_created", |
| 63 | distinctId: "uuid", |
| 64 | }); |
| 65 |
no test coverage detected