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