router.get("/:ticketid", async (req, res) => {
try {
const ticket = await ticketTable.findByPk(req.params.ticketid);
const severityTimeSpaninMinutes = {
"Severity 1 - Critical Business Impact": 1 * 60 * 24,
"Severity 2 - Significant Business Impact": 3 * 60 * 24,
"Severity 3 - Some Business Impact": 90 * 60 * 24,
"Severity 4 - Minimal Business Impact": 91 * 60 * 24
}
if (ticket) {
// check if time until caseSubmittedDate is more than 1 day
const timeUntilCaseSubmittedDate = dayjs(ticket.caseSubmittedDate).diff(dayjs(), 'minute')
// if yes, then update the ticketSLA to "Not Met"
if (timeUntilCaseSubmittedDate < -severityTimeSpaninMinutes[ticket.priority]) {
await ticketTable.update({
ticketSLA: "Not Met"
}, {
where: {
tID: ticket.tID
}
})
}
// get attachments based on R_TID
const attachments = await attachmentTable.findAll({
where: {
R_ID: ticket.tID,
columnName: "Requestor"
}
})
res.json({
data: { ...ticket.toJSON(), attachments },
statusCode: 200,
statusMessage: `Successfully fetched ${ticket.toJSON().ticketNo}`
})
} else {
res.status(400).json({
statusCode: 400,
statusMessage: "Missing Ticket"
})
}
} catch (err) {
return res.status(500).json({
statusCode: 500,
statusMessage: err.message
})
}
})
Within this ticket
variable is used to hold a specific item retrieved from the ticket table initially through sequelize
Furthermore, an update operation occurs within a conditional statement on the table.
Interestingly, in the line
data: { ...ticket.toJSON(), attachments },
the ticket
object automatically reflects the updated value from the table, even though it was declared prior to the update.
I am curious about the intricate workings of this process. How does this mechanism operate in detail?