@contrail/flexplm 1.1.65 → 1.1.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { BaseProcessPublishAssortment } from './base-process-publish-assortment';
2
- import { apc_2bOWR2j9R0QThDVu_delete_history, fall_2003_deleteChanges_run2, fall_2003_fedMapping, fall_2003_fullChange, fall_2003_fullChange_run2, fall_2003_hydratedDetails, fall_2003_hydratedDetails_run2, plan1_across_month_DST, plan1_history, plan1_history_descending } from './mockData';
2
+ import { apc_2bOWR2j9R0QThDVu_delete_history, fall_2003_deleteChanges_run2, fall_2003_fedMapping, fall_2003_fullChange, fall_2003_fullChange_run2, fall_2003_hydratedDetails, fall_2003_hydratedDetails_run2, plan1_across_month_DST, plan1_history } from './mockData';
3
3
  import { FCConfig, SeasonFederation } from '../interfaces/interfaces';
4
4
  import { DataConverter } from '../util/data-converter';
5
5
  import { PublishChangeData } from '../interfaces/publish-change-data';
@@ -8,7 +8,6 @@ import { Entities } from '@contrail/sdk';
8
8
  import { TypeConversionUtils } from '../util/type-conversion-utils';
9
9
  import { MapUtil } from '../util/map-utils';
10
10
  import { ItemFamilyChanges } from '../interfaces/item-family-changes';
11
- import { AssortmentPublishChange } from '@contrail/entity-types';
12
11
 
13
12
  let federatedId = '';
14
13
  jest.mock('../util/data-converter', () => {
@@ -513,7 +512,7 @@ describe('getSeasonFederation', () =>{
513
512
 
514
513
  describe('Test getSinceDate', () =>{
515
514
  it('getSinceDate from getSinceDateFromAPCs', async () =>{
516
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
515
+ const history = new Array(...plan1_history);
517
516
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
518
517
  const matchDate = new Date('2023-01-17T22:40:07.288Z');
519
518
 
@@ -530,7 +529,7 @@ describe('Test getSinceDate', () =>{
530
529
  expect(sinceDate).toEqual(matchDate);
531
530
  });
532
531
  it('getSinceDate date from config as year', async () =>{
533
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
532
+ const history = new Array(...plan1_history);
534
533
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
535
534
  const matchDate = new Date('2023-01-16T21:50:42.742Z');
536
535
 
@@ -549,7 +548,7 @@ describe('Test getSinceDate', () =>{
549
548
 
550
549
  it('getSinceDate date from config numberofdays-cross month', async () =>{
551
550
  const count = 10;
552
- const history = new Array(...plan1_across_month_DST) as any as AssortmentPublishChange[];
551
+ const history = new Array(...plan1_across_month_DST);
553
552
  const lastAPCId = '_mj--7nlyp7mmDrK';
554
553
  const matchDate = new Date('2023-02-25T19:13:58.902Z');
555
554
  const config = {sinceDate: 'numberofdays:'+ count } as any as FCConfig;
@@ -561,7 +560,7 @@ describe('Test getSinceDate', () =>{
561
560
  });
562
561
  it('getSinceDate date from config numberofdays-cross DST', async () =>{
563
562
  const count = 11;
564
- const history = new Array(...plan1_across_month_DST) as any as AssortmentPublishChange[];
563
+ const history = new Array(...plan1_across_month_DST);
565
564
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
566
565
  const matchDate = new Date('2023-03-06T21:50:42.742Z');
567
566
  const config = {sinceDate: 'numberofdays:'+ count } as any as FCConfig;
@@ -573,7 +572,7 @@ describe('Test getSinceDate', () =>{
573
572
  });
574
573
  it('getSinceDate date from config numberofpublishes', async () =>{
575
574
  const count = 3;
576
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
575
+ const history = new Array(...plan1_history);
577
576
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
578
577
  const matchDate = new Date('2023-01-17T22:35:20.517Z');
579
578
  const config = {sinceDate: 'numberofpublishes:'+ count } as any as FCConfig;
@@ -586,7 +585,7 @@ describe('Test getSinceDate', () =>{
586
585
 
587
586
  it('getSinceDate date from config numberofpublishes', async () =>{
588
587
  const count = 3;
589
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
588
+ const history = new Array(...plan1_history);
590
589
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
591
590
  const matchDate = new Date('2023-01-17T22:35:20.517Z');
592
591
  const config = {sinceDate: 'numberofpublishes:'+ count } as any as FCConfig;
@@ -603,7 +602,7 @@ describe('Test getSinceDate', () =>{
603
602
 
604
603
  describe('getSinceDateFromAPCSpecificDate', () =>{
605
604
  it('last apc - one day', () =>{
606
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
605
+ const history = new Array(...plan1_history);
607
606
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
608
607
  const matchDate = new Date('2023-01-16T21:50:42.742Z');
609
608
 
@@ -617,7 +616,7 @@ describe('getSinceDateFromAPCSpecificDate', () =>{
617
616
  });
618
617
 
619
618
  it('apc in the middle - one day', () =>{
620
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
619
+ const history = new Array(...plan1_history);
621
620
  const lastAPCId = 'GiT9CZXZGVljoYMR';
622
621
  const matchDate = new Date('2023-01-15T19:13:58.902Z');
623
622
 
@@ -630,7 +629,7 @@ describe('getSinceDateFromAPCSpecificDate', () =>{
630
629
  expect(sinceDate).toEqual(matchDate);
631
630
  });
632
631
  it('before initial publish', () => {
633
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
632
+ const history = new Array(...plan1_history);
634
633
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
635
634
  const matchDate = new Date('2023-01-15T19:13:58.902Z');
636
635
  const config = {} as FCConfig;
@@ -641,7 +640,7 @@ describe('getSinceDateFromAPCSpecificDate', () =>{
641
640
  expect(sinceDate).toEqual(matchDate);
642
641
  });
643
642
  it('numberofdays at 2 ', () => {
644
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
643
+ const history = new Array(...plan1_history);
645
644
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
646
645
  const matchDate = new Date('2023-01-15T19:13:58.902Z');
647
646
  const config = {} as FCConfig;
@@ -656,7 +655,7 @@ describe('getSinceDateFromAPCSpecificDate', () =>{
656
655
 
657
656
  describe('getSinceDateDaysPrevious', () =>{
658
657
  it('last apc - one day', () =>{
659
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
658
+ const history = new Array(...plan1_history);
660
659
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
661
660
  const matchDate = new Date('2023-01-16T21:50:42.742Z');
662
661
 
@@ -670,7 +669,7 @@ describe('getSinceDateDaysPrevious', () =>{
670
669
  });
671
670
 
672
671
  it('apc in the middle - one day', () =>{
673
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
672
+ const history = new Array(...plan1_history);
674
673
  const lastAPCId = 'GiT9CZXZGVljoYMR';
675
674
  const matchDate = new Date('2023-01-15T19:13:58.902Z');
676
675
 
@@ -683,7 +682,7 @@ describe('getSinceDateDaysPrevious', () =>{
683
682
  expect(sinceDate).toEqual(matchDate);
684
683
  });
685
684
  it('numberofdays greater than array size', () => {
686
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
685
+ const history = new Array(...plan1_history);
687
686
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
688
687
  const matchDate = new Date('2023-01-15T19:13:58.902Z');
689
688
  const config = {} as FCConfig;
@@ -694,7 +693,7 @@ describe('getSinceDateDaysPrevious', () =>{
694
693
  expect(sinceDate).toEqual(matchDate);
695
694
  });
696
695
  it('numberofdays at 2 ', () => {
697
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
696
+ const history = new Array(...plan1_history);
698
697
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
699
698
  const matchDate = new Date('2023-01-15T19:13:58.902Z');
700
699
  const config = {} as FCConfig;
@@ -707,9 +706,9 @@ describe('getSinceDateDaysPrevious', () =>{
707
706
 
708
707
  });
709
708
 
710
- describe('getSinceDateFromAPCs - plan history in ascending order', () => {
711
- it('oldest / only apc', () => {
712
- const history = new Array(...plan1_history).slice(0, 1) as any as AssortmentPublishChange[];
709
+ describe('getSinceDateFromAPCs', () => {
710
+ it('first / only apc', () => {
711
+ const history = new Array(...plan1_history).slice(0, 1);
713
712
  const lastAPCId = 'v9BKkHo-tpL0wUZN';
714
713
  const matchDate = new Date(0);
715
714
 
@@ -723,8 +722,8 @@ describe('getSinceDateFromAPCs - plan history in ascending order', () => {
723
722
  expect(sinceDate).toEqual(matchDate);
724
723
  });
725
724
 
726
- it('oldest / multiple apcs in history -ascending order', () => {
727
- const history = new Array(...plan1_history).slice(0, 3) as any as AssortmentPublishChange[];
725
+ it('first / multiple apcs in history', () => {
726
+ const history = new Array(...plan1_history).slice(0, 3);
728
727
  const lastAPCId = 'v9BKkHo-tpL0wUZN';
729
728
  const matchDate = new Date(0);
730
729
 
@@ -738,8 +737,8 @@ describe('getSinceDateFromAPCs - plan history in ascending order', () => {
738
737
  expect(sinceDate).toEqual(matchDate);
739
738
  });
740
739
 
741
- it('most recent apc -ascending order', () => {
742
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
740
+ it('last apc', () => {
741
+ const history = new Array(...plan1_history);
743
742
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
744
743
  const matchDate = new Date('2023-01-17T22:40:07.288Z');
745
744
 
@@ -753,8 +752,8 @@ describe('getSinceDateFromAPCs - plan history in ascending order', () => {
753
752
  expect(sinceDate).toEqual(matchDate);
754
753
  });
755
754
 
756
- it('apc in the middle -ascending order', () => {
757
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
755
+ it('apc in the middle', () => {
756
+ const history = new Array(...plan1_history);
758
757
  const lastAPCId = 'GiT9CZXZGVljoYMR';
759
758
  const matchDate = new Date('2023-01-16T21:50:42.742Z');
760
759
 
@@ -768,102 +767,10 @@ describe('getSinceDateFromAPCs - plan history in ascending order', () => {
768
767
  expect(sinceDate).toEqual(matchDate);
769
768
  });
770
769
 
771
- it('pastPublishCount greater than array size -ascending order; so include all changes', () => {
772
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
770
+ it('pastPublishCount greater than array size', () => {
771
+ const history = new Array(...plan1_history);
773
772
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
774
- const matchDate = new Date(0);
775
-
776
- const config = {} as FCConfig;
777
-
778
- const mapFileUtil = new MapFileUtil(new Entities());
779
- const dc = new DataConverter(config, mapFileUtil);
780
- const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
781
-
782
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId, 20);
783
- expect(sinceDate).toEqual(matchDate);
784
- });
785
-
786
- it('pastPublishCount at 3 -ascending order', () => {
787
- const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
788
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
789
- const matchDate = new Date('2023-01-17T22:35:20.517Z');
790
-
791
- const config = {} as FCConfig;
792
-
793
- const mapFileUtil = new MapFileUtil(new Entities());
794
- const dc = new DataConverter(config, mapFileUtil);
795
- const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
796
-
797
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId, 3);
798
- expect(sinceDate).toEqual(matchDate);
799
- });
800
- });
801
-
802
- describe('getSinceDateFromAPCs - plan history in descending order', () => {
803
- it('oldest / only apc', () => {
804
- const history = new Array(...plan1_history_descending).slice(0, 1) as any as AssortmentPublishChange[];
805
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
806
- const matchDate = new Date(0);
807
-
808
- const config = {} as FCConfig;
809
-
810
- const mapFileUtil = new MapFileUtil(new Entities());
811
- const dc = new DataConverter(config, mapFileUtil);
812
- const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
813
-
814
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
815
- expect(sinceDate).toEqual(matchDate);
816
- });
817
-
818
- it('oldest / multiple apcs in history -descending order', () => {
819
- const history = new Array(...plan1_history_descending).slice(0, 3) as any as AssortmentPublishChange[];
820
- const lastAPCId = '4JM83QNiIO0IBkck';
821
- const matchDate = new Date(0);
822
-
823
- const config = {} as FCConfig;
824
-
825
- const mapFileUtil = new MapFileUtil(new Entities());
826
- const dc = new DataConverter(config, mapFileUtil);
827
- const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
828
-
829
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
830
- expect(sinceDate).toEqual(matchDate);
831
- });
832
-
833
- it('most recent apc -descending order', () => {
834
- const history = new Array(...plan1_history_descending) as any as AssortmentPublishChange[];
835
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
836
- const matchDate = new Date('2023-01-17T22:40:07.288Z');
837
-
838
- const config = {} as FCConfig;
839
-
840
- const mapFileUtil = new MapFileUtil(new Entities());
841
- const dc = new DataConverter(config, mapFileUtil);
842
- const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
843
-
844
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
845
- expect(sinceDate).toEqual(matchDate);
846
- });
847
-
848
- it('apc in the middle -descending order', () => {
849
- const history = new Array(...plan1_history_descending) as any as AssortmentPublishChange[];
850
- const lastAPCId = 'GiT9CZXZGVljoYMR';
851
- const matchDate = new Date('2023-01-16T21:50:42.742Z');
852
-
853
- const config = {} as FCConfig;
854
-
855
- const mapFileUtil = new MapFileUtil(new Entities());
856
- const dc = new DataConverter(config, mapFileUtil);
857
- const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
858
-
859
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
860
- expect(sinceDate).toEqual(matchDate);
861
- });
862
-
863
- it('pastPublishCount greater than array size -descending order; so include all changes', () => {
864
- const history = new Array(...plan1_history_descending) as any as AssortmentPublishChange[];
865
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
866
- const matchDate = new Date(0);
773
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
867
774
 
868
775
  const config = {} as FCConfig;
869
776
 
@@ -875,8 +782,8 @@ describe('getSinceDateFromAPCs - plan history in descending order', () => {
875
782
  expect(sinceDate).toEqual(matchDate);
876
783
  });
877
784
 
878
- it('pastPublishCount at 3 -descending order', () => {
879
- const history = new Array(...plan1_history_descending) as any as AssortmentPublishChange[];
785
+ it('pastPublishCount at 3 ', () => {
786
+ const history = new Array(...plan1_history);
880
787
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
881
788
  const matchDate = new Date('2023-01-17T22:35:20.517Z');
882
789
 
@@ -1141,10 +1048,9 @@ describe('buildDeleteChanges', () =>{
1141
1048
  ];
1142
1049
  const apc ={};
1143
1050
  const fullAPC = {
1144
- id: 'apcId',
1145
1051
  deleteDataDownloadLink: 'deleteDataDownloadLink',
1146
1052
  returnedDeleteData
1147
- } as AssortmentPublishChange;
1053
+ };
1148
1054
  const previousApc = {};
1149
1055
  const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
1150
1056
  const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
@@ -1171,7 +1077,6 @@ describe('buildDeleteChanges', () =>{
1171
1077
  ];
1172
1078
  const apc ={};
1173
1079
  const fullAPC = {
1174
- id: 'apcId',
1175
1080
  returnedDeleteData
1176
1081
  };
1177
1082
  const previousApc = undefined;
@@ -1205,14 +1110,13 @@ describe('buildDeleteChanges', () =>{
1205
1110
  deletes: [{id:'1'}, {id:'3'}]
1206
1111
  }
1207
1112
 
1208
- } as AssortmentPublishChange;
1209
- const previousApc: AssortmentPublishChange = {
1210
- id: 'previousApcId',
1211
1113
  };
1212
- const fullPreviousApc: AssortmentPublishChange = {
1114
+ const previousApc = {
1115
+ };
1116
+ const fullPreviousApc = {
1213
1117
  id: previousApcId,
1214
1118
  assortmentBaselineDownloadLink: 'assortmentBaselineDownloadLink'
1215
- } ;
1119
+ };
1216
1120
  const previousApcBaseline = {
1217
1121
  assortmentItems: [
1218
1122
  { itemId: '1' },
@@ -1266,7 +1170,7 @@ describe('buildDeleteChanges', () =>{
1266
1170
  deletes: [{id:'1'}, {id:'3'}]
1267
1171
  }
1268
1172
 
1269
- } as AssortmentPublishChange;
1173
+ };
1270
1174
  const previousApc = {
1271
1175
  assortmentBaselineDownloadLink: 'assortmentBaselineDownloadLink'
1272
1176
  };
@@ -1,4 +1,4 @@
1
- import { API_VERSION, Entities, Files, Request } from '@contrail/sdk';
1
+ import { Entities, Files, Request } from '@contrail/sdk';
2
2
  import { AsyncEventsPayloadType, FCConfig, ProductFederation, SeasonalPayload, SeasonFederation, SkuFederation } from '../interfaces/interfaces';
3
3
  import { DataConverter } from '../util/data-converter';
4
4
  import { FlexPLMConnect } from '../util/flexplm-connect';
@@ -12,7 +12,6 @@ import path = require('path');
12
12
  import { MapFileUtil } from '@contrail/transform-data';
13
13
  import { Logger } from '@contrail/app-framework';
14
14
  import { EventShortMessageStatus } from '../util/event-short-message-status';
15
- import { AssortmentPublishChange } from '@contrail/entity-types';
16
15
 
17
16
  export class BaseProcessPublishAssortment {
18
17
 
@@ -41,7 +40,7 @@ export class BaseProcessPublishAssortment {
41
40
  public async process(event) {
42
41
 
43
42
  const assortmentPublishChangeId = event.assortmentPublishChangeId;
44
- let apcHistory: AssortmentPublishChange[];
43
+ let apcHistory;
45
44
  let publisher;
46
45
  const assortmentId = event.assortmentId;
47
46
  try {
@@ -211,7 +210,7 @@ export class BaseProcessPublishAssortment {
211
210
  return this.assortment;
212
211
  }
213
212
 
214
- public async getSinceDate(assortmentId: any, assortmentPublishChangeId: any, apcHistory: AssortmentPublishChange[]): Promise<Date> {
213
+ public async getSinceDate(assortmentId: any, assortmentPublishChangeId: any, apcHistory: object[]): Promise<Date> {
215
214
 
216
215
  let sinceDate = null;
217
216
 
@@ -250,34 +249,15 @@ export class BaseProcessPublishAssortment {
250
249
  return sinceDate;
251
250
  }
252
251
 
253
- async getApcHistory(assortmentId: string): Promise<AssortmentPublishChange[]> {
254
- const apcs = [];
255
- const MAX_PAGES = 1_000;
256
- let nextPageKey = null;
257
- const options = {
258
- entityName: 'assortment',
259
- id: assortmentId,
260
- apiVersion: API_VERSION.V2,
261
- nextPageKey,
262
- relation: 'history',
263
- };
264
-
265
- let i = 0;
266
- do {
267
- const response = await new Entities().get(options);
268
- if(response?.results){
269
- apcs.push(...response.results);
252
+ async getApcHistory(assortmentId: any) {
253
+ const resource = `/assortments/${assortmentId}/history/`;
254
+ return Request.request(resource, {
255
+ method: 'GET',
256
+ headers: {
257
+ Accept: 'application/json',
258
+ 'Content-Type': 'application/json'
270
259
  }
271
- nextPageKey = response?.nextPageKey;
272
- options.nextPageKey = nextPageKey;
273
- i++;
274
- } while(nextPageKey && i < MAX_PAGES);
275
-
276
- if(i === MAX_PAGES && nextPageKey){
277
- throw new Error('Max pages reached getting APC history for assortmentId: ' + assortmentId);
278
- }
279
-
280
- return apcs;
260
+ });
281
261
  }
282
262
 
283
263
  protected updatedSinceDate(entity, sinceDate: Date): boolean {
@@ -285,7 +265,7 @@ export class BaseProcessPublishAssortment {
285
265
  return (updatedOn && new Date(updatedOn) > sinceDate);
286
266
  }
287
267
 
288
- getSinceDateFromAPCSpecificDate(apcHistory: AssortmentPublishChange[], assortmentPublishChangeId: string, specificDate: Date):Date {
268
+ getSinceDateFromAPCSpecificDate(apcHistory: any[], assortmentPublishChangeId: string, specificDate: Date):Date {
289
269
  const apc = apcHistory.find(apc => apc?.id === assortmentPublishChangeId);
290
270
  const apcDate = new Date(apc?.createdOn);
291
271
  let afterDate = apcDate;
@@ -306,7 +286,7 @@ export class BaseProcessPublishAssortment {
306
286
  const selectedDate = (beforeDate.getTime() !== 0)?beforeDate : afterDate;
307
287
  return selectedDate;
308
288
  }
309
- getSinceDateDaysPrevious(apcHistory: AssortmentPublishChange[], assortmentPublishChangeId: string, daysBack):Date {
289
+ getSinceDateDaysPrevious(apcHistory: any[], assortmentPublishChangeId: string, daysBack):Date {
310
290
  const apc = apcHistory.find(apc => apc?.id === assortmentPublishChangeId);
311
291
  const apcDate = new Date(apc?.createdOn);
312
292
  let afterDate = apcDate;
@@ -335,14 +315,18 @@ export class BaseProcessPublishAssortment {
335
315
  return selectedDate;
336
316
  }
337
317
 
338
- getSinceDateFromAPCs(apcHistory: AssortmentPublishChange[], assortmentPublishChangeId: string, pastPublishCount = 1): Date {
318
+ getSinceDateFromAPCs(apcHistory: any[], assortmentPublishChangeId: string, pastPublishCount = 1): Date {
339
319
  if(apcHistory.length === 1){
340
320
  return new Date(0);
341
321
  }
342
-
343
- const apc = apcHistory.find(apc => apc.id === assortmentPublishChangeId);
322
+ const apcIndex = apcHistory.findIndex(apc => apc.id === assortmentPublishChangeId);
323
+ if(apcIndex === 0){
324
+ return new Date(0);
325
+ }
326
+ const apc = apcHistory[apcIndex];
344
327
  const apcDate = new Date(apc?.createdOn);
345
- const dateArray: Date[] = [];
328
+ let sinceDate = new Date(0);
329
+ const dateArray = [];
346
330
  for (const tempapc of apcHistory) {
347
331
  if (assortmentPublishChangeId !== tempapc?.id) {
348
332
  const tempDate = new Date(tempapc?.createdOn);
@@ -351,15 +335,12 @@ export class BaseProcessPublishAssortment {
351
335
  }
352
336
  }
353
337
  }
354
- if(dateArray.length === 0 || pastPublishCount > dateArray.length){
355
- return new Date(0);
356
- }
357
- dateArray.sort((a,b) => { return a.getTime() - b.getTime();});
358
- const arrIndex = dateArray.length - pastPublishCount;
359
- return dateArray[arrIndex];
338
+ dateArray.sort((a,b) => { return Date.parse(a) - Date.parse(b);});
339
+ const arrIndex = (dateArray.length - pastPublishCount > 0)? dateArray.length - pastPublishCount: 0;
340
+ sinceDate = dateArray[arrIndex];
341
+ return sinceDate;
360
342
  }
361
-
362
- protected getPublisher(assortmentPublishChange: AssortmentPublishChange) {
343
+ protected getPublisher(assortmentPublishChange) {
363
344
  const createdBy = assortmentPublishChange?.createdBy;
364
345
  const publisher = {};
365
346
  const includeKeys = ['email', 'firstName', 'isSsoUser', 'lastName'];
@@ -373,7 +354,7 @@ export class BaseProcessPublishAssortment {
373
354
 
374
355
  }
375
356
 
376
- async downloadAssortmentPublishChange(assortmentId: string, assortmentPublishChangeId: string): Promise<AssortmentPublishChange> {
357
+ async downloadAssortmentPublishChange(assortmentId: string, assortmentPublishChangeId: string) {
377
358
  const resourceString = '/assortments/' + assortmentId + '/history/' + assortmentPublishChangeId + '?relations=createdBy';
378
359
  return await Request.request(
379
360
  resourceString,
@@ -387,7 +368,7 @@ export class BaseProcessPublishAssortment {
387
368
  );
388
369
  }
389
370
 
390
- async downloadHydratedChangeDetail(assortmentPublishChange: AssortmentPublishChange) {
371
+ async downloadHydratedChangeDetail(assortmentPublishChange) {
391
372
  try {
392
373
  console.info('downloadHydratedChangeDetail-start');
393
374
  const link = assortmentPublishChange?.hydratedDetailDownloadLink;
@@ -401,7 +382,7 @@ export class BaseProcessPublishAssortment {
401
382
  return undefined;
402
383
  }
403
384
 
404
- async downloadAssortmentBaseline(assortmentPublishChange: AssortmentPublishChange) {
385
+ async downloadAssortmentBaseline(assortmentPublishChange) {
405
386
  console.info('downloadAssortmentBaseline-start');
406
387
  try {
407
388
  const link = assortmentPublishChange?.assortmentBaselineDownloadLink;