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

41 lines
1.3 KiB
JavaScript
Raw Normal View History

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(
`SELECT lh.dated, chn.name, cht.name, w.id
2019-03-22 07:28:57 +00:00
FROM vn.holiday lh
2019-01-21 10:45:53 +00:00
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
2019-03-22 07:28:57 +00:00
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;
});
2019-01-21 10:45:53 +00:00
};
};