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' } }); Self.getByWarehouse = warehouseFk => { let beginningYear = new Date(); beginningYear.setMonth(0); beginningYear.setDate(1); beginningYear.setHours(0, 0, 0, 0); return Self.rawSql( `SELECT lh.dated, lhl.description, lht.name, w.id FROM vn.labourHoliday lh JOIN vn.workCenter w ON w.id = lh.workcenterFk LEFT JOIN vn.labourHolidayLegend lhl ON lhl.id = lh.labourHolidayLegendFk LEFT JOIN vn.labourHolidayType lht ON lht.id = lh.labourHolidayTypeFk WHERE w.warehouseFk = ? AND lh.dated >= ?`, [warehouseFk, beginningYear] ); }; };