feat(api): add get executions endpoint
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import Base from './base.js';
|
||||
import Flow from './flow.js';
|
||||
import ExecutionStep from './execution-step.js';
|
||||
@@ -40,6 +41,49 @@ class Execution extends Base {
|
||||
},
|
||||
});
|
||||
|
||||
static find({ name, status, startDateTime, endDateTime }) {
|
||||
return this.query()
|
||||
.withSoftDeleted()
|
||||
.joinRelated({
|
||||
flow: true,
|
||||
})
|
||||
.withGraphFetched({
|
||||
flow: {
|
||||
steps: true,
|
||||
},
|
||||
})
|
||||
.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');
|
||||
}
|
||||
|
||||
if (startDateTime) {
|
||||
const startDate = DateTime.fromMillis(Number(startDateTime));
|
||||
|
||||
if (startDate.isValid) {
|
||||
builder.where('executions.created_at', '>=', startDate.toISO());
|
||||
}
|
||||
}
|
||||
|
||||
if (endDateTime) {
|
||||
const endDate = DateTime.fromMillis(Number(endDateTime));
|
||||
|
||||
if (endDate.isValid) {
|
||||
builder.where('executions.created_at', '<=', endDate.toISO());
|
||||
}
|
||||
}
|
||||
})
|
||||
.orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
async $afterInsert(queryContext) {
|
||||
await super.$afterInsert(queryContext);
|
||||
Telemetry.executionCreated(this);
|
||||
|
||||
Reference in New Issue
Block a user