fix(public-api): fix issue paginating executions

* 🐛 Fix pagination issue in /executions

*  Enable all executions tests

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
Ricardo Espinoza
2022-08-08 16:15:56 -04:00
committed by GitHub
parent c1451d2688
commit b9fe707cbd
2 changed files with 81 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
import { parse } from 'flatted';
import { In, Not, ObjectLiteral, LessThan, IsNull } from 'typeorm';
import { In, Not, Raw, ObjectLiteral, LessThan, IsNull } from 'typeorm';
import { Db, IExecutionFlattedDb, IExecutionResponseApi } from '../../../..';
import { ExecutionStatus } from '../../../types';
@@ -59,14 +59,23 @@ export async function getExecutions(data: {
status?: ExecutionStatus;
excludedExecutionsIds?: number[];
}): Promise<IExecutionResponseApi[]> {
const where = {
...(data.lastId && { id: LessThan(data.lastId) }),
...(data.status && { ...getStatusCondition(data.status) }),
...(data.workflowIds && { workflowId: In(data.workflowIds.map(String)) }),
...(data.excludedExecutionsIds && { id: Not(In(data.excludedExecutionsIds)) }),
};
if (data.lastId && data.excludedExecutionsIds) {
where.id = Raw((id) => `${id} < :lastId AND ${id} NOT IN (:...excludedExecutionsIds)`, {
lastId: data.lastId,
excludedExecutionsIds: data.excludedExecutionsIds,
});
}
const executions = await Db.collections.Execution.find({
select: getExecutionSelectableProperties(data.includeData),
where: {
...(data.lastId && { id: LessThan(data.lastId) }),
...(data.status && { ...getStatusCondition(data.status) }),
...(data.workflowIds && { workflowId: In(data.workflowIds.map(String)) }),
...(data.excludedExecutionsIds && { id: Not(In(data.excludedExecutionsIds)) }),
},
where,
order: { id: 'DESC' },
take: data.limit,
});