Skip to content

Commit 1741e29

Browse files
fix(api): update workflow fetching logic to include updatedBy flag and adjust boolean parameters
1 parent 1d214e2 commit 1741e29

File tree

7 files changed

+114
-88
lines changed

7 files changed

+114
-88
lines changed

apps/api/src/app/bridge/bridge.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class BridgeController {
169169
user.environmentId,
170170
workflowId,
171171
undefined,
172-
true
172+
false
173173
);
174174
if (!workflowExist) {
175175
throw new NotFoundException('Workflow not found');

apps/api/src/app/events/usecases/parse-event-request/parse-event-request.usecase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ export class ParseEventRequest {
404404
command.environmentId,
405405
command.triggerIdentifier,
406406
undefined,
407-
true
407+
false
408408
);
409409
}
410410

apps/api/src/app/workflows-v1/usecases/get-workflow-with-preferences/get-workflow-with-preferences.usecase.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class GetWorkflowWithPreferencesUseCase {
2626
organizationId: command.organizationId,
2727
userId: command.userId,
2828
session: command.session,
29+
includeUpdatedBy: true,
2930
});
3031

3132
const workflowPreferences = await this.getWorkflowPreferences(command, workflowEntity);

apps/api/src/app/workflows-v2/usecases/sync-to-environment/sync-to-environment.usecase.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export class SyncToEnvironmentUseCase {
217217
tags: sourceWorkflow.tags,
218218
description: sourceWorkflow.description,
219219
__source: WorkflowCreationSourceEnum.DASHBOARD,
220+
severity: sourceWorkflow.severity,
220221
steps: await this.mapStepsToCreateOrUpdateDto(sourceWorkflow.steps),
221222
preferences: this.mapPreferences(preferences),
222223
};
@@ -237,6 +238,7 @@ export class SyncToEnvironmentUseCase {
237238
active: sourceWorkflow.active,
238239
tags: sourceWorkflow.tags,
239240
description: sourceWorkflow.description,
241+
severity: sourceWorkflow.severity,
240242
steps: await this.mapStepsToCreateOrUpdateDto(sourceWorkflow.steps, existingTargetEnvWorkflow?.steps),
241243
preferences: this.mapPreferences(preferencesToClone),
242244
};

libs/application-generic/src/usecases/workflow/get-workflow-by-ids/get-workflow-by-ids.command.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export class GetWorkflowByIdsCommand extends EnvironmentCommand {
1212
@IsString()
1313
userId?: string;
1414

15+
@IsOptional()
16+
includeUpdatedBy?: boolean;
17+
1518
@IsOptional()
1619
@Exclude()
1720
session?: ClientSession | null;

libs/application-generic/src/usecases/workflow/get-workflow-by-ids/get-workflow-by-ids.usecase.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ export class GetWorkflowByIdsUseCase {
1616
workflowEntity = await this.notificationTemplateRepository.findById(
1717
command.workflowIdOrInternalId,
1818
command.environmentId,
19-
command.session
19+
command.session,
20+
command.includeUpdatedBy || false
2021
);
2122
} else {
2223
workflowEntity = await this.notificationTemplateRepository.findByTriggerIdentifier(
2324
command.environmentId,
2425
command.workflowIdOrInternalId,
2526
command.session,
26-
true
27+
command.includeUpdatedBy || false
2728
);
2829
}
2930

libs/dal/src/repositories/notification-template/notification-template.repository.ts

Lines changed: 103 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class NotificationTemplateRepository extends BaseRepository<
8080
environmentId: string,
8181
identifier: string,
8282
session?: ClientSession | null,
83-
skipUpdatedBy: boolean = false
83+
includeUpdatedBy: boolean = true
8484
) {
8585
const requestQuery: NotificationTemplateQuery = {
8686
_environmentId: environmentId,
@@ -89,7 +89,7 @@ export class NotificationTemplateRepository extends BaseRepository<
8989

9090
const query = this.MongooseModel.findOne(requestQuery, undefined, { session }).populate('steps.template');
9191

92-
if (!skipUpdatedBy) {
92+
if (includeUpdatedBy) {
9393
query.populate('updatedBy');
9494
}
9595

@@ -113,7 +113,7 @@ export class NotificationTemplateRepository extends BaseRepository<
113113
return this.mapEntities(query);
114114
}
115115

116-
async findById(id: string, environmentId: string, session?: ClientSession | null) {
116+
async findById(id: string, environmentId: string, session?: ClientSession | null, includeUpdatedBy: boolean = true) {
117117
const query = this.MongooseModel.findOne(
118118
{
119119
_id: id,
@@ -124,110 +124,129 @@ export class NotificationTemplateRepository extends BaseRepository<
124124
)
125125
.populate('steps.template')
126126
.populate('steps.variants.template')
127-
.populate('updatedBy');
128127

129-
const item = await query;
128+
if (includeUpdatedBy) {
129+
query.populate('updatedBy');
130+
}
130131

131-
return this.mapEntity(item);
132-
}
132+
const item = await query;
133133

134-
async findByTriggerIdentifierAndUpdate(environmentId: string, triggerIdentifier: string, lastTriggeredAt: Date) {
135-
const requestQuery: NotificationTemplateQuery = {
136-
_environmentId: environmentId,
137-
'triggers.identifier': triggerIdentifier,
138-
};
134+
return this.mapEntity(item);
135+
}
139136

140-
const item = await this.MongooseModel.findOneAndUpdate(
141-
requestQuery,
142-
{
143-
$set: {
144-
lastTriggeredAt,
137+
async;
138+
findByTriggerIdentifierAndUpdate(environmentId: string, triggerIdentifier: string, lastTriggeredAt: Date)
139+
{
140+
const requestQuery: NotificationTemplateQuery = {
141+
_environmentId: environmentId,
142+
'triggers.identifier': triggerIdentifier,
143+
};
144+
145+
const item = await this.MongooseModel.findOneAndUpdate(
146+
requestQuery,
147+
{
148+
$set: {
149+
lastTriggeredAt,
150+
},
145151
},
146-
},
147-
{
148-
timestamps: false,
149-
}
150-
).populate('steps.template');
151-
152-
return this.mapEntity(item);
153-
}
152+
{
153+
timestamps: false,
154+
}
155+
).populate('steps.template');
154156

155-
async updatePublishFields(workflowId: string, environmentId: string, userId: string, session?: ClientSession | null) {
156-
const requestQuery: NotificationTemplateQuery = {
157-
_id: workflowId,
158-
_environmentId: environmentId,
159-
};
157+
return this.mapEntity(item);
158+
}
160159

161-
const item = await this.MongooseModel.findOneAndUpdate(
162-
requestQuery,
163-
{
164-
$set: {
165-
lastPublishedAt: new Date(),
166-
_lastPublishedBy: userId,
160+
async;
161+
updatePublishFields(workflowId: string, environmentId: string, userId: string, session?: ClientSession | null)
162+
{
163+
const requestQuery: NotificationTemplateQuery = {
164+
_id: workflowId,
165+
_environmentId: environmentId,
166+
};
167+
168+
const item = await this.MongooseModel.findOneAndUpdate(
169+
requestQuery,
170+
{
171+
$set: {
172+
lastPublishedAt: new Date(),
173+
_lastPublishedBy: userId,
174+
},
167175
},
168-
},
169-
{ session, new: true }
170-
);
176+
{ session, new: true }
177+
);
171178

172-
return this.mapEntity(item);
173-
}
179+
return this.mapEntity(item);
180+
}
174181

175-
async findBlueprintById(id: string) {
176-
if (!this.blueprintOrganizationId) throw new DalException('Blueprint environment id was not found');
182+
async;
183+
findBlueprintById(id: string)
184+
{
185+
if (!this.blueprintOrganizationId) throw new DalException('Blueprint environment id was not found');
177186

178-
const requestQuery: NotificationTemplateQuery = {
179-
isBlueprint: true,
180-
_organizationId: this.blueprintOrganizationId,
181-
_id: id,
182-
};
187+
const requestQuery: NotificationTemplateQuery = {
188+
isBlueprint: true,
189+
_organizationId: this.blueprintOrganizationId,
190+
_id: id,
191+
};
183192

184-
const item = await this.MongooseModel.findOne(requestQuery)
185-
.populate('steps.template')
186-
.populate('notificationGroup')
187-
.lean();
193+
const item = await this.MongooseModel.findOne(requestQuery)
194+
.populate('steps.template')
195+
.populate('notificationGroup')
196+
.lean();
188197

189-
return this.mapEntity(item);
190-
}
198+
return this.mapEntity(item);
199+
}
191200

192-
async findBlueprintByTriggerIdentifier(identifier: string) {
193-
if (!this.blueprintOrganizationId) throw new DalException('Blueprint environment id was not found');
201+
async;
202+
findBlueprintByTriggerIdentifier(identifier: string)
203+
{
204+
if (!this.blueprintOrganizationId) throw new DalException('Blueprint environment id was not found');
194205

195-
const requestQuery: NotificationTemplateQuery = {
196-
isBlueprint: true,
197-
_organizationId: this.blueprintOrganizationId,
198-
triggers: { $elemMatch: { identifier } },
199-
};
206+
const requestQuery: NotificationTemplateQuery = {
207+
isBlueprint: true,
208+
_organizationId: this.blueprintOrganizationId,
209+
triggers: { $elemMatch: { identifier } },
210+
};
200211

201-
const item = await this.MongooseModel.findOne(requestQuery)
202-
.populate('steps.template')
203-
.populate('notificationGroup')
204-
.lean();
212+
const item = await this.MongooseModel.findOne(requestQuery)
213+
.populate('steps.template')
214+
.populate('notificationGroup')
215+
.lean();
205216

206-
return this.mapEntity(item);
207-
}
217+
return this.mapEntity(item);
218+
}
208219

209-
async findBlueprintTemplates(organizationId: string, environmentId: string): Promise<NotificationTemplateEntity[]> {
210-
const _organizationId = organizationId;
220+
async;
221+
findBlueprintTemplates(organizationId: string, environmentId: string)
222+
: Promise<NotificationTemplateEntity[]>
223+
{
224+
const _organizationId = organizationId;
211225

212-
if (!_organizationId) throw new DalException('Blueprint environment id was not found');
226+
if (!_organizationId) throw new DalException('Blueprint environment id was not found');
213227

214-
const templates = await this.MongooseModel.find({
215-
isBlueprint: true,
216-
_environmentId: environmentId,
217-
_organizationId,
218-
})
219-
.populate('steps.template')
220-
.populate('notificationGroup')
221-
.lean();
228+
const templates = await this.MongooseModel.find({
229+
isBlueprint: true,
230+
_environmentId: environmentId,
231+
_organizationId,
232+
})
233+
.populate('steps.template')
234+
.populate('notificationGroup')
235+
.lean();
222236

223-
if (!templates) {
224-
return [];
225-
}
237+
if (!templates) {
238+
return [];
239+
}
226240

227-
return this.mapEntities(templates);
228-
}
241+
return this.mapEntities(templates);
242+
}
229243

230-
async findAllGroupedByCategory(): Promise<{ name: string; blueprints: NotificationTemplateEntity[] }[]> {
244+
async;
245+
findAllGroupedByCategory();
246+
: Promise<
247+
name: string;
248+
blueprints: NotificationTemplateEntity[]
249+
[]> {
231250
const organizationId = this.blueprintOrganizationId;
232251

233252
if (!organizationId) {

0 commit comments

Comments
 (0)