(fastify: FastifyInstance)
| 25 | }; |
| 26 | |
| 27 | export function ticketRoutes(fastify: FastifyInstance) { |
| 28 | // Create a new ticket - public endpoint, no preHandler needed |
| 29 | fastify.post( |
| 30 | "/api/v1/ticket/create", |
| 31 | { |
| 32 | preHandler: requirePermission(["issue::create"]), |
| 33 | }, |
| 34 | async (request: FastifyRequest, reply: FastifyReply) => { |
| 35 | const { |
| 36 | name, |
| 37 | company, |
| 38 | detail, |
| 39 | title, |
| 40 | priority, |
| 41 | email, |
| 42 | engineer, |
| 43 | type, |
| 44 | createdBy, |
| 45 | }: any = request.body; |
| 46 | |
| 47 | const ticket: any = await prisma.ticket.create({ |
| 48 | data: { |
| 49 | name, |
| 50 | title, |
| 51 | detail: JSON.stringify(detail), |
| 52 | priority: priority ? priority : "low", |
| 53 | email, |
| 54 | type: type ? type.toLowerCase() : "support", |
| 55 | createdBy: createdBy |
| 56 | ? { |
| 57 | id: createdBy.id, |
| 58 | name: createdBy.name, |
| 59 | role: createdBy.role, |
| 60 | email: createdBy.email, |
| 61 | } |
| 62 | : undefined, |
| 63 | client: |
| 64 | company !== undefined |
| 65 | ? { |
| 66 | connect: { id: company.id || company }, |
| 67 | } |
| 68 | : undefined, |
| 69 | fromImap: false, |
| 70 | assignedTo: |
| 71 | engineer && engineer.name !== "Unassigned" |
| 72 | ? { |
| 73 | connect: { id: engineer.id }, |
| 74 | } |
| 75 | : undefined, |
| 76 | isComplete: Boolean(false), |
| 77 | }, |
| 78 | }); |
| 79 | |
| 80 | if (!email && !validateEmail(email)) { |
| 81 | await sendTicketCreate(ticket); |
| 82 | } |
| 83 | |
| 84 | if (engineer && engineer.name !== "Unassigned") { |
no test coverage detected