#6276 createNewWarehouse methods migrated from silex to salix #1850
|
@ -0,0 +1,63 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('updateInTime', {
|
||||
description: '',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'plate',
|
||||
type: 'string',
|
||||
}
|
||||
],
|
||||
http: {
|
||||
path: `/updateInTime`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updateInTime = async(ctx, plate, options) => {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const machine = await models.Machine.findOne({
|
||||
fields: ['id', 'plate'],
|
||||
where: {plate}
|
||||
}, myOptions);
|
||||
|
||||
if (!machine) throw new Error(`plate ${plate} does not exist`);
|
||||
|
||||
const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions);
|
||||
|
||||
const machineWorker = await models.MachineWorker.findOne({
|
||||
where: {
|
||||
workerFk: userId,
|
||||
inTime: {gte: new Date(Date.now() - maxHours * 60 * 60 * 1000)},
|
||||
outTimed: null,
|
||||
machineFk: machine.id,
|
||||
}
|
||||
|
||||
});
|
||||
if (machineWorker) {
|
||||
await machineWorker.updateAttributes({
|
||||
inTime: new Date(Date.now())
|
||||
jorgep marked this conversation as resolved
Outdated
|
||||
}, myOptions);
|
||||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -1,71 +0,0 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('updateMachine', {
|
||||
description: '',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'plate',
|
||||
type: 'string',
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/update-machine`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updateMachine = async(ctx, plate, options) => {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
let insertState = false;
|
||||
|
||||
const machine = await models.Machine.findOne({
|
||||
fields: ['id', 'plate'],
|
||||
where: {plate}
|
||||
}, myOptions);
|
||||
|
||||
if (machine) {
|
||||
const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions);
|
||||
|
||||
const machineWorker = await models.MachineWorker.findOne({
|
||||
where: {
|
||||
workerFk: userId,
|
||||
inTime: {gte: new Date(Date.now() - maxHours * 60 * 60 * 1000)},
|
||||
outTimed: null,
|
||||
machineFk: machine.id,
|
||||
}
|
||||
|
||||
});
|
||||
if (machineWorker) {
|
||||
await machineWorker.updateAttributes({
|
||||
inTime: new Date(Date.now())
|
||||
}, myOptions);
|
||||
}
|
||||
insertState = true;
|
||||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
return insertState;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -1,3 +1,3 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/machine-worker/updateMachine')(Self);
|
||||
require('../methods/machine-worker/updateInTime')(Self);
|
||||
};
|
||||
|
|
|
@ -2,7 +2,4 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp
|
|||
VALUES
|
||||
('Collection', 'assignCollection', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||
('ExpeditionPallet', 'getPallet', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
('MachineWorker','updateMachine','WRITE','ALLOW','ROLE','employee');
|
||||
|
||||
INSERT INTO `vn`.`machineWorkerConfig` (id, maxHours)
|
||||
VALUES (1, 12)
|
||||
('MachineWorker','updateInTime','WRITE','ALLOW','ROLE','employee');
|
|
@ -3671,3 +3671,6 @@ CALL itemShelvingSale_reserveByCollection(10101010);
|
|||
UPDATE vn.collection
|
||||
SET workerFk=9
|
||||
WHERE id=10101010;
|
||||
|
||||
INSERT INTO `vn`.`machineWorkerConfig` (id, maxHours)
|
||||
VALUES (1, 12)
|
Loading…
Reference in New Issue
isHimself