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}
|
||||
});
|
||||
const maxCreditRows = clientConfig.maxCreditRows;
|
||||
|
||||
const clientCredit = await models.ClientCredit.find({
|
||||
where: {clientFk: instance.clientFk},
|
||||
order: 'created DESC'
|
||||
order: 'created DESC',
|
||||
limit: maxCreditRows
|
||||
}, ctx.options);
|
||||
|
||||
if (clientCredit.length > maxCreditRows) {
|
||||
const creditToDestroy = [];
|
||||
for (const [index, credit] of clientCredit.entries()) {
|
||||
if (index >= maxCreditRows)
|
||||
creditToDestroy.push(credit.id);
|
||||
}
|
||||
|
||||
const lastCredit = clientCredit[maxCreditRows - 1];
|
||||
if (lastCredit) {
|
||||
await models.ClientCredit.destroyAll({
|
||||
id: {inq: creditToDestroy}
|
||||
clientFk: instance.clientFk,
|
||||
created: {lt: lastCredit.created}
|
||||
}, ctx.options);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue