MCPcopy
hub / github.com/Peppermint-Lab/peppermint / ticketRoutes

Function ticketRoutes

apps/api/src/controllers/ticket.ts:27–843  ·  view source on GitHub ↗
(fastify: FastifyInstance)

Source from the content-addressed store, hash-verified

25};
26
27export 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") {

Callers 1

registerRoutesFunction · 0.90

Calls 12

requirePermissionFunction · 0.90
sendTicketCreateFunction · 0.90
sendAssignedEmailFunction · 0.90
assignedNotificationFunction · 0.90
sendWebhookNotificationFunction · 0.90
trackFunction · 0.90
checkTokenFunction · 0.90
checkSessionFunction · 0.90
sendCommentFunction · 0.90
commentNotificationFunction · 0.90
sendTicketStatusFunction · 0.90
validateEmailFunction · 0.70

Tested by

no test coverage detected