-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
183 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 63 additions & 41 deletions
104
apps/api/src/app/workflows-v2/shared/schemas/workflow-zod-schemas.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,85 @@ | ||
import { z } from 'zod'; | ||
import { StepTypeEnum, WorkflowCreationSourceEnum, WorkflowOriginEnum, WorkflowStatusEnum } from '@novu/shared'; | ||
import { ChannelTypeEnum, StepTypeEnum } from '@novu/shared'; | ||
|
||
export const stepDtoSchema = z.object({ | ||
name: z.string().min(1), | ||
// Define the StepDto schema | ||
const StepDtoSchema = z.object({ | ||
name: z.string().nonempty(), | ||
type: z.nativeEnum(StepTypeEnum), | ||
}); | ||
|
||
export const stepResponseDtoSchema = stepDtoSchema.extend({ | ||
_id: z.string().min(1), | ||
slug: z.string().min(1), | ||
stepId: z.string().min(1), | ||
// Define the WorkflowCommonsFields schema | ||
const WorkflowCommonsFieldsSchema = z.object({ | ||
tags: z.array(z.string()).optional(), | ||
active: z.boolean().optional(), | ||
name: z.string().nonempty(), | ||
workflowId: z.string().nonempty(), | ||
description: z.string().optional(), | ||
}); | ||
|
||
export const stepCreateDtoSchema = stepDtoSchema.extend({ | ||
controlValues: z.record(z.unknown()), | ||
// Define the PreferencesRequestDto schema | ||
const PreferencesRequestDtoSchema = z.object({ | ||
user: z.union([z.lazy(() => WorkflowPreferencesSchema), z.null()]), | ||
workflow: z.union([z.lazy(() => WorkflowPreferencesSchema), z.null()]).optional(), | ||
}); | ||
|
||
export const stepUpdateDtoSchema = stepCreateDtoSchema.extend({ | ||
_id: z.string().min(1), | ||
// Define the WorkflowPreferences schema | ||
const WorkflowPreferenceSchema = z.object({ | ||
enabled: z.boolean().default(true), | ||
readOnly: z.boolean().default(false), | ||
}); | ||
|
||
export const preferencesResponseDtoSchema = z.object({ | ||
user: z.union([z.lazy(() => z.object({})), z.null()]), | ||
default: z.object({}), | ||
const ChannelPreferenceSchema = z.object({ | ||
enabled: z.boolean().default(true), | ||
}); | ||
|
||
export const preferencesRequestDtoSchema = z.object({ | ||
user: z.union([z.lazy(() => z.object({})), z.null()]), | ||
workflow: z.union([z.lazy(() => z.object({})), z.null()]).optional(), | ||
const WorkflowPreferencesSchema = z.object({ | ||
all: WorkflowPreferenceSchema, | ||
channels: z.record(z.nativeEnum(ChannelTypeEnum), ChannelPreferenceSchema), | ||
}); | ||
|
||
export const workflowCommonsFieldsSchema = z.object({ | ||
tags: z.array(z.string()).optional(), | ||
active: z.boolean().optional(), | ||
name: z.string().min(1), | ||
workflowId: z.string().min(1), | ||
description: z.string().optional(), | ||
// Define the StepCreateDto schema | ||
const StepCreateDtoSchema = StepDtoSchema.extend({ | ||
controlValues: z.record(z.string()).optional(), | ||
}); | ||
|
||
export const workflowResponseDtoSchema = workflowCommonsFieldsSchema.extend({ | ||
_id: z.string().min(1), | ||
slug: z.string().min(1), | ||
updatedAt: z.string().min(1), | ||
createdAt: z.string().min(1), | ||
steps: z.array(stepResponseDtoSchema).min(1), | ||
origin: z.nativeEnum(WorkflowOriginEnum), | ||
preferences: preferencesResponseDtoSchema, | ||
status: z.nativeEnum(WorkflowStatusEnum), | ||
issues: z.record(z.unknown()).optional(), | ||
// Define the StepUpdateDto schema | ||
const StepUpdateDtoSchema = StepCreateDtoSchema.extend({ | ||
_id: z.string().nonempty(), | ||
}); | ||
|
||
export const updateWorkflowDtoSchema = workflowCommonsFieldsSchema.extend({ | ||
updatedAt: z.string().min(1), | ||
steps: z.array(z.union([stepCreateDtoSchema, stepUpdateDtoSchema])).min(1), | ||
preferences: preferencesRequestDtoSchema, | ||
// Define the UpdateWorkflowDto schema | ||
const UpdateWorkflowDtoSchema = WorkflowCommonsFieldsSchema.extend({ | ||
updatedAt: z.string().nonempty(), // Assuming updatedAt is a string representing a date | ||
steps: z.array(z.union([StepCreateDtoSchema, StepUpdateDtoSchema])), | ||
preferences: PreferencesRequestDtoSchema, | ||
}); | ||
|
||
export const createWorkflowDtoSchema = workflowCommonsFieldsSchema.extend({ | ||
steps: z.array(stepCreateDtoSchema).min(1), | ||
__source: z.nativeEnum(WorkflowCreationSourceEnum), | ||
preferences: preferencesRequestDtoSchema.optional(), | ||
// Define the ListWorkflowResponse schema | ||
const ListWorkflowResponseSchema = z.object({ | ||
workflows: z.array( | ||
z.object({ | ||
name: z.string(), | ||
tags: z.array(z.string()), | ||
updatedAt: z.string(), | ||
createdAt: z.string(), | ||
_id: z.string(), | ||
slug: z.string(), | ||
status: z.string(), | ||
origin: z.string(), | ||
stepTypeOverviews: z.array(z.nativeEnum(StepTypeEnum)), | ||
}) | ||
), | ||
totalCount: z.number(), | ||
}); | ||
|
||
// Export all schemas for use in other parts of the application | ||
export { | ||
StepDtoSchema, | ||
WorkflowCommonsFieldsSchema, | ||
PreferencesRequestDtoSchema, | ||
WorkflowPreferencesSchema, | ||
StepCreateDtoSchema, | ||
StepUpdateDtoSchema, | ||
UpdateWorkflowDtoSchema, | ||
ListWorkflowResponseSchema, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
apps/api/src/app/workflows-v2/usecases/get-step-schema/get-step-schema.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.