salix/modules/worker/back/methods/holiday/getByWarehouse.js

41 lines
1.3 KiB
JavaScript

module.exports = Self => {
Self.remoteMethod('getByWarehouse', {
description: 'Returns an array of labour holidays from an specified warehouse',
accepts: [{
arg: 'warehouseFk',
type: 'Number',
required: true,
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/getByWarehouse`,
verb: 'GET'
}
});
Self.getByWarehouse = async warehouseFk => {
let beginningYear = new Date();
beginningYear.setMonth(0);
beginningYear.setDate(1);
beginningYear.setHours(0, 0, 0, 0);
let holidays = await Self.rawSql(
`SELECT lh.dated, chn.name, cht.name, w.id
FROM vn.holiday lh
JOIN vn.workCenter w ON w.id = lh.workcenterFk
LEFT JOIN vn.calendarHolidaysName chn ON chn.id = lh.holidayDetailFk
LEFT JOIN vn.calendarHolidaysType cht ON cht.id = lh.holidayTypeFk
WHERE w.warehouseFk = ? AND lh.dated >= ?`, [warehouseFk, beginningYear]);
return holidays.map(holiday => {
holiday.dated = new Date(holiday.dated);
holiday.dated.setHours(0, 0, 0, 0);
return holiday;
});
};
};