This commit is contained in:
Alex Tran
2025-11-24 19:10:07 +00:00
parent 1f25422958
commit 380d03476e
12 changed files with 460 additions and 368 deletions

View File

@@ -48,8 +48,8 @@ export class WorkflowCreateDto {
}
export class WorkflowUpdateDto {
@ValidateEnum({ enum: PluginTriggerType, name: 'PluginTriggerType' })
triggerType!: PluginTriggerType;
@ValidateEnum({ enum: PluginTriggerType, name: 'PluginTriggerType', optional: true })
triggerType?: PluginTriggerType;
@IsString()
@IsNotEmpty()

View File

@@ -56,7 +56,7 @@ export class WorkflowService extends BaseService {
}
const workflow = await this.findOrFail(id);
const trigger = this.getTriggerOrFail(workflow.triggerType);
const trigger = this.getTriggerOrFail(dto.triggerType ?? workflow.triggerType);
const { filters, actions, ...workflowUpdate } = dto;
const filterInserts = filters && (await this.validateAndMapFilters(filters, trigger.context));

View File

@@ -611,6 +611,52 @@ describe(WorkflowService.name, () => {
sut.update(auth, created.id, { actions: [{ actionId: factory.uuid(), actionConfig: {} }] }),
).rejects.toThrow();
});
it('should update trigger type', async () => {
const { sut, ctx } = setup();
const { user } = await ctx.newUser();
const auth = factory.auth({ user });
const created = await sut.create(auth, {
triggerType: PluginTriggerType.PersonRecognized,
name: 'test-workflow',
description: 'Test',
enabled: true,
filters: [],
actions: [],
});
const updated = await sut.update(auth, created.id, {
triggerType: PluginTriggerType.AssetCreate,
});
expect(updated.triggerType).toBe(PluginTriggerType.AssetCreate);
});
it('should use existing trigger type when triggerType not provided in update', async () => {
const { sut, ctx } = setup();
const { user } = await ctx.newUser();
const auth = factory.auth({ user });
const created = await sut.create(auth, {
triggerType: PluginTriggerType.AssetCreate,
name: 'test-workflow',
description: 'Test',
enabled: true,
filters: [{ filterId: testFilterId }],
actions: [],
});
const updated = await sut.update(auth, created.id, {
filters: [
{ filterId: testFilterId, filterConfig: { updated: true } },
{ filterId: testFilterId, filterConfig: { second: true } },
],
});
expect(updated.triggerType).toBe(PluginTriggerType.AssetCreate);
expect(updated.filters).toHaveLength(2);
});
});
describe('delete', () => {