@@ -32,6 +32,7 @@ import {
32
32
} from '../notice-of-intent-decision.dto' ;
33
33
import { NoticeOfIntentDecision } from '../notice-of-intent-decision.entity' ;
34
34
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' ;
35
36
36
37
@Injectable ( )
37
38
export class NoticeOfIntentDecisionV2Service {
@@ -292,26 +293,15 @@ export class NoticeOfIntentDecisionV2Service {
292
293
} ) ;
293
294
294
295
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.' ) ;
298
297
}
299
298
300
- await this . validateResolutionNumber (
301
- createDto . resolutionNumber ,
302
- createDto . resolutionYear ,
303
- ) ;
299
+ await this . validateResolutionNumber ( createDto . resolutionNumber , createDto . resolutionYear ) ;
304
300
305
301
let decisionComponents : NoticeOfIntentDecisionComponent [ ] = [ ] ;
306
302
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 ) ;
315
305
}
316
306
317
307
const decision = new NoticeOfIntentDecision ( {
@@ -321,27 +311,20 @@ export class NoticeOfIntentDecisionV2Service {
321
311
resolutionYear : createDto . resolutionYear ,
322
312
decisionMaker : createDto . decisionMaker ,
323
313
decisionMakerName : createDto . decisionMakerName ,
324
- auditDate : createDto . auditDate
325
- ? new Date ( createDto . auditDate )
326
- : undefined ,
314
+ auditDate : createDto . auditDate ? new Date ( createDto . auditDate ) : undefined ,
327
315
isDraft : true ,
328
316
isSubjectToConditions : createDto . isSubjectToConditions ,
329
317
decisionDescription : createDto . decisionDescription ,
330
- rescindedDate : createDto . rescindedDate
331
- ? new Date ( createDto . rescindedDate )
332
- : null ,
318
+ rescindedDate : createDto . rescindedDate ? new Date ( createDto . rescindedDate ) : null ,
333
319
rescindedComment : createDto . rescindedComment ,
334
320
noticeOfIntent,
335
321
modifies,
336
322
components : decisionComponents ,
337
323
} ) ;
338
324
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
+ } ) ;
345
328
346
329
if ( createDto . decisionToCopy ) {
347
330
await this . copyDecisionFields ( createDto . decisionToCopy , savedDecision ) ;
@@ -350,10 +333,7 @@ export class NoticeOfIntentDecisionV2Service {
350
333
return this . get ( savedDecision . uuid ) ;
351
334
}
352
335
353
- private async copyDecisionFields (
354
- decisionToCopy : string ,
355
- decision : NoticeOfIntentDecision ,
356
- ) {
336
+ private async copyDecisionFields ( decisionToCopy : string , decision : NoticeOfIntentDecision ) {
357
337
//It is intentional to only copy select fields
358
338
const existingDecision = await this . get ( decisionToCopy ) ;
359
339
decision . decisionMaker = existingDecision . decisionMaker ;
@@ -377,23 +357,22 @@ export class NoticeOfIntentDecisionV2Service {
377
357
conditions : [ ] ,
378
358
} ) ,
379
359
) ;
380
- const savedDecision =
381
- await this . noticeOfIntentDecisionRepository . save ( decision ) ;
360
+ const savedDecision = await this . noticeOfIntentDecisionRepository . save ( decision ) ;
382
361
383
362
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
+ } ) ;
387
370
return new NoticeOfIntentDecisionCondition ( {
388
371
...condition ,
389
372
uuid : undefined ,
390
373
components : savedDecision . components . filter ( ( component ) => {
391
374
const oldUuid = newToOldComponentsUuid . get ( component . uuid ) ;
392
- return (
393
- ! ! oldUuid &&
394
- conditionsComponents &&
395
- conditionsComponents . includes ( oldUuid )
396
- ) ;
375
+ return ! ! oldUuid && conditionsComponents && conditionsComponents . includes ( oldUuid ) ;
397
376
} ) ,
398
377
} ) ;
399
378
} ) ;
0 commit comments