refator: delete unnecessary transaction
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
a486b1593b
commit
5c76437498
|
@ -28,40 +28,30 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
if (!myOptions.transaction) {
|
const query =
|
||||||
tx = await Self.beginTransaction({});
|
`SELECT DISTINCT u.nickname
|
||||||
myOptions.transaction = tx;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const query =
|
|
||||||
`SELECT DISTINCT w.id, w.firstName, w.lastName, u.name, u.nickname
|
|
||||||
FROM itemType it
|
FROM itemType it
|
||||||
JOIN worker w ON w.id = it.workerFk
|
JOIN worker w ON w.id = it.workerFk
|
||||||
JOIN account.user u ON u.id = w.id`;
|
JOIN account.user u ON u.id = w.id`;
|
||||||
|
|
||||||
let stmt = new ParameterizedSQL(query);
|
let stmt = new ParameterizedSQL(query);
|
||||||
|
|
||||||
if (filter.where) {
|
if (filter.where) {
|
||||||
const value = filter.where.firstName;
|
const value = filter.where.firstName;
|
||||||
const myFilter = {
|
const myFilter = {
|
||||||
where: {or: [
|
where: {or: [
|
||||||
{'w.firstName': {like: `%${value}%`}},
|
{'w.firstName': {like: `%${value}%`}},
|
||||||
{'w.lastName': {like: `%${value}%`}},
|
{'w.lastName': {like: `%${value}%`}},
|
||||||
{'u.name': {like: `%${value}%`}},
|
{'u.name': {like: `%${value}%`}},
|
||||||
{'u.nickname': {like: `%${value}%`}}
|
{'u.nickname': {like: `%${value}%`}}
|
||||||
]}
|
]}
|
||||||
};
|
};
|
||||||
|
|
||||||
stmt.merge(conn.makeSuffix(myFilter));
|
stmt.merge(conn.makeSuffix(myFilter));
|
||||||
}
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
|
||||||
|
|
||||||
return conn.executeStmt(stmt);
|
|
||||||
} catch (e) {
|
|
||||||
if (tx) await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return conn.executeStmt(stmt);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,6 +16,6 @@ describe('ticket-request getItemTypeWorker()', () => {
|
||||||
|
|
||||||
const result = await models.TicketRequest.getItemTypeWorker(ctx, filter);
|
const result = await models.TicketRequest.getItemTypeWorker(ctx, filter);
|
||||||
|
|
||||||
expect(result.length).toEqual(2);
|
expect(result.length).toBeGreaterThan(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue