7489-testToMaster #2515
|
@ -0,0 +1,32 @@
|
|||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('chooseLocker', {
|
||||
description: 'Returns an unoccupied locker for the employee',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'filter',
|
||||
type: 'Object',
|
||||
description: 'Filter defining where and paginated data',
|
||||
required: true
|
||||
}],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/chooseLocker`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.chooseLocker = async filter => {
|
||||
const query =
|
||||
`SELECT l.code AS locker_code
|
||||
FROM worker w
|
||||
JOIN locker l ON w.sex = l.gender
|
||||
WHERE w.id = ? AND l.workerFk IS NULL;
|
||||
`[this.worker.id];
|
||||
|
||||
return Self.chooseLocker(query, filter);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/worker/chooseLocker')(Self);
|
||||
|
||||
Self.validatesUniquenessOf('locker', {
|
||||
message: 'This locker has already been assigned'
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue