Skip to content

Commit

Permalink
fix: comment notification
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed Oct 26, 2024
1 parent 39dbab6 commit 583104f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 35 deletions.
7 changes: 5 additions & 2 deletions apps/api/src/controllers/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { sendAssignedEmail } from "../lib/nodemailer/ticket/assigned";
import { sendComment } from "../lib/nodemailer/ticket/comment";
import { sendTicketCreate } from "../lib/nodemailer/ticket/create";
import { sendTicketStatus } from "../lib/nodemailer/ticket/status";
import { createNotification } from "../lib/notifications";
import { checkSession } from "../lib/session";
import { prisma } from "../prisma";
import { assignedNotification } from "../lib/notifications/issue/assigned";
import { commentNotification } from "../lib/notifications/issue/comment";

const validateEmail = (email: string) => {
return String(email)
Expand Down Expand Up @@ -83,7 +84,7 @@ export function ticketRoutes(fastify: FastifyInstance) {

await sendAssignedEmail(assgined!.email);

await createNotification("ticket_assigned", engineer.id, ticket);
await assignedNotification(engineer.id, ticket);
}

const webhook = await prisma.webhooks.findMany({
Expand Down Expand Up @@ -542,6 +543,8 @@ export function ticketRoutes(fastify: FastifyInstance) {
sendComment(text, title, email);
}

await commentNotification(user!.id, ticket, user!.name);

const hog = track();

hog.capture({
Expand Down
32 changes: 0 additions & 32 deletions apps/api/src/lib/notifications.ts

This file was deleted.

18 changes: 18 additions & 0 deletions apps/api/src/lib/notifications/issue/assigned.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { prisma } from "../../../prisma";

export async function assignedNotification(
userId: string,
ticket: any
) {
try {
return await prisma.notifications.create({
data: {
text: `Assigned Ticket #${ticket.Number}`,
userId,
ticketId: ticket.id,
},
});
} catch (error) {
console.error("Error creating notification:", error);
}
}
24 changes: 24 additions & 0 deletions apps/api/src/lib/notifications/issue/comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { prisma } from "../../../prisma";

/**
* Creates a new comment notification.
*
* @param {string} userId - The ID of the user to notify.
* @param {object} ticket - The ticket object related to the comment.
* @param {string} comment - The content of the comment.
* @returns {Promise<void>}
*/
export async function commentNotification(userId: string, ticket: any, user: string) {
try {
const text = `New comment on #${ticket.Number} by ${user}`;
return await prisma.notifications.create({
data: {
text,
userId,
ticketId: ticket.id,
},
});
} catch (error) {
console.error("Error creating comment notification:", error);
}
}
1 change: 1 addition & 0 deletions apps/api/src/lib/notifications/issue/status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"next-translate": "^1.3.4",
"posthog-js": "1.93.2",
"prismjs": "^1.29.0",
"prop-types": "^15.8.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-frame-component": "^5.2.6",
Expand All @@ -63,6 +64,7 @@
"@types/next": "^9.0.0",
"@types/node": "17.0.4",
"@types/prismjs": "^1",
"@types/prop-types": "^15",
"@types/react": "18.2.38",
"@types/react-table": "^7.7.15",
"autoprefixer": "^10.4.0",
Expand Down
4 changes: 3 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4363,7 +4363,7 @@ __metadata:
languageName: node
linkType: hard

"@types/prop-types@npm:*":
"@types/prop-types@npm:*, @types/prop-types@npm:^15":
version: 15.7.13
resolution: "@types/prop-types@npm:15.7.13"
checksum: 10c0/1b20fc67281902c6743379960247bc161f3f0406ffc0df8e7058745a85ea1538612109db0406290512947f9632fe9e10e7337bf0ce6338a91d6c948df16a7c61
Expand Down Expand Up @@ -5741,6 +5741,7 @@ __metadata:
"@types/next": "npm:^9.0.0"
"@types/node": "npm:17.0.4"
"@types/prismjs": "npm:^1"
"@types/prop-types": "npm:^15"
"@types/react": "npm:18.2.38"
"@types/react-table": "npm:^7.7.15"
autoprefixer: "npm:^10.4.0"
Expand All @@ -5760,6 +5761,7 @@ __metadata:
postcss: "npm:^8.4.5"
posthog-js: "npm:1.93.2"
prismjs: "npm:^1.29.0"
prop-types: "npm:^15.8.1"
react: "npm:^18.3.1"
react-dom: "npm:^18.3.1"
react-frame-component: "npm:^5.2.6"
Expand Down

0 comments on commit 583104f

Please sign in to comment.