Merge pull request #1381 from automatisch/add-filters-in-get-executions-query
feat(queries/get-executions): add filter support
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
import { Knex } from 'knex';
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
await knex.schema.table('executions', (table) => {
|
||||||
|
table.index('flow_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
await knex.schema.table('executions', (table) => {
|
||||||
|
table.dropIndex('flow_id');
|
||||||
|
});
|
||||||
|
}
|
@@ -0,0 +1,13 @@
|
|||||||
|
import { Knex } from 'knex';
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
await knex.schema.table('executions', (table) => {
|
||||||
|
table.index('updated_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
await knex.schema.table('executions', (table) => {
|
||||||
|
table.dropIndex('updated_at');
|
||||||
|
});
|
||||||
|
}
|
494
packages/backend/src/graphql/queries/get-executions.test.ts
Normal file
494
packages/backend/src/graphql/queries/get-executions.test.ts
Normal file
@@ -0,0 +1,494 @@
|
|||||||
|
import request from 'supertest';
|
||||||
|
import app from '../../app';
|
||||||
|
import appConfig from '../../config/app';
|
||||||
|
import createAuthTokenByUserId from '../../helpers/create-auth-token-by-user-id';
|
||||||
|
import { IJSONObject } from '@automatisch/types';
|
||||||
|
import { createRole } from '../../../test/factories/role';
|
||||||
|
import { createPermission } from '../../../test/factories/permission';
|
||||||
|
import { createUser } from '../../../test/factories/user';
|
||||||
|
import { createFlow } from '../../../test/factories/flow';
|
||||||
|
import { createStep } from '../../../test/factories/step';
|
||||||
|
import { createExecution } from '../../../test/factories/execution';
|
||||||
|
import { createExecutionStep } from '../../../test/factories/execution-step';
|
||||||
|
import { IRole, IUser, IExecution, IFlow, IStep } from '@automatisch/types';
|
||||||
|
|
||||||
|
describe('graphQL getExecutions query', () => {
|
||||||
|
const query = `
|
||||||
|
query {
|
||||||
|
getExecutions(limit: 10, offset: 0) {
|
||||||
|
pageInfo {
|
||||||
|
currentPage
|
||||||
|
totalPages
|
||||||
|
}
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
testRun
|
||||||
|
createdAt
|
||||||
|
updatedAt
|
||||||
|
status
|
||||||
|
flow {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
active
|
||||||
|
steps {
|
||||||
|
iconUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const invalidToken = 'invalid-token';
|
||||||
|
|
||||||
|
describe('with unauthenticated user', () => {
|
||||||
|
it('should throw not authorized error', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', invalidToken)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.errors).toBeDefined();
|
||||||
|
expect(response.body.errors[0].message).toEqual('Not Authorised!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with authenticated user', () => {
|
||||||
|
describe('and without permissions', () => {
|
||||||
|
it('should throw not authorized error', async () => {
|
||||||
|
const userWithoutPermissions = await createUser();
|
||||||
|
const token = createAuthTokenByUserId(userWithoutPermissions.id);
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.errors).toBeDefined();
|
||||||
|
expect(response.body.errors[0].message).toEqual('Not authorized!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and with correct permission', () => {
|
||||||
|
let role: IRole,
|
||||||
|
currentUser: IUser,
|
||||||
|
anotherUser: IUser,
|
||||||
|
token: string,
|
||||||
|
flowOne: IFlow,
|
||||||
|
stepOneForFlowOne: IStep,
|
||||||
|
stepTwoForFlowOne: IStep,
|
||||||
|
executionOne: IExecution,
|
||||||
|
flowTwo: IFlow,
|
||||||
|
stepOneForFlowTwo: IStep,
|
||||||
|
stepTwoForFlowTwo: IStep,
|
||||||
|
executionTwo: IExecution,
|
||||||
|
flowThree: IFlow,
|
||||||
|
stepOneForFlowThree: IStep,
|
||||||
|
stepTwoForFlowThree: IStep,
|
||||||
|
executionThree: IExecution,
|
||||||
|
expectedResponseForExecutionOne: IJSONObject,
|
||||||
|
expectedResponseForExecutionTwo: IJSONObject,
|
||||||
|
expectedResponseForExecutionThree: IJSONObject;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
role = await createRole({
|
||||||
|
key: 'sample',
|
||||||
|
name: 'sample',
|
||||||
|
});
|
||||||
|
|
||||||
|
currentUser = await createUser({
|
||||||
|
roleId: role.id,
|
||||||
|
fullName: 'Current User',
|
||||||
|
});
|
||||||
|
|
||||||
|
anotherUser = await createUser();
|
||||||
|
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
|
||||||
|
flowOne = await createFlow({
|
||||||
|
userId: currentUser.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
stepOneForFlowOne = await createStep({
|
||||||
|
flowId: flowOne.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
stepTwoForFlowOne = await createStep({
|
||||||
|
flowId: flowOne.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
executionOne = await createExecution({
|
||||||
|
flowId: flowOne.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
await createExecutionStep({
|
||||||
|
executionId: executionOne.id,
|
||||||
|
stepId: stepOneForFlowOne.id,
|
||||||
|
status: 'success',
|
||||||
|
});
|
||||||
|
|
||||||
|
await createExecutionStep({
|
||||||
|
executionId: executionOne.id,
|
||||||
|
stepId: stepTwoForFlowOne.id,
|
||||||
|
status: 'success',
|
||||||
|
});
|
||||||
|
|
||||||
|
flowTwo = await createFlow({
|
||||||
|
userId: currentUser.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
stepOneForFlowTwo = await createStep({
|
||||||
|
flowId: flowTwo.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
stepTwoForFlowTwo = await createStep({
|
||||||
|
flowId: flowTwo.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
executionTwo = await createExecution({
|
||||||
|
flowId: flowTwo.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
await createExecutionStep({
|
||||||
|
executionId: executionTwo.id,
|
||||||
|
stepId: stepOneForFlowTwo.id,
|
||||||
|
status: 'success',
|
||||||
|
});
|
||||||
|
|
||||||
|
await createExecutionStep({
|
||||||
|
executionId: executionTwo.id,
|
||||||
|
stepId: stepTwoForFlowTwo.id,
|
||||||
|
status: 'failure',
|
||||||
|
});
|
||||||
|
|
||||||
|
flowThree = await createFlow({
|
||||||
|
userId: anotherUser.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
stepOneForFlowThree = await createStep({
|
||||||
|
flowId: flowThree.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
stepTwoForFlowThree = await createStep({
|
||||||
|
flowId: flowThree.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
executionThree = await createExecution({
|
||||||
|
flowId: flowThree.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
await createExecutionStep({
|
||||||
|
executionId: executionThree.id,
|
||||||
|
stepId: stepOneForFlowThree.id,
|
||||||
|
status: 'success',
|
||||||
|
});
|
||||||
|
|
||||||
|
await createExecutionStep({
|
||||||
|
executionId: executionThree.id,
|
||||||
|
stepId: stepTwoForFlowThree.id,
|
||||||
|
status: 'failure',
|
||||||
|
});
|
||||||
|
|
||||||
|
expectedResponseForExecutionOne = {
|
||||||
|
node: {
|
||||||
|
createdAt: (executionOne.createdAt as Date).getTime().toString(),
|
||||||
|
flow: {
|
||||||
|
active: flowOne.active,
|
||||||
|
id: flowOne.id,
|
||||||
|
name: flowOne.name,
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${stepOneForFlowOne.appKey}/assets/favicon.svg`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${stepTwoForFlowOne.appKey}/assets/favicon.svg`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
id: executionOne.id,
|
||||||
|
status: 'success',
|
||||||
|
testRun: executionOne.testRun,
|
||||||
|
updatedAt: (executionOne.updatedAt as Date).getTime().toString(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expectedResponseForExecutionTwo = {
|
||||||
|
node: {
|
||||||
|
createdAt: (executionTwo.createdAt as Date).getTime().toString(),
|
||||||
|
flow: {
|
||||||
|
active: flowTwo.active,
|
||||||
|
id: flowTwo.id,
|
||||||
|
name: flowTwo.name,
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${stepTwoForFlowTwo.appKey}/assets/favicon.svg`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${stepTwoForFlowTwo.appKey}/assets/favicon.svg`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
id: executionTwo.id,
|
||||||
|
status: 'failure',
|
||||||
|
testRun: executionTwo.testRun,
|
||||||
|
updatedAt: (executionTwo.updatedAt as Date).getTime().toString(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expectedResponseForExecutionThree = {
|
||||||
|
node: {
|
||||||
|
createdAt: (executionThree.createdAt as Date).getTime().toString(),
|
||||||
|
flow: {
|
||||||
|
active: flowThree.active,
|
||||||
|
id: flowThree.id,
|
||||||
|
name: flowThree.name,
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${stepOneForFlowThree.appKey}/assets/favicon.svg`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
iconUrl: `${appConfig.baseUrl}/apps/${stepTwoForFlowThree.appKey}/assets/favicon.svg`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
id: executionThree.id,
|
||||||
|
status: 'failure',
|
||||||
|
testRun: executionThree.testRun,
|
||||||
|
updatedAt: (executionThree.updatedAt as Date).getTime().toString(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and with isCreator condition', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await createPermission({
|
||||||
|
action: 'read',
|
||||||
|
subject: 'Execution',
|
||||||
|
roleId: role.id,
|
||||||
|
conditions: ['isCreator'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return executions data of the current user', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedResponsePayload = {
|
||||||
|
data: {
|
||||||
|
getExecutions: {
|
||||||
|
edges: [
|
||||||
|
expectedResponseForExecutionTwo,
|
||||||
|
expectedResponseForExecutionOne,
|
||||||
|
],
|
||||||
|
pageInfo: { currentPage: 1, totalPages: 1 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and without isCreator condition', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await createPermission({
|
||||||
|
action: 'read',
|
||||||
|
subject: 'Execution',
|
||||||
|
roleId: role.id,
|
||||||
|
conditions: [],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return executions data of all users', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedResponsePayload = {
|
||||||
|
data: {
|
||||||
|
getExecutions: {
|
||||||
|
edges: [
|
||||||
|
expectedResponseForExecutionThree,
|
||||||
|
expectedResponseForExecutionTwo,
|
||||||
|
expectedResponseForExecutionOne,
|
||||||
|
],
|
||||||
|
pageInfo: { currentPage: 1, totalPages: 1 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and with filters', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await createPermission({
|
||||||
|
action: 'read',
|
||||||
|
subject: 'Execution',
|
||||||
|
roleId: role.id,
|
||||||
|
conditions: [],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return executions data for the specified flow', async () => {
|
||||||
|
const query = `
|
||||||
|
query {
|
||||||
|
getExecutions(limit: 10, offset: 0, filters: { flowId: "${flowOne.id}" }) {
|
||||||
|
pageInfo {
|
||||||
|
currentPage
|
||||||
|
totalPages
|
||||||
|
}
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
testRun
|
||||||
|
createdAt
|
||||||
|
updatedAt
|
||||||
|
status
|
||||||
|
flow {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
active
|
||||||
|
steps {
|
||||||
|
iconUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedResponsePayload = {
|
||||||
|
data: {
|
||||||
|
getExecutions: {
|
||||||
|
edges: [expectedResponseForExecutionOne],
|
||||||
|
pageInfo: { currentPage: 1, totalPages: 1 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return only executions data with success status', async () => {
|
||||||
|
const query = `
|
||||||
|
query {
|
||||||
|
getExecutions(limit: 10, offset: 0, filters: { status: "success" }) {
|
||||||
|
pageInfo {
|
||||||
|
currentPage
|
||||||
|
totalPages
|
||||||
|
}
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
testRun
|
||||||
|
createdAt
|
||||||
|
updatedAt
|
||||||
|
status
|
||||||
|
flow {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
active
|
||||||
|
steps {
|
||||||
|
iconUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedResponsePayload = {
|
||||||
|
data: {
|
||||||
|
getExecutions: {
|
||||||
|
edges: [expectedResponseForExecutionOne],
|
||||||
|
pageInfo: { currentPage: 1, totalPages: 1 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return only executions data within date range', async () => {
|
||||||
|
const createdAtFrom = (executionOne.createdAt as Date)
|
||||||
|
.getTime()
|
||||||
|
.toString();
|
||||||
|
|
||||||
|
const createdAtTo = (executionOne.createdAt as Date)
|
||||||
|
.getTime()
|
||||||
|
.toString();
|
||||||
|
|
||||||
|
const query = `
|
||||||
|
query {
|
||||||
|
getExecutions(limit: 10, offset: 0, filters: { createdAt: { from: "${createdAtFrom}", to: "${createdAtTo}" }}) {
|
||||||
|
pageInfo {
|
||||||
|
currentPage
|
||||||
|
totalPages
|
||||||
|
}
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
testRun
|
||||||
|
createdAt
|
||||||
|
updatedAt
|
||||||
|
status
|
||||||
|
flow {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
active
|
||||||
|
steps {
|
||||||
|
iconUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedResponsePayload = {
|
||||||
|
data: {
|
||||||
|
getExecutions: {
|
||||||
|
edges: [expectedResponseForExecutionOne],
|
||||||
|
pageInfo: { currentPage: 1, totalPages: 1 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -1,11 +1,22 @@
|
|||||||
import { raw } from 'objection';
|
import { raw } from 'objection';
|
||||||
|
import { DateTime } from 'luxon';
|
||||||
import Context from '../../types/express/context';
|
import Context from '../../types/express/context';
|
||||||
import Execution from '../../models/execution';
|
import Execution from '../../models/execution';
|
||||||
import paginate from '../../helpers/pagination';
|
import paginate from '../../helpers/pagination';
|
||||||
|
|
||||||
|
type Filters = {
|
||||||
|
flowId?: string;
|
||||||
|
status?: string;
|
||||||
|
createdAt?: {
|
||||||
|
from?: string;
|
||||||
|
to?: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
limit: number;
|
limit: number;
|
||||||
offset: number;
|
offset: number;
|
||||||
|
filters?: Filters;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getExecutions = async (
|
const getExecutions = async (
|
||||||
@@ -15,6 +26,8 @@ const getExecutions = async (
|
|||||||
) => {
|
) => {
|
||||||
const conditions = context.currentUser.can('read', 'Execution');
|
const conditions = context.currentUser.can('read', 'Execution');
|
||||||
|
|
||||||
|
const filters = params.filters;
|
||||||
|
|
||||||
const userExecutions = context.currentUser.$relatedQuery('executions');
|
const userExecutions = context.currentUser.$relatedQuery('executions');
|
||||||
const allExecutions = Execution.query();
|
const allExecutions = Execution.query();
|
||||||
const executionBaseQuery = conditions.isCreator ? userExecutions : allExecutions;
|
const executionBaseQuery = conditions.isCreator ? userExecutions : allExecutions;
|
||||||
@@ -32,16 +45,49 @@ const getExecutions = async (
|
|||||||
.clone()
|
.clone()
|
||||||
.joinRelated('executionSteps as execution_steps')
|
.joinRelated('executionSteps as execution_steps')
|
||||||
.select('executions.*', raw(selectStatusStatement))
|
.select('executions.*', raw(selectStatusStatement))
|
||||||
|
.groupBy('executions.id')
|
||||||
|
.orderBy('created_at', 'desc');
|
||||||
|
|
||||||
|
const computedExecutions = Execution
|
||||||
|
.query()
|
||||||
|
.with('executions', executions)
|
||||||
.withSoftDeleted()
|
.withSoftDeleted()
|
||||||
.withGraphFetched({
|
.withGraphFetched({
|
||||||
flow: {
|
flow: {
|
||||||
steps: true,
|
steps: true,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
.groupBy('executions.id')
|
|
||||||
.orderBy('updated_at', 'desc');
|
|
||||||
|
|
||||||
return paginate(executions, params.limit, params.offset);
|
if (filters?.flowId) {
|
||||||
|
computedExecutions.where('executions.flow_id', filters.flowId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filters?.status) {
|
||||||
|
computedExecutions.where('executions.status', filters.status);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filters?.createdAt) {
|
||||||
|
const createdAtFilter = filters.createdAt;
|
||||||
|
if (createdAtFilter.from) {
|
||||||
|
const isoFromDateTime = DateTime
|
||||||
|
.fromMillis(
|
||||||
|
parseInt(createdAtFilter.from, 10)
|
||||||
|
)
|
||||||
|
.toISO();
|
||||||
|
computedExecutions.where('executions.created_at', '>=', isoFromDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createdAtFilter.to) {
|
||||||
|
const isoToDateTime = DateTime
|
||||||
|
.fromMillis(
|
||||||
|
parseInt(createdAtFilter.to, 10)
|
||||||
|
)
|
||||||
|
.toISO();
|
||||||
|
computedExecutions.where('executions.created_at', '<=', isoToDateTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return paginate(computedExecutions, params.limit, params.offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default getExecutions;
|
export default getExecutions;
|
||||||
|
@@ -20,7 +20,11 @@ type Query {
|
|||||||
): FlowConnection
|
): FlowConnection
|
||||||
getStepWithTestExecutions(stepId: String!): [Step]
|
getStepWithTestExecutions(stepId: String!): [Step]
|
||||||
getExecution(executionId: String!): Execution
|
getExecution(executionId: String!): Execution
|
||||||
getExecutions(limit: Int!, offset: Int!): ExecutionConnection
|
getExecutions(
|
||||||
|
limit: Int!
|
||||||
|
offset: Int!
|
||||||
|
filters: ExecutionFiltersInput
|
||||||
|
): ExecutionConnection
|
||||||
getExecutionSteps(
|
getExecutionSteps(
|
||||||
executionId: String!
|
executionId: String!
|
||||||
limit: Int!
|
limit: Int!
|
||||||
@@ -795,6 +799,17 @@ type Notification {
|
|||||||
description: String
|
description: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input ExecutionCreatedAtFilterInput {
|
||||||
|
from: String
|
||||||
|
to: String
|
||||||
|
}
|
||||||
|
|
||||||
|
input ExecutionFiltersInput {
|
||||||
|
flowId: String
|
||||||
|
createdAt: ExecutionCreatedAtFilterInput
|
||||||
|
status: String
|
||||||
|
}
|
||||||
|
|
||||||
schema {
|
schema {
|
||||||
query: Query
|
query: Query
|
||||||
mutation: Mutation
|
mutation: Mutation
|
||||||
|
@@ -4,6 +4,8 @@ import { createFlow } from './flow';
|
|||||||
export const createExecution = async (params: Partial<Execution> = {}) => {
|
export const createExecution = async (params: Partial<Execution> = {}) => {
|
||||||
params.flowId = params?.flowId || (await createFlow()).id;
|
params.flowId = params?.flowId || (await createFlow()).id;
|
||||||
params.testRun = params?.testRun || false;
|
params.testRun = params?.testRun || false;
|
||||||
|
params.createdAt = params?.createdAt || new Date().toISOString();
|
||||||
|
params.updatedAt = params?.updatedAt || new Date().toISOString();
|
||||||
|
|
||||||
const [execution] = await global.knex
|
const [execution] = await global.knex
|
||||||
.table('executions')
|
.table('executions')
|
||||||
|
@@ -4,6 +4,8 @@ import { createUser } from './user';
|
|||||||
export const createFlow = async (params: Partial<Flow> = {}) => {
|
export const createFlow = async (params: Partial<Flow> = {}) => {
|
||||||
params.userId = params?.userId || (await createUser()).id;
|
params.userId = params?.userId || (await createUser()).id;
|
||||||
params.name = params?.name || 'Name your flow!';
|
params.name = params?.name || 'Name your flow!';
|
||||||
|
params.createdAt = params?.createdAt || new Date().toISOString();
|
||||||
|
params.updatedAt = params?.updatedAt || new Date().toISOString();
|
||||||
|
|
||||||
const [flow] = await global.knex.table('flows').insert(params).returning('*');
|
const [flow] = await global.knex.table('flows').insert(params).returning('*');
|
||||||
|
|
||||||
|
@@ -1,24 +1,15 @@
|
|||||||
import { IPermission } from '@automatisch/types';
|
import Permission from '../../src/models/permission';
|
||||||
import { createRole } from './role';
|
import { createRole } from './role';
|
||||||
|
|
||||||
type PermissionParams = {
|
export const createPermission = async (params: Partial<Permission> = {}) => {
|
||||||
roleId?: string;
|
params.roleId = params?.roleId || (await createRole()).id;
|
||||||
action?: string;
|
params.action = params?.action || 'read';
|
||||||
subject?: string;
|
params.subject = params?.subject || 'User';
|
||||||
};
|
params.conditions = params?.conditions || ['isCreator'];
|
||||||
|
|
||||||
export const createPermission = async (
|
|
||||||
params: PermissionParams = {}
|
|
||||||
): Promise<IPermission> => {
|
|
||||||
const permissionData = {
|
|
||||||
roleId: params?.roleId || (await createRole()).id,
|
|
||||||
action: params?.action || 'read',
|
|
||||||
subject: params?.subject || 'User',
|
|
||||||
};
|
|
||||||
|
|
||||||
const [permission] = await global.knex
|
const [permission] = await global.knex
|
||||||
.table('permissions')
|
.table('permissions')
|
||||||
.insert(permissionData)
|
.insert(params)
|
||||||
.returning('*');
|
.returning('*');
|
||||||
|
|
||||||
return permission;
|
return permission;
|
||||||
|
@@ -13,7 +13,9 @@ export const createStep = async (params: Partial<Step> = {}) => {
|
|||||||
.first();
|
.first();
|
||||||
|
|
||||||
params.position = params?.position || (lastStep?.position || 0) + 1;
|
params.position = params?.position || (lastStep?.position || 0) + 1;
|
||||||
params.status = params?.status || 'incomplete';
|
params.status = params?.status || 'completed';
|
||||||
|
params.appKey =
|
||||||
|
params?.appKey || (params.type === 'action' ? 'webhook' : 'deepl');
|
||||||
|
|
||||||
const [step] = await global.knex.table('steps').insert(params).returning('*');
|
const [step] = await global.knex.table('steps').insert(params).returning('*');
|
||||||
|
|
||||||
|
8
packages/types/index.d.ts
vendored
8
packages/types/index.d.ts
vendored
@@ -51,8 +51,8 @@ export interface IExecution {
|
|||||||
testRun: boolean;
|
testRun: boolean;
|
||||||
status: 'success' | 'failure';
|
status: 'success' | 'failure';
|
||||||
executionSteps: IExecutionStep[];
|
executionSteps: IExecutionStep[];
|
||||||
updatedAt: string;
|
updatedAt: string | Date;
|
||||||
createdAt: string;
|
createdAt: string | Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IStep {
|
export interface IStep {
|
||||||
@@ -83,8 +83,8 @@ export interface IFlow {
|
|||||||
active: boolean;
|
active: boolean;
|
||||||
status: 'paused' | 'published' | 'draft';
|
status: 'paused' | 'published' | 'draft';
|
||||||
steps: IStep[];
|
steps: IStep[];
|
||||||
createdAt: string;
|
createdAt: string | Date;
|
||||||
updatedAt: string;
|
updatedAt: string | Date;
|
||||||
remoteWebhookId: string;
|
remoteWebhookId: string;
|
||||||
lastInternalId: () => Promise<string>;
|
lastInternalId: () => Promise<string>;
|
||||||
}
|
}
|
||||||
|
@@ -39,11 +39,15 @@ function ExecutionId(props: Pick<IExecution, 'id'>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ExecutionDate(props: Pick<IExecution, 'createdAt'>) {
|
function ExecutionDate(props: Pick<IExecution, 'createdAt'>) {
|
||||||
const createdAt = DateTime.fromMillis(parseInt(props.createdAt, 10));
|
const createdAt = DateTime.fromMillis(
|
||||||
|
parseInt(props.createdAt as string, 10)
|
||||||
|
);
|
||||||
const relativeCreatedAt = createdAt.toRelative();
|
const relativeCreatedAt = createdAt.toRelative();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip title={createdAt.toLocaleString(DateTime.DATETIME_FULL_WITH_SECONDS)}>
|
<Tooltip
|
||||||
|
title={createdAt.toLocaleString(DateTime.DATETIME_FULL_WITH_SECONDS)}
|
||||||
|
>
|
||||||
<Typography variant="body1" gutterBottom>
|
<Typography variant="body1" gutterBottom>
|
||||||
{relativeCreatedAt}
|
{relativeCreatedAt}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
@@ -23,8 +23,10 @@ export default function ExecutionRow(
|
|||||||
const { execution } = props;
|
const { execution } = props;
|
||||||
const { flow } = execution;
|
const { flow } = execution;
|
||||||
|
|
||||||
const updatedAt = DateTime.fromMillis(parseInt(execution.updatedAt, 10));
|
const createdAt = DateTime.fromMillis(
|
||||||
const relativeUpdatedAt = updatedAt.toRelative();
|
parseInt(execution.createdAt as string, 10)
|
||||||
|
);
|
||||||
|
const relativeCreatedAt = createdAt.toRelative();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link to={URLS.EXECUTION(execution.id)} data-test="execution-row">
|
<Link to={URLS.EXECUTION(execution.id)} data-test="execution-row">
|
||||||
@@ -41,8 +43,8 @@ export default function ExecutionRow(
|
|||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Typography variant="caption" noWrap>
|
<Typography variant="caption" noWrap>
|
||||||
{formatMessage('execution.updatedAt', {
|
{formatMessage('execution.createdAt', {
|
||||||
datetime: relativeUpdatedAt,
|
datetime: relativeCreatedAt,
|
||||||
})}
|
})}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Title>
|
</Title>
|
||||||
|
@@ -65,8 +65,8 @@ export default function FlowRow(props: FlowRowProps): React.ReactElement {
|
|||||||
setAnchorEl(contextButtonRef.current);
|
setAnchorEl(contextButtonRef.current);
|
||||||
};
|
};
|
||||||
|
|
||||||
const createdAt = DateTime.fromMillis(parseInt(flow.createdAt, 10));
|
const createdAt = DateTime.fromMillis(parseInt(flow.createdAt as string, 10));
|
||||||
const updatedAt = DateTime.fromMillis(parseInt(flow.updatedAt, 10));
|
const updatedAt = DateTime.fromMillis(parseInt(flow.updatedAt as string, 10));
|
||||||
const isUpdated = updatedAt > createdAt;
|
const isUpdated = updatedAt > createdAt;
|
||||||
const relativeCreatedAt = createdAt.toRelative();
|
const relativeCreatedAt = createdAt.toRelative();
|
||||||
const relativeUpdatedAt = updatedAt.toRelative();
|
const relativeUpdatedAt = updatedAt.toRelative();
|
||||||
|
@@ -89,7 +89,7 @@
|
|||||||
"executions.title": "Executions",
|
"executions.title": "Executions",
|
||||||
"executions.noExecutions": "There is no execution data point to show.",
|
"executions.noExecutions": "There is no execution data point to show.",
|
||||||
"execution.id": "Execution ID: {id}",
|
"execution.id": "Execution ID: {id}",
|
||||||
"execution.updatedAt": "updated {datetime}",
|
"execution.createdAt": "created {datetime}",
|
||||||
"execution.test": "Test run",
|
"execution.test": "Test run",
|
||||||
"execution.statusSuccess": "Success",
|
"execution.statusSuccess": "Success",
|
||||||
"execution.statusFailure": "Failure",
|
"execution.statusFailure": "Failure",
|
||||||
|
Reference in New Issue
Block a user