Skip to content

Commit 91b6153

Browse files
authored
Merge pull request #2088 from bcgov/hotfix/ALCS-2487-create-new-dates-instead-of-update-DEV-MERGE
ALCS-2478 Create new dates when duplicating conditions
2 parents e5453ec + 6d50ee1 commit 91b6153

File tree

2 files changed

+28
-41
lines changed

2 files changed

+28
-41
lines changed

services/apps/alcs/src/alcs/application-decision/application-decision-v2/application-decision/application-decision-v2.service.ts

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { ApplicationDecisionComponentType } from './component/application-decisi
3232
import { ApplicationDecisionComponent } from './component/application-decision-component.entity';
3333
import { ApplicationDecisionComponentService } from './component/application-decision-component.service';
3434
import { ApplicationDecisionConditionCardService } from '../../application-decision-condition/application-decision-condition-card/application-decision-condition-card.service';
35+
import { ApplicationDecisionConditionDate } from '../../application-decision-condition/application-decision-condition-date/application-decision-condition-date.entity';
3536

3637
@Injectable()
3738
export class ApplicationDecisionV2Service {
@@ -428,10 +429,17 @@ export class ApplicationDecisionV2Service {
428429
conditions: [],
429430
}),
430431
);
432+
431433
const savedDecision = await this.appDecisionRepository.save(decision);
432434

433435
savedDecision.conditions = existingDecision.conditions.map((condition) => {
434436
const conditionsComponents = condition.components?.map((component) => component.uuid);
437+
condition.dates = condition.dates?.map((d) => {
438+
return new ApplicationDecisionConditionDate({
439+
...d,
440+
uuid: undefined,
441+
});
442+
});
435443
return new ApplicationDecisionCondition({
436444
...condition,
437445
uuid: undefined,

services/apps/alcs/src/alcs/notice-of-intent-decision/notice-of-intent-decision-v2/notice-of-intent-decision-v2.service.ts

+20-41
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
} from '../notice-of-intent-decision.dto';
3333
import { NoticeOfIntentDecision } from '../notice-of-intent-decision.entity';
3434
import { NoticeOfIntentModification } from '../notice-of-intent-modification/notice-of-intent-modification.entity';
35+
import { NoticeOfIntentDecisionConditionDate } from '../notice-of-intent-decision-condition/notice-of-intent-decision-condition-date/notice-of-intent-decision-condition-date.entity';
3536

3637
@Injectable()
3738
export class NoticeOfIntentDecisionV2Service {
@@ -292,26 +293,15 @@ export class NoticeOfIntentDecisionV2Service {
292293
});
293294

294295
if (isDraftExists) {
295-
throw new ServiceValidationException(
296-
'Draft decision already exists for this notice of intent.',
297-
);
296+
throw new ServiceValidationException('Draft decision already exists for this notice of intent.');
298297
}
299298

300-
await this.validateResolutionNumber(
301-
createDto.resolutionNumber,
302-
createDto.resolutionYear,
303-
);
299+
await this.validateResolutionNumber(createDto.resolutionNumber, createDto.resolutionYear);
304300

305301
let decisionComponents: NoticeOfIntentDecisionComponent[] = [];
306302
if (createDto.decisionComponents) {
307-
this.decisionComponentService.validate(
308-
createDto.decisionComponents,
309-
createDto.isDraft,
310-
);
311-
decisionComponents = await this.decisionComponentService.createOrUpdate(
312-
createDto.decisionComponents,
313-
false,
314-
);
303+
this.decisionComponentService.validate(createDto.decisionComponents, createDto.isDraft);
304+
decisionComponents = await this.decisionComponentService.createOrUpdate(createDto.decisionComponents, false);
315305
}
316306

317307
const decision = new NoticeOfIntentDecision({
@@ -321,27 +311,20 @@ export class NoticeOfIntentDecisionV2Service {
321311
resolutionYear: createDto.resolutionYear,
322312
decisionMaker: createDto.decisionMaker,
323313
decisionMakerName: createDto.decisionMakerName,
324-
auditDate: createDto.auditDate
325-
? new Date(createDto.auditDate)
326-
: undefined,
314+
auditDate: createDto.auditDate ? new Date(createDto.auditDate) : undefined,
327315
isDraft: true,
328316
isSubjectToConditions: createDto.isSubjectToConditions,
329317
decisionDescription: createDto.decisionDescription,
330-
rescindedDate: createDto.rescindedDate
331-
? new Date(createDto.rescindedDate)
332-
: null,
318+
rescindedDate: createDto.rescindedDate ? new Date(createDto.rescindedDate) : null,
333319
rescindedComment: createDto.rescindedComment,
334320
noticeOfIntent,
335321
modifies,
336322
components: decisionComponents,
337323
});
338324

339-
const savedDecision = await this.noticeOfIntentDecisionRepository.save(
340-
decision,
341-
{
342-
transaction: true,
343-
},
344-
);
325+
const savedDecision = await this.noticeOfIntentDecisionRepository.save(decision, {
326+
transaction: true,
327+
});
345328

346329
if (createDto.decisionToCopy) {
347330
await this.copyDecisionFields(createDto.decisionToCopy, savedDecision);
@@ -350,10 +333,7 @@ export class NoticeOfIntentDecisionV2Service {
350333
return this.get(savedDecision.uuid);
351334
}
352335

353-
private async copyDecisionFields(
354-
decisionToCopy: string,
355-
decision: NoticeOfIntentDecision,
356-
) {
336+
private async copyDecisionFields(decisionToCopy: string, decision: NoticeOfIntentDecision) {
357337
//It is intentional to only copy select fields
358338
const existingDecision = await this.get(decisionToCopy);
359339
decision.decisionMaker = existingDecision.decisionMaker;
@@ -377,23 +357,22 @@ export class NoticeOfIntentDecisionV2Service {
377357
conditions: [],
378358
}),
379359
);
380-
const savedDecision =
381-
await this.noticeOfIntentDecisionRepository.save(decision);
360+
const savedDecision = await this.noticeOfIntentDecisionRepository.save(decision);
382361

383362
savedDecision.conditions = existingDecision.conditions.map((condition) => {
384-
const conditionsComponents = condition.components?.map(
385-
(component) => component.uuid,
386-
);
363+
const conditionsComponents = condition.components?.map((component) => component.uuid);
364+
condition.dates = condition.dates?.map((d) => {
365+
return new NoticeOfIntentDecisionConditionDate({
366+
...d,
367+
uuid: undefined,
368+
});
369+
});
387370
return new NoticeOfIntentDecisionCondition({
388371
...condition,
389372
uuid: undefined,
390373
components: savedDecision.components.filter((component) => {
391374
const oldUuid = newToOldComponentsUuid.get(component.uuid);
392-
return (
393-
!!oldUuid &&
394-
conditionsComponents &&
395-
conditionsComponents.includes(oldUuid)
396-
);
375+
return !!oldUuid && conditionsComponents && conditionsComponents.includes(oldUuid);
397376
}),
398377
});
399378
});

0 commit comments

Comments
 (0)