2019-01-21 10:45:53 +00:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-03-22 07:28:57 +00:00
|
|
|
Self.getByWarehouse = async warehouseFk => {
|
2019-01-21 10:45:53 +00:00
|
|
|
let beginningYear = new Date();
|
|
|
|
beginningYear.setMonth(0);
|
|
|
|
beginningYear.setDate(1);
|
|
|
|
beginningYear.setHours(0, 0, 0, 0);
|
|
|
|
|
2019-03-22 07:28:57 +00:00
|
|
|
let holidays = await Self.rawSql(
|
2020-03-12 09:59:41 +00:00
|
|
|
`SELECT clh.dated, chn.name, cht.name, w.id
|
|
|
|
FROM vn.calendarHolidays clh
|
|
|
|
JOIN vn.workCenter w ON w.id = clh.workcenterFk
|
|
|
|
LEFT JOIN vn.calendarHolidaysName chn ON chn.id = clh.calendarHolidaysNameFk
|
|
|
|
LEFT JOIN vn.calendarHolidaysType cht ON cht.id = clh.calendarHolidaysTypeFk
|
|
|
|
WHERE w.warehouseFk = ? AND clh.dated >= ?`, [warehouseFk, beginningYear]);
|
2019-03-22 07:28:57 +00:00
|
|
|
|
|
|
|
return holidays.map(holiday => {
|
|
|
|
holiday.dated = new Date(holiday.dated);
|
|
|
|
holiday.dated.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
return holiday;
|
|
|
|
});
|
2019-01-21 10:45:53 +00:00
|
|
|
};
|
|
|
|
};
|