fix logging messages
This commit is contained in:
@ -31,9 +31,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
const targetTable = req.query.nextcrud[0];
|
const targetTable = req.query.nextcrud[0];
|
||||||
//get target action
|
//get target action
|
||||||
if (req.method === 'DELETE') {
|
if (req.method === 'DELETE') {
|
||||||
|
switch (targetTable) {
|
||||||
|
case 'publishers':
|
||||||
const targetId = req.query.nextcrud[1];
|
const targetId = req.query.nextcrud[1];
|
||||||
logger.info('[nextCrud] ' + targetTable + ': ' + targetId + 'DELETED by ' + session.user.email);
|
logger.info('[nextCrud] ' + targetTable + ': ' + targetId + ' DELETED by ' + session.user.email);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nextCrudHandler(req, res);
|
return nextCrudHandler(req, res);
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,6 @@ export default async function handler(req, res) {
|
|||||||
let toSubscribed = req.body.toSubscribed;
|
let toSubscribed = req.body.toSubscribed;
|
||||||
let toAvailable = req.body.toAvailable;
|
let toAvailable = req.body.toAvailable;
|
||||||
|
|
||||||
|
|
||||||
let assignment = await prisma.assignment.findUnique({
|
let assignment = await prisma.assignment.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: parseInt(assignmentId)
|
id: parseInt(assignmentId)
|
||||||
@ -248,7 +247,6 @@ export default async function handler(req, res) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// update the assignment. generate new publicGuid, isConfirmed to false
|
// update the assignment. generate new publicGuid, isConfirmed to false
|
||||||
let newPublicGuid = uuidv4();
|
let newPublicGuid = uuidv4();
|
||||||
await prisma.assignment.update({
|
await prisma.assignment.update({
|
||||||
@ -269,25 +267,6 @@ export default async function handler(req, res) {
|
|||||||
targetEmails.availablePublishers = [];
|
targetEmails.availablePublishers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// let subscribedPublishers = targetEmails.subscribedPublishers, availablePublishers = [];
|
|
||||||
// if (toSubscribed) {
|
|
||||||
// //get all subscribed publisers
|
|
||||||
// subscribedPublishers = await prisma.publisher.findMany({
|
|
||||||
// where: {
|
|
||||||
// isSubscribedToCoverMe: true
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// if (toAvailable) {
|
|
||||||
// availablePublishers = await data.filterPublishersNew("id,firstName,lastName,email", new Date(assignment.shift.startTime),
|
|
||||||
// true, false);
|
|
||||||
|
|
||||||
// }
|
|
||||||
// use
|
|
||||||
|
|
||||||
|
|
||||||
//concat and remove duplicate emails
|
//concat and remove duplicate emails
|
||||||
let pubsToSend = targetEmails.subscribedPublishers.concat(targetEmails.availablePublishers).
|
let pubsToSend = targetEmails.subscribedPublishers.concat(targetEmails.availablePublishers).
|
||||||
filter((item, index, self) =>
|
filter((item, index, self) =>
|
||||||
@ -301,10 +280,10 @@ export default async function handler(req, res) {
|
|||||||
data: {
|
data: {
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
publisher: { connect: { id: publisher.id } },
|
publisher: { connect: { id: publisher.id } },
|
||||||
shift: { connect: { id: assignment.shiftId } },
|
shift: { connect: { id: assignment.shift.id } },
|
||||||
type: EventLogType.AssignmentReplacementRequested,
|
type: EventLogType.AssignmentReplacementRequested,
|
||||||
content: "Заявка за заместване от " + publisher.firstName + " " + publisher.lastName
|
content: "Заявка за заместване от " + publisher.firstName + " " + publisher.lastName
|
||||||
+ "до: " + pubsToSend.map(p => p.firstName + " " + p.lastName + "<" + p.email + ">").join(", "),
|
+ " до: " + pubsToSend.map(p => p.firstName + " " + p.lastName + "<" + p.email + ">").join(", "),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
logger.info("User: " + publisher.email + " sent a 'CoverMe' request for his assignment " + assignmentId + " - " + assignment.shift.cartEvent.location.name + " " + assignment.shift.startTime.toISOString() + " to " + pubsToSend.map(p => p.firstName + " " + p.lastName + "<" + p.email + ">").join(", ") + ". EventLogId: " + eventLog.id + "");
|
logger.info("User: " + publisher.email + " sent a 'CoverMe' request for his assignment " + assignmentId + " - " + assignment.shift.cartEvent.location.name + " " + assignment.shift.startTime.toISOString() + " to " + pubsToSend.map(p => p.firstName + " " + p.lastName + "<" + p.email + ">").join(", ") + ". EventLogId: " + eventLog.id + "");
|
||||||
@ -313,12 +292,12 @@ export default async function handler(req, res) {
|
|||||||
for (let i = 0; i < pubsToSend.length; i++) {
|
for (let i = 0; i < pubsToSend.length; i++) {
|
||||||
|
|
||||||
//send email to subscribed publisher
|
//send email to subscribed publisher
|
||||||
let acceptUrl = process.env.NEXTAUTH_URL + "/api/email?action=email_response&emailaction=coverMeAccept&userId=" + pubsToSend[i].id + "&shiftId=" + assignment.shiftId + "&assignmentPID=" + newPublicGuid;
|
let acceptUrl = process.env.NEXTAUTH_URL + "/api/email?action=email_response&emailaction=coverMeAccept&userId=" + pubsToSend[i].id + "&shiftId=" + assignment.shift.id + "&assignmentPID=" + newPublicGuid;
|
||||||
publisher.prefix = publisher.isMale ? "Брат" : "Сестра";
|
publisher.prefix = publisher.isMale ? "Брат" : "Сестра";
|
||||||
|
|
||||||
let model = {
|
let model = {
|
||||||
user: publisher,
|
user: publisher,
|
||||||
shiftId: assignment.shiftId,
|
shiftId: assignment.shift.id,
|
||||||
acceptUrl: acceptUrl,
|
acceptUrl: acceptUrl,
|
||||||
firstName: pubsToSend[i].firstName,
|
firstName: pubsToSend[i].firstName,
|
||||||
lastName: pubsToSend[i].lastName,
|
lastName: pubsToSend[i].lastName,
|
||||||
@ -350,7 +329,6 @@ export default async function handler(req, res) {
|
|||||||
return res.status(400).json({ message: "Invalid action" });
|
return res.status(400).json({ message: "Invalid action" });
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(200).json({ message: "User action processed" });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user