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

42 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',
accessType: '',
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(
2019-01-21 10:45:53 +00:00
`SELECT lh.dated, lhl.description, lht.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
2019-03-22 07:28:57 +00:00
LEFT JOIN vn.holidayDetail lhl ON lhl.id = lh.holidayDetailFk
LEFT JOIN vn.holidayType lht ON lht.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;
});
2019-01-21 10:45:53 +00:00
};
};