add exceprion to half day absence
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
4c064f8a80
commit
21bd625b3b
|
@ -46,21 +46,24 @@ module.exports = Self => {
|
||||||
if (isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss))
|
if (isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss))
|
||||||
throw new UserError(`You don't have enough privileges`);
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
const timed = new Date(args.timed);
|
const minTime = new Date(args.timed);
|
||||||
timed.setHours(0, 0, 0, 0);
|
minTime.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
query = `SELECT * FROM vn.workerLabour WHERE workerFk = ? AND (ended >= ? OR ended IS NULL);`;
|
query = `SELECT * FROM vn.workerLabour WHERE workerFk = ? AND (ended >= ? OR ended IS NULL);`;
|
||||||
const [workerLabour] = await Self.rawSql(query, [workerId, timed]);
|
const [workerLabour] = await Self.rawSql(query, [workerId, minTime]);
|
||||||
const hasAbsence = await models.Calendar.findOne({
|
const absence = await models.Calendar.findOne({
|
||||||
where: {
|
where: {
|
||||||
businessFk: workerLabour.businessFk,
|
businessFk: workerLabour.businessFk,
|
||||||
dated: timed
|
dated: minTime
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (absence) {
|
||||||
|
const absenceType = await models.AbsenceType.findById(absence.dayOffTypeFk, null, myOptions);
|
||||||
|
const isNotHalfAbsence = absenceType.id != 6 && absenceType.id != 15 && absenceType.id != 21;
|
||||||
|
|
||||||
if (hasAbsence)
|
if (isNotHalfAbsence)
|
||||||
throw new UserError(`The worker has a marked absence that day`);
|
throw new UserError(`The worker has a marked absence that day`);
|
||||||
|
}
|
||||||
return models.WorkerTimeControl.create({
|
return models.WorkerTimeControl.create({
|
||||||
userFk: workerId,
|
userFk: workerId,
|
||||||
direction: args.direction,
|
direction: args.direction,
|
||||||
|
|
|
@ -71,10 +71,12 @@ module.exports = Self => {
|
||||||
LIMIT 1;`;
|
LIMIT 1;`;
|
||||||
const [hasHoursRecorded] = await Self.rawSql(query, [args.id, args.dated, args.dated]);
|
const [hasHoursRecorded] = await Self.rawSql(query, [args.id, args.dated, args.dated]);
|
||||||
|
|
||||||
if (hasHoursRecorded)
|
const isNotHalfAbsence = args.absenceTypeId != 6 && args.absenceTypeId != 15 && args.absenceTypeId != 21;
|
||||||
|
|
||||||
|
if (hasHoursRecorded && isNotHalfAbsence)
|
||||||
throw new UserError(`The worker has hours recorded that day`);
|
throw new UserError(`The worker has hours recorded that day`);
|
||||||
|
|
||||||
const result = await Self.rawSql(
|
const [result] = await Self.rawSql(
|
||||||
`SELECT COUNT(*) halfHolidayCounter
|
`SELECT COUNT(*) halfHolidayCounter
|
||||||
FROM vn.calendar c
|
FROM vn.calendar c
|
||||||
JOIN postgresql.business b ON b.business_id = c.businessFk
|
JOIN postgresql.business b ON b.business_id = c.businessFk
|
||||||
|
@ -85,7 +87,7 @@ module.exports = Self => {
|
||||||
AND c.dated BETWEEN util.firstDayOfYear(CURDATE())
|
AND c.dated BETWEEN util.firstDayOfYear(CURDATE())
|
||||||
AND LAST_DAY(DATE_ADD(NOW(), INTERVAL 12-MONTH(NOW()) MONTH))`, [args.id]);
|
AND LAST_DAY(DATE_ADD(NOW(), INTERVAL 12-MONTH(NOW()) MONTH))`, [args.id]);
|
||||||
|
|
||||||
const hasHalfHoliday = result[0].halfHolidayCounter > 0;
|
const hasHalfHoliday = result.halfHolidayCounter > 0;
|
||||||
const isHalfHoliday = args.absenceTypeId == 6;
|
const isHalfHoliday = args.absenceTypeId == 6;
|
||||||
|
|
||||||
if (isHalfHoliday && hasHalfHoliday)
|
if (isHalfHoliday && hasHalfHoliday)
|
||||||
|
|
|
@ -103,13 +103,13 @@ describe('Worker createAbsence()', () => {
|
||||||
expect(error.message).toEqual(`Cannot add more than one '1/2 day vacation'`);
|
expect(error.message).toEqual(`Cannot add more than one '1/2 day vacation'`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should throw an error when adding a absence if the worker has hours recorded that day`, async() => {
|
it(`should throw an error when adding a absence if the worker has hours recorded that day and not is a half absence`, async() => {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
req: {accessToken: {userId: 19}},
|
req: {accessToken: {userId: 19}},
|
||||||
args: {
|
args: {
|
||||||
id: 1106,
|
id: 1106,
|
||||||
businessFk: 1106,
|
businessFk: 1106,
|
||||||
absenceTypeId: 6,
|
absenceTypeId: 1,
|
||||||
dated: new Date()
|
dated: new Date()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue