feat: refs #8077 create testo to sumAmount
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
5287b8a492
commit
d831b5197d
|
@ -56,8 +56,7 @@ module.exports = Self => {
|
|||
filter = mergeFilters(ctx.args.filter, {where});
|
||||
|
||||
const stmts = [];
|
||||
const fields = ctx.args.sumAmount ? 'sum(d.amount) sumAmount' : ` DISTINCT c.id clientFk,
|
||||
c.name clientName,
|
||||
const sqlCode = `, c.name clientName,
|
||||
c.salesPersonFk,
|
||||
c.businessTypeFk = 'worker' isWorker,
|
||||
u.name salesPersonName,
|
||||
|
@ -75,6 +74,8 @@ module.exports = Self => {
|
|||
dp.id departmentFk,
|
||||
dp.name departmentName,
|
||||
dp.notificationEmail departmentEmail`;
|
||||
const fields = ctx.args.sumAmount ? `sum(d.amount) sumAmount, d.clientFk ${sqlCode}`
|
||||
: ` DISTINCT c.id clientFk ${sqlCode}`;
|
||||
const date = Date.vnNew();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const stmt = new ParameterizedSQL(
|
||||
|
@ -108,7 +109,7 @@ module.exports = Self => {
|
|||
, [date]);
|
||||
|
||||
stmt.merge(conn.makeWhere(filter.where));
|
||||
!ctx.args.sumAmount && stmt.merge(`GROUP BY d.clientFk`);
|
||||
!ctx.args.sumAmount && stmt.merge(`GROUP BY clientFk`);
|
||||
stmt.merge(conn.makeOrderBy(filter.order));
|
||||
stmt.merge(conn.makeLimit(filter));
|
||||
|
||||
|
|
|
@ -60,4 +60,21 @@ describe('defaulter filter()', () => {
|
|||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should return the defaulter the sum of every defaulters', async() => {
|
||||
const tx = await models.Defaulter.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const ctx = {req: {accessToken: {userId: authUserId}}, args: {search: 1101, sumAmount: true}};
|
||||
const [result] = await models.Defaulter.filter(ctx, null, options);
|
||||
|
||||
expect(result.sumAmount).toBeDefined();
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue