using original Publisher when there is a replacement. log manual replacements.

This commit is contained in:
Dobromir Popov
2024-05-11 14:25:49 +03:00
parent 26af8382ad
commit bf80e985de
3 changed files with 64 additions and 1 deletions

View File

@ -106,6 +106,7 @@ export default async function handler(req, res) {
}, },
data: { data: {
publisherId: userId, publisherId: userId,
originalPublisherId: originalPublisher.id,
publicGuid: null, // if this exists, we consider the request open publicGuid: null, // if this exists, we consider the request open
isConfirmed: true isConfirmed: true
} }

View File

@ -2,7 +2,7 @@ import { getToken } from "next-auth/jwt";
import { authOptions } from './auth/[...nextauth]' import { authOptions } from './auth/[...nextauth]'
import { getServerSession } from "next-auth/next" import { getServerSession } from "next-auth/next"
import { NextApiRequest, NextApiResponse } from 'next' import { NextApiRequest, NextApiResponse } from 'next'
import { DayOfWeek, AvailabilityType, UserRole } from '@prisma/client'; import { DayOfWeek, AvailabilityType, UserRole, EventLogType } from '@prisma/client';
const common = require('../../src/helpers/common'); const common = require('../../src/helpers/common');
const dataHelper = require('../../src/helpers/data'); const dataHelper = require('../../src/helpers/data');
const subq = require('../../prisma/bl/subqueries'); const subq = require('../../prisma/bl/subqueries');
@ -11,6 +11,7 @@ import { addMinutes } from 'date-fns';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import { all } from "axios"; import { all } from "axios";
import { logger } from "src/helpers/common";
/** /**
* *
@ -821,10 +822,70 @@ async function replaceInAssignment(oldPublisherId, newPublisherId, shiftId) {
}, },
data: { data: {
publisherId: newPublisherId, publisherId: newPublisherId,
originalPublisherId: oldPublisherId,
isConfirmed: false, isConfirmed: false,
isBySystem: true, isBySystem: true,
isMailSent: false isMailSent: false
} }
}); });
// log the event
let shift = await prisma.shift.findUnique({
where: {
id: shiftId
},
select: {
startTime: true,
cartEvent: {
select: {
location: {
select: {
name: true
}
}
}
}
},
include: {
assignments: {
include: {
publisher: {
select: {
firstName: true,
lastName: true,
email: true
}
}
}
}
}
});
let publishers = await prisma.publisher.findMany({
where: {
id: { in: [oldPublisherId, newPublisherId] }
},
select: {
id: true,
firstName: true,
lastName: true,
email: true
}
});
let originalPublisher = publishers.find(p => p.id == oldPublisherId);
let newPublisher = publishers.find(p => p.id == newPublisherId);
let eventLog = await prisma.eventLog.create({
data: {
date: new Date(),
publisher: { connect: { id: oldPublisherId } },
shift: { connect: { id: shiftId } },
type: EventLogType.AssignmentReplacementManual,
content: "Въведено заместване от " + originalPublisher.firstName + " " + originalPublisher.lastName + ". Ще го замества " + newPublisher.firstName + " " + newPublisher.lastName + "."
}
});
logger.info("User: " + originalPublisher.email + " replaced his assignment for " + shift.cartEvent.location.name + " " + shift.startTime.toISOString() + " with " + newPublisher.firstName + " " + newPublisher.lastName + "<" + newPublisher.email + ">. EventLogId: " + eventLog.id + "");
return result; return result;
} }

View File

@ -277,6 +277,7 @@ model Message {
} }
enum EventLogType { enum EventLogType {
AssignmentReplacementManual
AssignmentReplacementRequested AssignmentReplacementRequested
AssignmentReplacementAccepted AssignmentReplacementAccepted
SentEmail SentEmail