#6276 createNewWarehouse methods migrated from silex to salix #1850

Merged
jorgep merged 158 commits from 6276-createNewWarehouse into dev 2024-03-06 11:32:11 +00:00
6 changed files with 121 additions and 1 deletions
Showing only changes of commit fac6aab26c - Show all commits

View File

@ -0,0 +1,71 @@
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;
}
};
};

View File

@ -79,9 +79,15 @@
"Language": { "Language": {
"dataSource": "vn" "dataSource": "vn"
}, },
"Machine": {
"dataSource": "vn"
},
"MachineWorker": { "MachineWorker": {
"dataSource": "vn" "dataSource": "vn"
}, },
"MachineWorkerConfig": {
"dataSource": "vn"
},
"MobileAppVersionControl": { "MobileAppVersionControl": {
"dataSource": "vn" "dataSource": "vn"
}, },

View File

@ -0,0 +1,18 @@
{
"name": "MachineWorkerConfig",
"base": "VnModel",
"options": {
"mysql": {
"table": "vn.machineWorkerConfig"
}
},
"properties": {
"id": {
"type": "number",
"id": true
},
"maxHours": {
"type": "number"
}
}
}

View File

@ -0,0 +1,3 @@
module.exports = Self => {
require('../methods/machine-worker/updateMachine')(Self);
};

18
back/models/machine.json Normal file
View File

@ -0,0 +1,18 @@
{
"name": "Machine",
"base": "VnModel",
"options": {
"mysql": {
"table": "vn.machine"
}
},
"properties": {
"id": {
"type": "number",
"id": true
},
"plate": {
"type": "string"
}
}
}

View File

@ -1,4 +1,8 @@
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
VALUES VALUES
('Collection', 'assignCollection', 'WRITE', 'ALLOW', 'ROLE', 'employee'), ('Collection', 'assignCollection', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
('ExpeditionPallet', 'getPallet', 'READ', 'ALLOW', 'ROLE', 'employee'); ('ExpeditionPallet', 'getPallet', 'READ', 'ALLOW', 'ROLE', 'employee'),
('MachineWorker','updateMachine','WRITE','ALLOW','ROLE','employee');
INSERT INTO `vn`.`machineWorkerConfig` (id, maxHours)
VALUES (1, 12)