Skip to content

Commit

Permalink
Updated swagger schema of get workflow by id endpoint (#2762)
Browse files Browse the repository at this point in the history
* feat: updated swagger schema of get workflow by id endpoint

* feat: small changes

* feat: more small changes
  • Loading branch information
tomer-shvadron authored Oct 9, 2024
1 parent f9b7358 commit dbecc50
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Warnings:
- You are about to drop the column `backend` on the `WorkflowDefinition` table. All the data in the column will be lost.
- You are about to drop the column `supportedPlatforms` on the `WorkflowDefinition` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "WorkflowDefinition" DROP COLUMN "backend",
DROP COLUMN "supportedPlatforms";
2 changes: 0 additions & 2 deletions services/workflows-service/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,9 @@ model WorkflowDefinition {
contextSchema Json?
documentsSchema Json?
config Json?
supportedPlatforms Json?
extensions Json?
variant String @default("DEFAULT")
backend Json?
persistStates Json?
submitStates Json?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ export const WorkflowDefinitionWhereInput = z.lazy(() =>
version: z.union([IntFilterSchema, z.number()]).optional(),
definitionType: zStringFilterStringUnion.optional(),
definition: z.unknown().optional(),
supportedPlatforms: z.unknown().optional(),
extensions: z.unknown().optional(),
backend: z.unknown().optional(),
persistStates: z.unknown().optional(),
submitStates: z.unknown().optional(),
createdAt: zDateTimeFilterDateStringUnion.optional(),
Expand All @@ -235,9 +233,7 @@ export const WorkflowDefinitionWhereInputSchema = z.object({
version: IntFilterSchema.optional(),
definitionType: zStringFilterStringUnion.optional(),
definition: z.unknown().optional(),
supportedPlatforms: z.unknown().optional(),
extensions: z.unknown().optional(),
backend: z.unknown().optional(),
persistStates: z.unknown().optional(),
submitStates: z.unknown().optional(),
createdAt: zDateTimeFilterDateStringUnion.optional(),
Expand Down Expand Up @@ -288,9 +284,7 @@ export const WorkflowDefinitionSelectSchema = z.object({
version: z.boolean().optional(),
definitionType: z.boolean().optional(),
definition: z.boolean().optional(),
supportedPlatforms: z.boolean().optional(),
extensions: z.boolean().optional(),
backend: z.boolean().optional(),
persistStates: z.boolean().optional(),
submitStates: z.boolean().optional(),
createdAt: z.boolean().optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ export class WorkflowDefinitionCreateDto {
@IsObject()
config?: Record<string, unknown> | null;

@ApiProperty({ required: false, type: Array, nullable: true })
@IsOptional()
@IsArray()
supportedPlatforms?: unknown[] | null;

@ApiProperty({ required: false, type: Object, nullable: true })
@IsOptional()
@IsObject()
Expand All @@ -88,11 +83,6 @@ export class WorkflowDefinitionCreateDto {
@IsString()
variant?: string;

@ApiProperty({ required: false, type: Object, nullable: true })
@IsOptional()
@IsObject()
backend?: Record<string, unknown> | null;

@ApiProperty({ required: false, type: Array, nullable: true })
@IsOptional()
@IsArray()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
import { UserModel } from '@/user/user.model';
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
IsArray,
IsBoolean,
IsDate,
IsNotEmptyObject,
IsNumber,
IsObject,
IsOptional,
IsString,
ValidateNested,
} from 'class-validator';
import type { JsonValue } from 'type-fest';

export class WorkflowDefinitionModel {
@IsString()
id!: string;

@ApiProperty({
required: true,
type: () => UserModel,
})
@ValidateNested()
@Type(() => UserModel)
user?: UserModel;
@ApiProperty({ required: false, type: String })
@IsOptional()
@IsString()
crossEnvKey?: string;

@ApiProperty({ required: false, type: String })
@IsOptional()
@IsString()
projectId?: string;

@ApiProperty({ required: false, type: Boolean })
@IsOptional()
@IsBoolean()
isPublic?: boolean;

@ApiProperty({ required: false, type: String })
@IsOptional()
@IsString()
displayName?: string;

@ApiProperty({ required: false, type: String })
@IsOptional()
@IsString()
reviewMachineId?: string;

@ApiProperty({ required: false, type: String })
@IsOptional()
@IsString()
variant?: string;

@ApiProperty({
required: true,
Expand Down Expand Up @@ -67,31 +88,31 @@ export class WorkflowDefinitionModel {
})
@IsObject()
@IsOptional()
context?: JsonValue;
contextSchema?: JsonValue;

@ApiProperty({
required: false,
type: 'object',
})
@IsObject()
@IsOptional()
config?: JsonValue;
documentsSchema?: JsonValue;

@ApiProperty({
required: false,
type: 'object',
})
@IsNotEmptyObject()
@IsObject()
@IsOptional()
extensions?: JsonValue;
config?: JsonValue;

@ApiProperty({
required: false,
type: 'object',
})
@IsNotEmptyObject()
@IsOptional()
backend?: JsonValue;
extensions?: JsonValue;

@ApiProperty({
required: false,
Expand All @@ -113,6 +134,11 @@ export class WorkflowDefinitionModel {
@Type(() => Date)
createdAt!: Date;

@ApiProperty({ required: false, type: String })
@IsOptional()
@IsString()
createdBy?: string;

@IsDate()
@Type(() => Date)
updatedAt!: Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { IsNullable } from '@/common/decorators/is-nullable.decorator';
import { ApiProperty } from '@nestjs/swagger';
import { WorkflowRuntimeDataStatus } from '@prisma/client';
import { Expose } from 'class-transformer';
import { IsDate, IsJSON, IsNotEmptyObject, IsString, ValidateNested } from 'class-validator';
import {
IsArray,
IsDate,
IsJSON,
IsNotEmptyObject,
IsNumber,
IsOptional,
IsString,
ValidateNested,
} from 'class-validator';

export class WorkflowAssignee {
@Expose()
Expand All @@ -22,6 +31,55 @@ export class WorkflowRuntimeListItemModel {
@IsString()
id!: string;

@Expose()
@ApiProperty({ required: false, type: String })
@IsOptional()
@IsString()
projectId?: string;

@ApiProperty({ required: false, type: String })
@IsOptional()
@IsNullable()
@IsString()
salesforceObjectName?: string | null;

@ApiProperty({ required: false, type: String })
@IsOptional()
@IsNullable()
@IsString()
salesforceRecordId?: string | null;

@ApiProperty({ required: false, type: String })
@IsOptional()
@IsNullable()
@IsString()
parentRuntimeDataId?: string | null;

@ApiProperty({ required: false, type: String })
@IsOptional()
@IsString()
endUserId?: string;

@ApiProperty({ required: false, type: String })
@IsOptional()
@IsString()
businessId?: string;

@ApiProperty({ required: false, type: String })
@IsOptional()
@IsString()
assigneeId?: string;

@ApiProperty({ required: false, type: String })
@IsOptional()
@IsString()
uiDefinitionId?: string;

@ApiProperty({ required: false, type: Number })
@IsOptional()
@IsNumber()
workflowDefinitionVersion?: number;

@Expose()
@ApiProperty()
@IsString()
Expand All @@ -47,15 +105,28 @@ export class WorkflowRuntimeListItemModel {
@IsJSON()
context!: JSON;

@Expose()
@ApiProperty()
@IsJSON()
config!: JSON;

@Expose()
@IsNullable()
@IsString()
state!: string | null;

@Expose()
@IsNullable()
@IsOptional()
@IsArray()
@IsString({ each: true })
tags?: string[] | null;

@Expose()
@IsNullable()
@IsOptional()
@ValidateNested()
assignee!: WorkflowAssignee | null;
assignee?: WorkflowAssignee | null;

@Expose()
@IsString()
Expand All @@ -75,4 +146,9 @@ export class WorkflowRuntimeListItemModel {
@ApiProperty()
@IsDate()
updatedAt!: Date;

@ApiProperty()
@IsOptional()
@IsDate()
assignedAt?: Date;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as common from '@nestjs/common';
import { HttpStatus, NotFoundException, Query, Res } from '@nestjs/common';
import * as swagger from '@nestjs/swagger';
import { ApiOkResponse, ApiResponse } from '@nestjs/swagger';
import { WorkflowRuntimeData } from '@prisma/client';
import type { WorkflowRuntimeData } from '@prisma/client';
// import * as nestAccessControl from 'nest-access-control';
import { WorkflowTokenService } from '@/auth/workflow-token/workflow-token.service';
import { putPluginsExampleResponse } from '@/workflow/workflow-controller-examples';
Expand Down Expand Up @@ -36,7 +36,6 @@ import {
WorkflowDefinitionWhereUniqueInput,
WorkflowDefinitionWhereUniqueInputSchema,
} from './dtos/workflow-where-unique-input';
import { RunnableWorkflowData } from './types';
import { WorkflowDefinitionModel } from './workflow-definition.model';
import { WorkflowService } from './workflow.service';
import { Validate } from 'ballerine-nestjs-typebox';
Expand All @@ -45,6 +44,7 @@ import { type Static, Type } from '@sinclair/typebox';
import { defaultContextSchema } from '@ballerine/common';
import { WorkflowRunSchema } from './schemas/workflow-run';
import { ValidationError } from '@/errors';
import { WorkflowRuntimeListItemModel } from '@/workflow/workflow-runtime-list-item.model';

export const WORKFLOW_TAG = 'Workflows';
@swagger.ApiBearerAuth()
Expand Down Expand Up @@ -181,14 +181,14 @@ export class WorkflowControllerExternal {
}

@common.Get('/:id')
@swagger.ApiOkResponse({ type: WorkflowDefinitionModel })
@swagger.ApiOkResponse({ type: WorkflowRuntimeListItemModel })
@swagger.ApiNotFoundResponse({ type: errors.NotFoundException })
@swagger.ApiForbiddenResponse({ type: errors.ForbiddenException })
@UseCustomerAuthGuard()
async getRunnableWorkflowDataById(
@common.Param() params: WorkflowDefinitionWhereUniqueInput,
@ProjectIds() projectIds: TProjectIds,
): Promise<RunnableWorkflowData> {
): Promise<WorkflowRuntimeData> {
const workflowRuntimeData = await this.service.getWorkflowRuntimeDataById(
params.id,
{},
Expand All @@ -199,16 +199,7 @@ export class WorkflowControllerExternal {
throw new NotFoundException(`No resource with id [${params.id}] was found`);
}

const workflowDefinition = await this.service.getWorkflowDefinitionById(
workflowRuntimeData.workflowDefinitionId,
{},
projectIds,
);

return {
workflowDefinition,
workflowRuntimeData,
};
return workflowRuntimeData;
}

// PATCH /workflows/:id
Expand Down
Loading

0 comments on commit dbecc50

Please sign in to comment.