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) => { Self.add = async(ctx, code, model, options) => {
const userId = ctx.req.accessToken.userId; 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) INSERT INTO workerActivity (workerFk, workerActivityTypeFk, model)
SELECT ?, SELECT ?,
?, ?,
@ -44,8 +48,6 @@ module.exports = Self => {
WHERE sub.workerFk IS NULL WHERE sub.workerFk IS NULL
OR sub.code <> ? OR sub.code <> ?
OR TIMESTAMPDIFF(SECOND, sub.created, util.VN_NOW()) > wtcp.dayBreak;` OR TIMESTAMPDIFF(SECOND, sub.created, util.VN_NOW()) > wtcp.dayBreak;`
, [userId, code, model, userId, code]); , [userId, code, model, userId, code], myOptions);
return result;
}; };
}; };

View File

@ -1,36 +1,29 @@
const {models} = require('vn-loopback'); const {models} = require('vn-loopback');
describe('workerActivity insert()', () => { describe('workerActivity insert()', () => {
beforeAll(async() => { const ctx = beforeAll.getCtx(1106);
ctx = {
req: {
accessToken: {},
headers: {origin: 'http://localhost'},
__: value => value
}
};
});
it('should insert in workerActivity', async() => { it('should insert in workerActivity', async() => {
const tx = await models.WorkerActivity.beginTransaction({}); const tx = await models.WorkerActivity.beginTransaction({});
let count = 0;
const options = {transaction: tx};
try { try {
await models.WorkerActivityType.create( 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(); await tx.rollback();
} catch (e) { } catch (e) {
await tx.rollback(); await tx.rollback();
throw e; throw e;
} }
const count = await models.WorkerActivity.count(
{'workerFK': 1106}
);
expect(count).toEqual(1); expect(count).toEqual(1);
}); });