#6924 Notify absences only to department boss #3175
|
@ -58,9 +58,8 @@ module.exports = Self => {
|
|||
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
|
||||
throw new UserError(`You don't have enough privileges`);
|
||||
|
||||
const labour = await models.WorkerLabour.findById(args.businessFk, {
|
||||
include: {relation: 'department'}
|
||||
}, myOptions);
|
||||
const labour = await models.WorkerLabour.findById(args.businessFk,
|
||||
|
||||
{fields: ['started', 'ended', 'businessFk']}, myOptions);
|
||||
|
||||
if (args.dated < labour.started || (labour.ended != null && args.dated > labour.ended))
|
||||
throw new UserError(`The contract was not active during the selected date`);
|
||||
|
@ -87,7 +86,8 @@ module.exports = Self => {
|
|||
`SELECT COUNT(*) halfHolidayCounter
|
||||
FROM vn.calendar c
|
||||
JOIN vn.business b ON b.id = c.businessFk
|
||||
WHERE c.dayOffTypeFk = 6
|
||||
JOIN vn.absenceType at ON at.id = c.dayOffTypeFk
|
||||
WHERE at.code = 'halfHoliday'
|
||||
AND b.workerFk = ?
|
||||
AND c.dated BETWEEN util.firstDayOfYear(?)
|
||||
AND LAST_DAY(DATE_ADD(?, INTERVAL 12 - MONTH(?) MONTH))`, [id, date, now, now]);
|
||||
|
@ -119,25 +119,23 @@ module.exports = Self => {
|
|||
dated: args.dated
|
||||
}, myOptions);
|
||||
|
||||
const department = labour.department();
|
||||
if (department && department.notificationEmail) {
|
||||
const absenceType = await models.AbsenceType.findById(args.absenceTypeId, null, myOptions);
|
||||
const account = await models.VnUser.findById(userId, null, myOptions);
|
||||
const subordinated = await models.VnUser.findById(id, null, myOptions);
|
||||
const url = await Self.app.models.Url.getUrl();
|
||||
const body = $t('Created absence', {
|
||||
author: account.nickname,
|
||||
employee: subordinated.nickname,
|
||||
absenceType: absenceType.name,
|
||||
dated: formatDate(args.dated),
|
||||
workerUrl: `${url}worker/${id}/calendar`
|
||||
});
|
||||
await models.Mail.create({
|
||||
subject: $t('Absence change notification on the labour calendar'),
|
||||
body: body,
|
||||
receiver: department.notificationEmail
|
||||
}, myOptions);
|
||||
}
|
||||
const account = await models.VnUser.findById(userId, null, myOptions);
|
||||
const subordinated = await models.VnUser.findById(id, null, myOptions);
|
||||
const worker = await models.Worker.findById(subordinated.id, null, myOptions);
|
||||
alexm
commented
Diria que ja no cal mirar ni el department Diria que ja no cal mirar ni el department
|
||||
const departmentBoss = await models.VnUser.findById(worker.bossFk, null, myOptions);
|
||||
const url = await Self.app.models.Url.getUrl();
|
||||
const body = $t('Created absence', {
|
||||
author: account.nickname,
|
||||
employee: subordinated.nickname,
|
||||
absenceType: absenceType.name,
|
||||
dated: formatDate(args.dated),
|
||||
workerUrl: `${url}worker/${id}/calendar`
|
||||
});
|
||||
await models.Mail.create({
|
||||
subject: $t('Absence change notification on the labour calendar'),
|
||||
body: body,
|
||||
receiver: departmentBoss.email
|
||||
}, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
findById espera 3 parametres (o 2 si no vols gastar options)
En este cas seria:
const labour = await models.WorkerLabour.findById(args.businessFk, null, myOptions);
Pero hi ha que especificar sempre els fields, entonces seria (per el que he vist, revisau per si acas)
const labour = await models.WorkerLabour.findById(args.businessFk, {fields: ['started', 'ended', 'businessFk']}, myOptions);