refactor(client-credit)
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
800b4984ff
commit
1cc199e26b
|
@ -7,21 +7,17 @@ module.exports = Self => {
|
||||||
where: {id: 1}
|
where: {id: 1}
|
||||||
});
|
});
|
||||||
const maxCreditRows = clientConfig.maxCreditRows;
|
const maxCreditRows = clientConfig.maxCreditRows;
|
||||||
|
|
||||||
const clientCredit = await models.ClientCredit.find({
|
const clientCredit = await models.ClientCredit.find({
|
||||||
where: {clientFk: instance.clientFk},
|
where: {clientFk: instance.clientFk},
|
||||||
order: 'created DESC'
|
order: 'created DESC',
|
||||||
|
limit: maxCreditRows
|
||||||
}, ctx.options);
|
}, ctx.options);
|
||||||
|
|
||||||
if (clientCredit.length > maxCreditRows) {
|
const lastCredit = clientCredit[maxCreditRows - 1];
|
||||||
const creditToDestroy = [];
|
if (lastCredit) {
|
||||||
for (const [index, credit] of clientCredit.entries()) {
|
|
||||||
if (index >= maxCreditRows)
|
|
||||||
creditToDestroy.push(credit.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
await models.ClientCredit.destroyAll({
|
await models.ClientCredit.destroyAll({
|
||||||
id: {inq: creditToDestroy}
|
clientFk: instance.clientFk,
|
||||||
|
created: {lt: lastCredit.created}
|
||||||
}, ctx.options);
|
}, ctx.options);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue