@@ -118,13 +118,10 @@ const putTestData = async (req: Request) => {
118118
119119 const FieldMapperModel = getFieldMapperDb ( projectId , iteration ) ;
120120 await FieldMapperModel . read ( ) ;
121- for ( let index = 0 ; index < contentTypes . length ; index ++ ) {
122- const type : any = contentTypes [ index ] ;
123121 for ( let index = 0 ; index < contentTypes . length ; index ++ ) {
124122 const type : any = contentTypes [ index ] ;
125123 const fieldIds : string [ ] = [ ] ;
126124 const existingFieldsInDb : any [ ] = FieldMapperModel . data ?. field_mapper ?? [ ] ;
127- const existingFieldsInDb : any [ ] = FieldMapperModel . data ?. field_mapper ?? [ ] ;
128125
129126 const fields = Array . isArray ( type ?. fieldMapping ) ?
130127 type . fieldMapping
@@ -137,16 +134,6 @@ const putTestData = async (req: Request) => {
137134 ef . contentTypeId === type ?. id
138135 ) ;
139136
140- const id = existingField ?. id
141- ? existingField . id
142- : ( safeField ?. id
143- ? safeField . id . replace ( / [ { } ] / g, '' ) . toLowerCase ( )
144- : uuidv4 ( ) ) ;
145- const existingField = existingFieldsInDb . find ( ( ef : any ) =>
146- ef . contentstackFieldUid === safeField . contentstackFieldUid &&
147- ef . contentTypeId === type ?. id
148- ) ;
149-
150137 const id = existingField ?. id
151138 ? existingField . id
152139 : ( safeField ?. id
@@ -166,14 +153,6 @@ const putTestData = async (req: Request) => {
166153 } )
167154 : [ ] ;
168155
169- await FieldMapperModel . update ( ( data : any ) => {
170- const existingFields = data ?. field_mapper ?? [ ] ;
171- const newFields = fields . filter ( ( newField : any ) => {
172- return ! existingFields . some ( ( existingField : any ) =>
173- existingField . id === newField . id &&
174- existingField . contentTypeId === newField . contentTypeId
175- ) ;
176- } ) ;
177156 await FieldMapperModel . update ( ( data : any ) => {
178157 const existingFields = data ?. field_mapper ?? [ ] ;
179158 const newFields = fields . filter ( ( newField : any ) => {
@@ -197,13 +176,9 @@ const putTestData = async (req: Request) => {
197176 }
198177 }
199178
200- }
201-
202179 const EntryMapperModel = getEntryMapperDb ( projectId , iteration ) ;
203180 await EntryMapperModel . read ( ) ;
204181
205- const uidMapperIteration = iteration > 1 ? iteration - 1 : iteration ;
206- const uidMapperModel = getUidMapperDb ( projectId , uidMapperIteration ) ; // previous iteration mapping
207182 const uidMapperIteration = iteration > 1 ? iteration - 1 : iteration ;
208183 const uidMapperModel = getUidMapperDb ( projectId , uidMapperIteration ) ; // previous iteration mapping
209184 await uidMapperModel . read ( ) ;
@@ -240,41 +215,6 @@ const putTestData = async (req: Request) => {
240215 }
241216 } ) ;
242217
243- for ( let index = 0 ; index < contentTypes . length ; index ++ ) {
244- const type : any = contentTypes [ index ] ;
245-
246- const mergeEntry = ( base : any , incoming : any ) => {
247- const keep = { ...( base ?? { } ) } ;
248- const add = { ...( incoming ?? { } ) } ;
249-
250- if ( ! keep ?. contentstackEntryUid && add ?. contentstackEntryUid ) {
251- keep . contentstackEntryUid = add . contentstackEntryUid ;
252- }
253-
254- if ( ! keep ?. id && add ?. id ) {
255- keep . id = add . id ;
256- }
257-
258- Object . keys ( add ) . forEach ( ( k ) => {
259- if ( add [ k ] !== undefined ) {
260- keep [ k ] = add [ k ] ;
261- }
262- } ) ;
263-
264- return keep ;
265- } ;
266-
267- const entryKey = ( e : any ) =>
268- `${ e ?. contentTypeId ?? e ?. contentTypeUid ?? '' } :${ e ?. otherCmsEntryUid ?? '' } ` ;
269-
270- const existingEntryByKey = new Map < string , any > ( ) ;
271- ( EntryMapperModel . data ?. entry_mapper ?? [ ] ) . forEach ( ( e : any ) => {
272- if ( e ?. otherCmsEntryUid && ( e ?. contentTypeId || e ?. contentTypeUid ) ) {
273- const key = entryKey ( e ) ;
274- existingEntryByKey . set ( key , mergeEntry ( existingEntryByKey . get ( key ) , e ) ) ;
275- }
276- } ) ;
277-
278218 for ( let index = 0 ; index < contentTypes . length ; index ++ ) {
279219 const type : any = contentTypes [ index ] ;
280220 const entryIds : string [ ] = [ ] ;
@@ -283,8 +223,6 @@ const putTestData = async (req: Request) => {
283223 type . entryMapping
284224 . filter ( Boolean )
285225 . map ( ( entry : any ) => {
286- const existing = existingEntryByKey . get ( `${ type ?. id } :${ entry ?. otherCmsEntryUid } ` ) ;
287- const existingId = existing ?. id ;
288226 const existing = existingEntryByKey . get ( `${ type ?. id } :${ entry ?. otherCmsEntryUid } ` ) ;
289227 const existingId = existing ?. id ;
290228 const id =
@@ -295,37 +233,13 @@ const putTestData = async (req: Request) => {
295233 entry . id . replace ( / [ { } ] / g, '' ) . toLowerCase ( )
296234 : uuidv4 ( )
297235 ) ;
298- existingId ?
299- String ( existingId ) . replace ( / [ { } ] / g, '' ) . toLowerCase ( )
300- : (
301- entry ?. id ?
302- entry . id . replace ( / [ { } ] / g, '' ) . toLowerCase ( )
303- : uuidv4 ( )
304- ) ;
305236 entry . id = id ;
306237 entryIds . push ( id ) ;
307238
308239 const otherCmsUidRaw = ( entry ?. otherCmsEntryUid ?? id ) as string ;
309240 const otherCmsUid = otherCmsUidRaw ? otherCmsUidRaw . replace ( / [ { } ] / g, '' ) : '' ;
310241 const otherCmsUidLower = otherCmsUid ? otherCmsUid . toLowerCase ( ) : '' ;
311242
312- const entryUidMap =
313- ( uidMapperModel . data as any ) ?. entryUid ||
314- ( uidMapperModel . data as any ) ?. entry ||
315- { } ;
316-
317- const uidMapperValue = otherCmsUid
318- ? (
319- entryUidMap ?. [ otherCmsUid ] ||
320- entryUidMap ?. [ otherCmsUidRaw ] ||
321- entryUidMap ?. [ otherCmsUidLower ] ||
322- entryUidMap ?. [ idCorrector ( { id : otherCmsUid } ) ] ||
323- ( otherCmsUidLower ? entryUidMap ?. [ idCorrector ( { id : otherCmsUidLower } ) ] : undefined )
324- )
325- const otherCmsUidRaw = ( entry ?. otherCmsEntryUid ?? id ) as string ;
326- const otherCmsUid = otherCmsUidRaw ? otherCmsUidRaw . replace ( / [ { } ] / g, '' ) : '' ;
327- const otherCmsUidLower = otherCmsUid ? otherCmsUid . toLowerCase ( ) : '' ;
328-
329243 const entryUidMap =
330244 ( uidMapperModel . data as any ) ?. entryUid ||
331245 ( uidMapperModel . data as any ) ?. entry ||
@@ -343,19 +257,15 @@ const putTestData = async (req: Request) => {
343257
344258 const contentstackUid = uidMapperValue || existing ?. contentstackEntryUid ;
345259
346- const contentstackUid = uidMapperValue || existing ?. contentstackEntryUid ;
347-
348260 return {
349261 ...entry ,
350262 id,
351263 otherCmsEntryUid : entry ?. otherCmsEntryUid ,
352264 projectId,
353265 contentTypeUid : entry ?. contentTypeUid ?? type ?. otherCmsUid ?? type ?. contentTypeUid ,
354- contentTypeUid : entry ?. contentTypeUid ?? type ?. otherCmsUid ?? type ?. contentTypeUid ,
355266 contentTypeId : type ?. id ,
356267 isDeleted : false ,
357268 contentstackEntryUid : contentstackUid ,
358- contentstackEntryUid : contentstackUid ,
359269 } ;
360270 } )
361271 : [ ] ;
@@ -376,23 +286,6 @@ const putTestData = async (req: Request) => {
376286 byKey . set ( key , mergeEntry ( byKey . get ( key ) , e ) ) ;
377287 } ) ;
378288
379- data . entry_mapper = Array . from ( byKey . values ( ) ) ;
380- await EntryMapperModel . update ( ( data : any ) => {
381- const currentEntries : any [ ] = Array . isArray ( data ?. entry_mapper ) ? data . entry_mapper : [ ] ;
382- const byKey = new Map < string , any > ( ) ;
383-
384- currentEntries . forEach ( ( e : any ) => {
385- if ( e ?. otherCmsEntryUid && ( e ?. contentTypeUid || e ?. contentTypeId ) ) {
386- const key = entryKey ( e ) ;
387- byKey . set ( key , mergeEntry ( byKey . get ( key ) , e ) ) ;
388- }
389- } ) ;
390-
391- entries . forEach ( ( e : any ) => {
392- const key = entryKey ( e ) ;
393- byKey . set ( key , mergeEntry ( byKey . get ( key ) , e ) ) ;
394- } ) ;
395-
396289 data . entry_mapper = Array . from ( byKey . values ( ) ) ;
397290 } ) ;
398291
@@ -405,7 +298,6 @@ const putTestData = async (req: Request) => {
405298 contentType [ index ] . entryMapping = entryIds ;
406299 }
407300 }
408- }
409301
410302 await ContentTypesMapperModelLowdb . update ( ( data : any ) => {
411303 const existingContentTypes : any [ ] = data ?. ContentTypesMappers ?? [ ] ;
@@ -431,30 +323,6 @@ const putTestData = async (req: Request) => {
431323 }
432324 } ) ;
433325
434- data . ContentTypesMappers = existingContentTypes ;
435- const existingContentTypes : any [ ] = data ?. ContentTypesMappers ?? [ ] ;
436- const existingById = new Map < string , number > ( ) ;
437- existingContentTypes . forEach ( ( ct : any , idx : number ) => {
438- if ( ct ?. id && ct ?. projectId ) {
439- existingById . set ( `${ ct . id } :${ ct . projectId } ` , idx ) ;
440- }
441- } ) ;
442-
443- contentType . forEach ( ( ct : any ) => {
444- const key = `${ ct . id } :${ ct . projectId } ` ;
445- const existingIdx = existingById . get ( key ) ;
446- if ( existingIdx !== undefined ) {
447- existingContentTypes [ existingIdx ] = {
448- ...existingContentTypes [ existingIdx ] ,
449- ...ct ,
450- fieldMapping : ct . fieldMapping ,
451- entryMapping : ct . entryMapping ,
452- } ;
453- } else {
454- existingContentTypes . push ( ct ) ;
455- }
456- } ) ;
457-
458326 data . ContentTypesMappers = existingContentTypes ;
459327 } ) ;
460328
@@ -899,7 +767,6 @@ const getExistingGlobalFields = async (req: Request) => {
899767 let selectedGlobalField = null ;
900768
901769 if ( globalFieldUID ) {
902- const [ err , res ] = await safePromise (
903770 const [ err , res ] = await safePromise (
904771 https ( {
905772 method : 'GET' ,
@@ -1806,22 +1673,18 @@ const updateEntryStatus = async (req: Request) => {
18061673 const { projectId } = req . params ;
18071674 const { ids } = req . body ;
18081675 const validatedUids : string [ ] = Array . isArray ( ids ) ? ids : [ ] ;
1809- const { ids } = req . body ;
1810- const validatedUids : string [ ] = Array . isArray ( ids ) ? ids : [ ] ;
18111676 const srcFunc = "updateEntryMapping" ;
18121677 if ( isEmpty ( validatedUids ) ) {
18131678 logger . error (
18141679 getLogMessage (
18151680 srcFunc ,
18161681 "Invalid ids"
1817- "Invalid ids"
18181682 )
18191683 ) ;
18201684 return {
18211685 status : HTTP_CODES ?. BAD_REQUEST ,
18221686 data : {
18231687 message : "Invalid ids" ,
1824- message : "Invalid ids" ,
18251688 } ,
18261689 } ;
18271690 }
@@ -1837,7 +1700,6 @@ const updateEntryStatus = async (req: Request) => {
18371700 const foundEntry : EntryMapper [ ] = [ ] ;
18381701 await EntryMapperModel . update ( ( data : any ) => {
18391702 data ?. entry_mapper ?. forEach ( ( entry : any ) => {
1840- if ( validatedUids . includes ( entry ?. id ) ) {
18411703 if ( validatedUids . includes ( entry ?. id ) ) {
18421704 entry . isUpdate = ! entry . isUpdate ;
18431705 foundEntry . push ( entry ) ;
@@ -2177,7 +2039,4 @@ export const contentMapperService = {
21772039 getEntryMapping,
21782040 updateEntryStatus,
21792041 getExistingTaxonomies
2180- getEntryMapping ,
2181- updateEntryStatus,
2182- getExistingTaxonomies
21832042} ;
0 commit comments