(fastify: FastifyInstance)
| 3 | import { prisma } from "../prisma"; |
| 4 | |
| 5 | export function dataRoutes(fastify: FastifyInstance) { |
| 6 | // Get total count of all tickets |
| 7 | fastify.get( |
| 8 | "/api/v1/data/tickets/all", |
| 9 | { |
| 10 | preHandler: requirePermission(["issue::read"]), |
| 11 | }, |
| 12 | async (request: FastifyRequest, reply: FastifyReply) => { |
| 13 | const result = await prisma.ticket.count({ |
| 14 | where: { hidden: false }, |
| 15 | }); |
| 16 | |
| 17 | reply.send({ count: result }); |
| 18 | } |
| 19 | ); |
| 20 | |
| 21 | // Get total count of all completed tickets |
| 22 | fastify.get( |
| 23 | "/api/v1/data/tickets/completed", |
| 24 | { |
| 25 | preHandler: requirePermission(["issue::read"]), |
| 26 | }, |
| 27 | async (request: FastifyRequest, reply: FastifyReply) => { |
| 28 | const result = await prisma.ticket.count({ |
| 29 | where: { isComplete: true, hidden: false }, |
| 30 | }); |
| 31 | |
| 32 | reply.send({ count: result }); |
| 33 | } |
| 34 | ); |
| 35 | |
| 36 | // Get total count of all open tickets |
| 37 | fastify.get( |
| 38 | "/api/v1/data/tickets/open", |
| 39 | { |
| 40 | preHandler: requirePermission(["issue::read"]), |
| 41 | }, |
| 42 | async (request: FastifyRequest, reply: FastifyReply) => { |
| 43 | const result = await prisma.ticket.count({ |
| 44 | where: { isComplete: false, hidden: false }, |
| 45 | }); |
| 46 | |
| 47 | reply.send({ count: result }); |
| 48 | } |
| 49 | ); |
| 50 | |
| 51 | // Get total of all unsassigned tickets |
| 52 | fastify.get( |
| 53 | "/api/v1/data/tickets/unassigned", |
| 54 | { |
| 55 | preHandler: requirePermission(["issue::read"]), |
| 56 | }, |
| 57 | async (request: FastifyRequest, reply: FastifyReply) => { |
| 58 | const result = await prisma.ticket.count({ |
| 59 | where: { userId: null, hidden: false, isComplete: false }, |
| 60 | }); |
| 61 | |
| 62 | reply.send({ count: result }); |
no test coverage detected