refs #6078 - workerAct #2814
|
@ -0,0 +1,50 @@
|
||||||
|
module.exports = Self => {
|
||||||
sergiodt marked this conversation as resolved
|
|||||||
|
Self.remoteMethodCtx('add', {
|
||||||
|
description: 'Add activity if the activity is different or is the same but have exceed time for break',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'code',
|
||||||
|
type: 'string',
|
||||||
|
description: 'Code for activity'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'model',
|
||||||
|
type: 'string',
|
||||||
|
description: 'Origin model from insert'
|
||||||
|
},
|
||||||
|
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: `/add`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.add = async(ctx, code, model, options) => {
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
sergiodt marked this conversation as resolved
Outdated
alexm
commented
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
|
|||||||
|
if (typeof options == 'object')
|
||||||
sergiodt marked this conversation as resolved
Outdated
alexm
commented
return await Self.rawSql(` return await Self.rawSql(`
|
|||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
return await Self.rawSql(`
|
||||||
|
INSERT INTO workerActivity (workerFk, workerActivityTypeFk, model)
|
||||||
|
SELECT ?, ?, ?
|
||||||
|
FROM workerTimeControlParams wtcp
|
||||||
sergiodt marked this conversation as resolved
Outdated
guillermo
commented
Aquí como todas las columnas son parámetros, no metería un salto de linea por cada columna. A parte a partir de aquí, tiene que ir una tabulación más.
Aquí como todas las columnas son parámetros, no metería un salto de linea por cada columna.
A parte a partir de aquí, tiene que ir una tabulación más.
```
INSERT INTO...
SELECT ?, ?, ?
FROM...
```
sergiodt
commented
Tabulat Tabulat
|
|||||||
|
LEFT JOIN (
|
||||||
|
SELECT wa.workerFk,
|
||||||
|
wa.created,
|
||||||
|
wat.code
|
||||||
|
FROM workerActivity wa
|
||||||
|
LEFT JOIN workerActivityType wat ON wat.code = wa.workerActivityTypeFk
|
||||||
|
WHERE wa.workerFk = ?
|
||||||
|
ORDER BY wa.created DESC
|
||||||
|
LIMIT 1
|
||||||
|
) sub ON TRUE
|
||||||
|
WHERE sub.workerFk IS NULL
|
||||||
|
OR sub.code <> ?
|
||||||
|
OR TIMESTAMPDIFF(SECOND, sub.created, util.VN_NOW()) > wtcp.dayBreak;`
|
||||||
sergiodt marked this conversation as resolved
Outdated
alexm
commented
, myOptions); , myOptions);
|
|||||||
|
, [userId, code, model, userId, code], myOptions);
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,30 @@
|
||||||
|
const {models} = require('vn-loopback');
|
||||||
|
|
||||||
|
describe('workerActivity insert()', () => {
|
||||||
|
const ctx = beforeAll.getCtx(1106);
|
||||||
sergiodt marked this conversation as resolved
Outdated
alexm
commented
const ctx = beforeAll.getCtx(); const ctx = beforeAll.getCtx();
|
|||||||
|
|
||||||
|
it('should insert in workerActivity', async() => {
|
||||||
|
const tx = await models.WorkerActivity.beginTransaction({});
|
||||||
|
let count = 0;
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await models.WorkerActivityType.create(
|
||||||
|
{'code': 'STOP', 'description': 'STOP'}, options
|
||||||
|
);
|
||||||
sergiodt marked this conversation as resolved
Outdated
carlosap
commented
tens foco en el test tens foco en el test
|
|||||||
|
|
||||||
|
await models.WorkerActivity.add(ctx, 'STOP', 'APP', options);
|
||||||
sergiodt marked this conversation as resolved
Outdated
alexm
commented
result no es gasta result no es gasta
|
|||||||
|
|
||||||
|
count = await models.WorkerActivity.count(
|
||||||
|
{'workerFK': 1106}, options
|
||||||
|
);
|
||||||
|
|
||||||
sergiodt marked this conversation as resolved
alexm
commented
Esto arriba, y usar options Esto arriba, y usar options
|
|||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
sergiodt marked this conversation as resolved
alexm
commented
await await
|
|||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(count).toEqual(1);
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/workerActivity/add')(Self);
|
||||||
|
};
|
|
@ -22,18 +22,18 @@
|
||||||
},
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"relations": {
|
||||||
|
"workerFk": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Worker",
|
||||||
|
"foreignKey": "workerFk"
|
||||||
},
|
},
|
||||||
"relations": {
|
"workerActivityTypeFk": {
|
||||||
"workerFk": {
|
"type": "belongsTo",
|
||||||
"type": "belongsTo",
|
"model": "WorkerActivityType",
|
||||||
"model": "Worker",
|
"foreignKey": "workerActivityTypeFk"
|
||||||
"foreignKey": "workerFk"
|
|
||||||
},
|
|
||||||
"workerActivityTypeFk": {
|
|
||||||
"type": "belongsTo",
|
|
||||||
"model": "WorkerActivityType",
|
|
||||||
"foreignKey": "workerActivityTypeFk"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Aquí se te ha colado un salto de linea
Llevat