@@ -36,7 +36,21 @@ const putTestData = async (req: Request) => {
3636 const contentTypes = req . body . contentTypes ;
3737
3838 try {
39- await FieldMapperModel . read ( ) ;
39+
40+ /*
41+ this code snippet is iterating over an array called contentTypes and
42+ transforming each element by adding a unique identifier (id) if it doesn't already exist.
43+ The transformed elements are then stored in the contentType variable,
44+ and the generated id values are pushed into the contentIds array.
45+ */
46+ await ContentTypesMapperModelLowdb . read ( ) ;
47+ const contentIds : any [ ] = [ ] ;
48+ const contentType = contentTypes . map ( ( item : any ) => {
49+ const id = item ?. id ?. replace ( / [ { } ] / g, "" ) ?. toLowerCase ( ) || uuidv4 ( ) ;
50+ item . id = id ;
51+ contentIds . push ( id ) ;
52+ return { ...item , id, projectId } ;
53+ } ) ;
4054
4155 /*
4256 this code snippet iterates over an array of contentTypes and performs
@@ -47,36 +61,24 @@ const putTestData = async (req: Request) => {
4761 It then updates the field_mapper property of a data object using the FieldMapperModel.update() function.
4862 Finally, it updates the fieldMapping property of each type in the contentTypes array with the fieldIds array.
4963 */
64+ await FieldMapperModel . read ( ) ;
65+
5066 contentTypes . map ( ( type : any , index : any ) => {
5167 const fieldIds : string [ ] = [ ] ;
5268 const fields = type ?. fieldMapping ?. filter ( ( field : any ) => field ) ?. map ?.( ( field : any ) => {
5369 const id = field ?. id ? field ?. id ?. replace ( / [ { } ] / g, "" ) ?. toLowerCase ( ) : uuidv4 ( ) ;
5470 field . id = id ;
5571 fieldIds . push ( id ) ;
56- return { id, projectId, isDeleted : false , ...field } ;
72+ return { id, projectId, contentTypeId : type ?. id , isDeleted : false , ...field } ;
5773 } ) ;
5874
5975 FieldMapperModel . update ( ( data : any ) => {
6076 data . field_mapper = [ ...( data ?. field_mapper ?? [ ] ) , ...( fields ?? [ ] ) ] ;
6177 } ) ;
62- contentTypes [ index ] . fieldMapping = fieldIds ;
78+ contentType [ index ] . fieldMapping = fieldIds ;
6379 } ) ;
6480
65- await ContentTypesMapperModelLowdb . read ( ) ;
66- const contentIds : any [ ] = [ ] ;
6781
68- /*
69- this code snippet is iterating over an array called contentTypes and
70- transforming each element by adding a unique identifier (id) if it doesn't already exist.
71- The transformed elements are then stored in the contentType variable,
72- and the generated id values are pushed into the contentIds array.
73- */
74- const contentType = contentTypes . map ( ( item : any ) => {
75- const id = item ?. id ?. replace ( / [ { } ] / g, "" ) ?. toLowerCase ( ) || uuidv4 ( ) ;
76- item . id = id ;
77- contentIds . push ( id ) ;
78- return { ...item , id, projectId } ;
79- } ) ;
8082
8183 await ContentTypesMapperModelLowdb . update ( ( data : any ) => {
8284 data . ContentTypesMappers = [
@@ -248,7 +250,7 @@ const getFieldMapping = async (req: Request) => {
248250 const fieldData = contentType ?. fieldMapping ?. map ?.( ( fields : any ) => {
249251 const fieldMapper = FieldMapperModel . chain
250252 . get ( "field_mapper" )
251- . find ( { id : fields , projectId : projectId } )
253+ . find ( { id : fields , projectId : projectId , contentTypeId : contentTypeId } )
252254 . value ( ) ;
253255
254256 return fieldMapper ;
@@ -616,7 +618,7 @@ const updateContentType = async (req: Request) => {
616618 await FieldMapperModel . read ( ) ;
617619 fieldMapping . forEach ( ( field : any ) => {
618620 const fieldIndex = FieldMapperModel . data . field_mapper . findIndex (
619- ( f : any ) => f ?. id === field ?. id
621+ ( f : any ) => f ?. id === field ?. id && f ?. contentTypeId === field ?. contentTypeId
620622 ) ;
621623 if ( fieldIndex > - 1 && field ?. contentstackFieldType !== "" ) {
622624 FieldMapperModel . update ( ( data : any ) => {
0 commit comments