feat workerActivity refs #6078
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Sergio De la torre 2024-08-06 16:34:46 +02:00
parent 3c62046277
commit 163faf983e
2 changed files with 15 additions and 20 deletions

View File

@ -24,8 +24,12 @@ module.exports = Self => {
Self.add = async(ctx, code, model, options) => {
const userId = ctx.req.accessToken.userId;
const myOptions = {};
const result = await await Self.rawSql(`
if (typeof options == 'object')
Object.assign(myOptions, options);
return await Self.rawSql(`
INSERT INTO workerActivity (workerFk, workerActivityTypeFk, model)
SELECT ?,
?,
@ -44,8 +48,6 @@ module.exports = Self => {
WHERE sub.workerFk IS NULL
OR sub.code <> ?
OR TIMESTAMPDIFF(SECOND, sub.created, util.VN_NOW()) > wtcp.dayBreak;`
, [userId, code, model, userId, code]);
return result;
, [userId, code, model, userId, code], myOptions);
};
};

View File

@ -1,36 +1,29 @@
const {models} = require('vn-loopback');
describe('workerActivity insert()', () => {
beforeAll(async() => {
ctx = {
req: {
accessToken: {},
headers: {origin: 'http://localhost'},
__: value => value
}
};
});
const ctx = beforeAll.getCtx(1106);
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'}
{'code': 'STOP', 'description': 'STOP'}, options
);
const options = {transaction: tx};
ctx.req.accessToken.userId = 1106;
models.WorkerActivity.add(ctx, 'STOP', 'APP', options);
result = await models.WorkerActivity.add(ctx, 'STOP', 'APP', options);
count = await models.WorkerActivity.count(
{'workerFK': 1106}, options
);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
const count = await models.WorkerActivity.count(
{'workerFK': 1106}
);
expect(count).toEqual(1);
});