This commit is contained in:
parent
3c62046277
commit
163faf983e
|
@ -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;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue