feat: Implement status filter for executions
This commit is contained in:
@@ -14,5 +14,6 @@ export default async (request, response) => {
|
||||
const executionParams = (request) => {
|
||||
return {
|
||||
name: request.query.name,
|
||||
status: request.query.status,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -566,7 +566,7 @@ class User extends Base {
|
||||
.orderBy('updated_at', 'desc');
|
||||
}
|
||||
|
||||
getExecutions({ name }) {
|
||||
getExecutions({ name, status }) {
|
||||
return this.authorizedExecutions
|
||||
.clone()
|
||||
.withSoftDeleted()
|
||||
@@ -580,9 +580,16 @@ class User extends Base {
|
||||
})
|
||||
.where((builder) => {
|
||||
builder.withSoftDeleted();
|
||||
|
||||
if (name) {
|
||||
builder.where('flow.name', 'ilike', `%${name}%`);
|
||||
}
|
||||
|
||||
if (status === 'success') {
|
||||
builder.where('executions.status', 'success');
|
||||
} else if (status === 'failure') {
|
||||
builder.where('executions.status', 'failure');
|
||||
}
|
||||
})
|
||||
.orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
@@ -1377,16 +1377,19 @@ describe('User model', () => {
|
||||
executionOne = await createExecution({
|
||||
flowId: flow.id,
|
||||
testRun: false,
|
||||
status: 'success',
|
||||
});
|
||||
|
||||
executionTwo = await createExecution({
|
||||
flowId: flow.id,
|
||||
testRun: true,
|
||||
status: 'failure',
|
||||
});
|
||||
|
||||
executionThree = await createExecution({
|
||||
flowId: anotherUserFlow.id,
|
||||
testRun: false,
|
||||
status: 'success',
|
||||
});
|
||||
|
||||
await createPermission({
|
||||
@@ -1411,6 +1414,13 @@ describe('User model', () => {
|
||||
expect(executions[1].id).toBe(executionOne.id);
|
||||
});
|
||||
|
||||
it('should return executions filtered by status', async () => {
|
||||
const executions = await currentUser.getExecutions({ status: 'failure' });
|
||||
|
||||
expect(executions).toHaveLength(1);
|
||||
expect(executions[0].id).toBe(executionTwo.id);
|
||||
});
|
||||
|
||||
it('should return all executions when no filter is applied', async () => {
|
||||
const executions = await currentUser.getExecutions({});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user