-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: follow an issue (#414) * patch: issue deletion * feat: update client * feat: follow an issue * feat: notifications when following * feat: see who is subscribed to this issue * patch: on hold * patch: migratiom * patch: fix notififaction
- Loading branch information
Showing
13 changed files
with
562 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,40 @@ | ||
import { prisma } from "../../../prisma"; | ||
|
||
/** | ||
* Creates assignment notifications for all ticket followers. | ||
* | ||
* @param {object} ticket - The ticket object | ||
* @param {object} assignee - The user object being assigned | ||
* @param {object} assigner - The user object doing the assigning | ||
* @returns {Promise<void>} | ||
*/ | ||
export async function assignedNotification( | ||
userId: string, | ||
ticket: any | ||
assignee: any, | ||
ticket: any, | ||
assigner: any | ||
) { | ||
try { | ||
return await prisma.notifications.create({ | ||
data: { | ||
text: `Assigned Ticket #${ticket.Number}`, | ||
userId, | ||
ticketId: ticket.id, | ||
}, | ||
const text = `Ticket #${ticket.Number} was assigned to ${assignee.name} by ${assigner.name}`; | ||
|
||
// Get all followers of the ticket, ensuring the creator is not already a follower | ||
const followers = [ | ||
...(ticket.following || []), | ||
...(ticket.following?.includes(ticket.createdBy.id) | ||
? [] | ||
: [ticket.createdBy.id]), | ||
]; | ||
|
||
// Create notifications for all followers (except the assigner) | ||
await prisma.notifications.createMany({ | ||
data: followers | ||
.filter((userId: string) => userId !== assigner.id) | ||
.map((userId: string) => ({ | ||
text, | ||
userId, | ||
ticketId: ticket.id, | ||
})), | ||
}); | ||
} catch (error) { | ||
console.error("Error creating notification:", error); | ||
console.error("Error creating assignment notifications:", error); | ||
} | ||
} |
Oops, something went wrong.