From 473f70f8f8efe39c4224c2bf507a18289e16cb29 Mon Sep 17 00:00:00 2001 From: JohnDoe6345789 Date: Fri, 26 Dec 2025 01:32:27 +0000 Subject: [PATCH] code: workflow,dbal,get (2 files) --- .../core/entities/workflow/create-workflow.ts | 50 ++++++++++++------- .../core/entities/workflow/get-workflow.ts | 18 ++++--- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/dbal/ts/src/core/entities/workflow/create-workflow.ts b/dbal/ts/src/core/entities/workflow/create-workflow.ts index 7c32fc7be..86207a4cc 100644 --- a/dbal/ts/src/core/entities/workflow/create-workflow.ts +++ b/dbal/ts/src/core/entities/workflow/create-workflow.ts @@ -2,35 +2,51 @@ * @file create-workflow.ts * @description Create workflow operation */ -import type { Workflow, CreateWorkflowInput, Result } from '../types'; -import type { InMemoryStore } from '../store/in-memory-store'; -import { validateWorkflowType } from '../validation/workflow-validation'; +import type { CreateWorkflowInput, Result, Workflow } from '../../types' +import type { InMemoryStore } from '../../store/in-memory-store' +import { validateWorkflowCreate } from '../../validation/validate-workflow-create' /** * Create a new workflow in the store */ -export async function createWorkflow( +export const createWorkflow = async ( store: InMemoryStore, input: CreateWorkflowInput -): Promise> { - if (!input.name || input.name.length > 100) { - return { success: false, error: { code: 'VALIDATION_ERROR', message: 'Name required (max 100)' } }; +): Promise> => { + const isActive = input.isActive ?? true + const validationErrors = validateWorkflowCreate({ + name: input.name, + description: input.description, + trigger: input.trigger, + triggerConfig: input.triggerConfig, + steps: input.steps, + isActive, + createdBy: input.createdBy + }) + + if (validationErrors.length > 0) { + return { success: false, error: { code: 'VALIDATION_ERROR', message: validationErrors[0] } } } - if (!input.type || !validateWorkflowType(input.type)) { - return { success: false, error: { code: 'VALIDATION_ERROR', message: 'Invalid workflow type' } }; + + if (store.workflowNames.has(input.name)) { + return { success: false, error: { code: 'CONFLICT', message: 'Workflow name already exists' } } } const workflow: Workflow = { id: store.generateId('workflow'), name: input.name, - description: input.description ?? '', - type: input.type, - config: input.config ?? {}, - isActive: input.isActive ?? true, + description: input.description, + trigger: input.trigger, + triggerConfig: input.triggerConfig, + steps: input.steps, + isActive, + createdBy: input.createdBy, createdAt: new Date(), - updatedAt: new Date(), - }; + updatedAt: new Date() + } - store.workflows.set(workflow.id, workflow); - return { success: true, data: workflow }; + store.workflows.set(workflow.id, workflow) + store.workflowNames.set(workflow.name, workflow.id) + + return { success: true, data: workflow } } diff --git a/dbal/ts/src/core/entities/workflow/get-workflow.ts b/dbal/ts/src/core/entities/workflow/get-workflow.ts index 68019df30..5bc19408f 100644 --- a/dbal/ts/src/core/entities/workflow/get-workflow.ts +++ b/dbal/ts/src/core/entities/workflow/get-workflow.ts @@ -2,21 +2,23 @@ * @file get-workflow.ts * @description Get workflow operation */ -import type { Workflow, Result } from '../types'; -import type { InMemoryStore } from '../store/in-memory-store'; +import type { Result, Workflow } from '../../types' +import type { InMemoryStore } from '../../store/in-memory-store' +import { validateId } from '../../validation/validate-id' /** * Get a workflow by ID */ -export async function getWorkflow(store: InMemoryStore, id: string): Promise> { - if (!id) { - return { success: false, error: { code: 'VALIDATION_ERROR', message: 'ID required' } }; +export const getWorkflow = async (store: InMemoryStore, id: string): Promise> => { + const idErrors = validateId(id) + if (idErrors.length > 0) { + return { success: false, error: { code: 'VALIDATION_ERROR', message: idErrors[0] } } } - const workflow = store.workflows.get(id); + const workflow = store.workflows.get(id) if (!workflow) { - return { success: false, error: { code: 'NOT_FOUND', message: `Workflow not found: ${id}` } }; + return { success: false, error: { code: 'NOT_FOUND', message: `Workflow not found: ${id}` } } } - return { success: true, data: workflow }; + return { success: true, data: workflow } }