tango-app-api-store-builder 1.0.0-beta-133 → 1.0.0-beta-135

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-store-builder",
3
- "version": "1.0.0-beta-133",
3
+ "version": "1.0.0-beta-135",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -32,7 +32,7 @@
32
32
  "path": "^0.12.7",
33
33
  "selenium-webdriver": "^4.31.0",
34
34
  "sharp": "^0.34.1",
35
- "tango-api-schema": "^2.2.169",
35
+ "tango-api-schema": "^2.2.173",
36
36
  "tango-app-api-middleware": "3.1.48",
37
37
  "url": "^0.11.4",
38
38
  "winston": "^3.17.0",
@@ -164,7 +164,7 @@ export async function deleteTemplate( req, res ) {
164
164
 
165
165
  export async function duplicateTemplate( req, res ) {
166
166
  try {
167
- let templateDetails = await fixtureConfigService.findOne( { _id: req.body.templateId } );
167
+ let templateDetails = await fixtureConfigService.findOne( { _id: req.body.templateId }, { createdAt: 0, updatedAt: 0 } );
168
168
  if ( !templateDetails ) {
169
169
  return res.sendError( 'No data found', 204 );
170
170
  }
@@ -282,12 +282,14 @@ export async function getTemplateList( req, res ) {
282
282
  $group: {
283
283
  _id: null,
284
284
  planoId: { $addToSet: '$planoId' },
285
+ storeList: { $addToSet: '$storeName' },
285
286
  },
286
287
  },
287
288
  {
288
289
  $project: {
289
290
  _id: 0,
290
291
  planoId: 1,
292
+ storeList: 1,
291
293
  },
292
294
  },
293
295
  ],
@@ -301,6 +303,42 @@ export async function getTemplateList( req, res ) {
301
303
  fixtureWidth: 1,
302
304
  productBrandName: 1,
303
305
  productCategory: 1,
306
+ shelfProduct: {
307
+ $reduce: {
308
+ input: '$shelfConfig',
309
+ initialValue: [],
310
+ in: {
311
+ $concatArrays: [
312
+ '$$value',
313
+ { $ifNull: [ '$$this.productBrandName', [] ] },
314
+ ],
315
+ },
316
+ },
317
+ },
318
+ shelfProductCategory: {
319
+ $reduce: {
320
+ input: '$shelfConfig',
321
+ initialValue: [],
322
+ in: {
323
+ $concatArrays: [
324
+ '$$value',
325
+ { $ifNull: [ '$$this.productCategory', [] ] },
326
+ ],
327
+ },
328
+ },
329
+ },
330
+ shelfProductSubCategory: {
331
+ $reduce: {
332
+ input: '$shelfConfig',
333
+ initialValue: [],
334
+ in: {
335
+ $concatArrays: [
336
+ '$$value',
337
+ { $ifNull: [ '$$this.productSubCategory', [] ] },
338
+ ],
339
+ },
340
+ },
341
+ },
304
342
  clientId: 1,
305
343
  productSubCategory: 1,
306
344
  status: 1,
@@ -316,6 +354,7 @@ export async function getTemplateList( req, res ) {
316
354
  },
317
355
  },
318
356
  planoId: { $ifNull: [ { $arrayElemAt: [ '$storeFixtureDetails.planoId', 0 ] }, [] ] },
357
+ storeList: { $ifNull: [ { $arrayElemAt: [ '$storeFixtureDetails.storeList', 0 ] }, [] ] },
319
358
  },
320
359
  },
321
360
  {
@@ -345,16 +384,18 @@ export async function getTemplateList( req, res ) {
345
384
  fixtureCategory: 1,
346
385
  fixtureName: 1,
347
386
  fixtureWidth: 1,
348
- productBrandName: 1,
349
- productCategory: 1,
387
+ productBrandName: { $concatArrays: [ '$productBrandName', '$shelfProduct' ] },
388
+ productCategory: { $concatArrays: [ '$productCategory', '$shelfProductCategory' ] },
350
389
  clientId: 1,
351
390
  fixtureType: 1,
352
- productSubCategory: 1,
391
+ productSubCategory: { $concatArrays: [ '$productSubCategory', '$shelfProductSubCategory' ] },
353
392
  status: 1,
354
393
  templateId: 1,
355
394
  planoId: 1,
356
395
  vmCapacity: 1,
357
396
  productCapacity: 1,
397
+ storeList: 1,
398
+ storeCount: { $size: '$storeList' },
358
399
  planoStatus: { $ifNull: [ { $arrayElemAt: [ '$planoStatus.statusList', 0 ] }, [] ] },
359
400
  status: {
360
401
  $cond: {
@@ -79,6 +79,7 @@ export async function getplanoFeedback( req, res ) {
79
79
  $expr: {
80
80
  $and: [
81
81
  { $eq: [ '$_id', '$$taskId' ] },
82
+ { $eq: [ '$checklistStatus', 'submit' ] },
82
83
  ],
83
84
  },
84
85
  },
@@ -95,7 +96,7 @@ export async function getplanoFeedback( req, res ) {
95
96
  as: 'taskData',
96
97
  },
97
98
 
98
- }, { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: true } },
99
+ }, { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: false } },
99
100
  {
100
101
  $lookup: {
101
102
  from: 'storefixtures',
@@ -162,6 +163,7 @@ export async function getplanoFeedback( req, res ) {
162
163
  $expr: {
163
164
  $and: [
164
165
  { $eq: [ '$_id', '$$taskId' ] },
166
+ { $eq: [ '$checklistStatus', 'submit' ] },
165
167
  ],
166
168
  },
167
169
  },
@@ -178,7 +180,7 @@ export async function getplanoFeedback( req, res ) {
178
180
  as: 'taskData',
179
181
  },
180
182
 
181
- }, { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: true } },
183
+ }, { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: false } },
182
184
  {
183
185
  $lookup: {
184
186
  from: 'storefixtures',
@@ -671,6 +673,18 @@ export async function updateFixtureStatus( req, res ) {
671
673
  'status': 'complete',
672
674
  },
673
675
  );
676
+ if ( req.body.taskType==='layout' ) {
677
+ await planoTaskService.updateMany(
678
+ {
679
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
680
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
681
+ type: 'layout',
682
+ },
683
+ {
684
+ 'status': 'complete',
685
+ },
686
+ );
687
+ }
674
688
  }
675
689
  }
676
690
 
@@ -830,6 +844,7 @@ export async function updateGlobalComment( req, res ) {
830
844
  userId: req.user._id,
831
845
  userName: req.user.userName,
832
846
  comment: req.body.comment,
847
+ responsetype: req.body.responsetype,
833
848
  planoId: new mongoose.Types.ObjectId( req.body.planoId ),
834
849
  floorId: new mongoose.Types.ObjectId( req.body.floorId ),
835
850
  taskType: req.body.taskType,
@@ -53,8 +53,10 @@ export async function fixtureBulkUpload( req, res ) {
53
53
  },
54
54
  ],
55
55
  ...( typeof ele?.isEdit == undefined ) ? { 'status': ele?.fixLibCode ? inputData.updateFixtureStatus : inputData.newFixtureStatus } :{},
56
+ fixtureCapacity: ele.shelfType =='shelf' ? ele.productPerShelf : ele.trayRows * ele.productPerShelf,
56
57
  };
57
58
  } else {
59
+ acc[ele.fixtureName].fixtureCapacity = acc[ele.fixtureName].fixtureCapacity + ( ele.shelfType =='shelf' ? ele.productPerShelf : ele.trayRows * ele.productPerShelf );
58
60
  acc[ele.fixtureName].shelfConfig.push(
59
61
  {
60
62
  shelfNumber: ele.shelfNumber,
@@ -67,21 +69,22 @@ export async function fixtureBulkUpload( req, res ) {
67
69
  }
68
70
  return acc;
69
71
  }, {} );
70
- let fixtureData = [];
71
- await Promise.all( Object.keys( groupedData ).map( async ( ele ) => {
72
- if ( groupedData[ele]?.fixtureLibCode && !groupedData[ele]?.status ) {
73
- await planoLibraryService.updateOne( { fixtureLibCode: groupedData[ele]?.fixtureLibCode }, groupedData[ele] );
74
- } else {
75
- let FixLibCode = await getMaxFixtureLibCode();
76
- groupedData[ele].fixtureLibCode = FixLibCode;
77
- fixtureData.push( groupedData[ele] );
78
- }
79
- } ) );
80
- let deleteList = inputData.deleteFixtureList.map( ( ele ) => new ObjectId( ele ) );
81
- if ( deleteList.length ) {
82
- await planoLibraryService.deleteMany( { _id: { $in: deleteList } } );
72
+ // let fixtureData = [];
73
+ for ( let ele of Object.keys( groupedData ) ) {
74
+ // if ( groupedData[ele]?.fixtureLibCode && !groupedData[ele]?.status ) {
75
+ // await planoLibraryService.updateOne( { fixtureLibCode: groupedData[ele]?.fixtureLibCode }, groupedData[ele] );
76
+ // } else {
77
+ let FixLibCode = await getMaxFixtureLibCode();
78
+ groupedData[ele].fixtureLibCode = FixLibCode;
79
+ // fixtureData.push( groupedData[ele] );
80
+ await planoLibraryService.findOneAndUpdate( { 'fixtureCategory': groupedData[ele].fixtureCategory, 'fixtureWidth.value': groupedData[ele].fixtureWidth.value, 'fixtureWidth.unit': groupedData[ele].fixtureWidth.unit }, groupedData[ele] );
81
+ // }
83
82
  }
84
- await planoLibraryService.insertMany( fixtureData );
83
+ // let deleteList = inputData.deleteFixtureList.map( ( ele ) => new ObjectId( ele ) );
84
+ // if ( deleteList.length ) {
85
+ // await planoLibraryService.deleteMany( { _id: { $in: deleteList } } );
86
+ // }
87
+ // await planoLibraryService.insertMany( fixtureData );
85
88
  return res.sendSuccess( 'Fixture library created successfully' );
86
89
  } catch ( e ) {
87
90
  console.log( e );
@@ -242,7 +245,7 @@ export async function FixtureLibraryList( req, res ) {
242
245
  const matchStage = {
243
246
  clientId: req.body.clientId,
244
247
  ...( req.body?.searchValue ?
245
- { fixtureCategory: { $regex: req.body.searchValue, $options: 'i' } } :
248
+ { $or: [ { fixtureCategory: { $regex: req.body.searchValue, $options: 'i' } }, { fixtureCategorySize: { $regex: req.body.searchValue, $options: 'i' } } ] } :
246
249
  {} ),
247
250
  ...( req.body?.filter?.type?.length ?
248
251
  { fixtureType: { $in: req.body.filter.type } } :
@@ -253,6 +256,13 @@ export async function FixtureLibraryList( req, res ) {
253
256
  };
254
257
 
255
258
  const query = [
259
+ {
260
+ $addFields: {
261
+ fixtureCategorySize: {
262
+ $concat: [ '$fixtureCategory', ' - ', { $toString: '$fixtureWidth.value' }, { $toString: '$fixtureWidth.unit' } ],
263
+ },
264
+ },
265
+ },
256
266
  { $match: matchStage },
257
267
  {
258
268
  $lookup: {
@@ -284,6 +294,7 @@ export async function FixtureLibraryList( req, res ) {
284
294
  },
285
295
  {
286
296
  $project: {
297
+ fixtureCategorySize: 1,
287
298
  fixtureWidth: 1,
288
299
  fixtureHeight: 1,
289
300
  fixtureLength: 1,
@@ -343,6 +354,7 @@ export async function FixtureLibraryList( req, res ) {
343
354
  footer: 1,
344
355
  fixtureLibCode: 1,
345
356
  planoId: { $ifNull: [ { $arrayElemAt: [ '$storeFixtureDetails.planoId', 0 ] }, [] ] },
357
+ templateCount: { $size: '$templateId' },
346
358
  },
347
359
  },
348
360
  {
@@ -381,6 +393,7 @@ export async function FixtureLibraryList( req, res ) {
381
393
  templateId: 1,
382
394
  header: 1,
383
395
  footer: 1,
396
+ templateCount: 1,
384
397
  fixtureLibCode: 1,
385
398
  planoStatus: { $ifNull: [ { $arrayElemAt: [ '$planoStatus.statusList', 0 ] }, [] ] },
386
399
  status: {
@@ -449,7 +462,7 @@ export async function FixtureLibraryList( req, res ) {
449
462
  const workbook = new ExcelJS.Workbook();
450
463
  const sheet = workbook.addWorksheet( 'Fixture Library' );
451
464
 
452
- sheet.getRow( 1 ).values = [ 'Fixture Code', 'Fixture Name', 'Fixture Type', 'Fixture Height(ft)', 'Fixture Width(ft)', 'Fixture Header Height(ft)', 'Fixture Footer Height(ft)', 'Shelf Number', 'Shelf Type', 'Tray Rows', 'Product Per Shelf/Tray', 'Panel Name' ];
465
+ sheet.getRow( 1 ).values = [ 'Fixture Name', 'Fixture Type', 'Fixture Height(ft)', 'Fixture Width(ft)', 'Fixture Header Height(ft)', 'Fixture Footer Height(ft)', 'Shelf Number', 'Shelf Type', 'Tray Rows', 'Product Per Shelf/Tray', 'Panel Name' ];
453
466
 
454
467
  let rowStart = 2;
455
468
  let lockedRowNumber = [];
@@ -475,7 +488,8 @@ export async function FixtureLibraryList( req, res ) {
475
488
  footerHeight = result.data[i].footer.height.value;
476
489
  }
477
490
  if ( !result.data[i].shelfConfig.length ) {
478
- sheet.getRow( rowStart ).values = [ result.data[i]?.fixtureLibCode || '', result.data[i]?.fixtureCategory || '', result.data[i]?.fixtureType || 'Wall', height, width, headerHeight, footerHeight, 0, '', 0, 0, '' ];
491
+ // result.data[i]?.fixtureLibCode || '',
492
+ sheet.getRow( rowStart ).values = [ result.data[i]?.fixtureCategory || '', result.data[i]?.fixtureType || 'Wall', height, width, headerHeight, footerHeight, 0, '', 0, 0, '' ];
479
493
  if ( result.data[i].status == 'active' || result.data[i].templateId.length ) {
480
494
  lockedRowNumber.push( rowStart );
481
495
  }
@@ -483,7 +497,7 @@ export async function FixtureLibraryList( req, res ) {
483
497
  }
484
498
 
485
499
  result.data[i].shelfConfig.forEach( ( shelf ) => {
486
- sheet.getRow( rowStart ).values = [ result.data[i]?.fixtureLibCode || '', result.data[i]?.fixtureCategory || '', result.data[i]?.fixtureType || 'Wall', height, width, headerHeight, footerHeight, shelf?.shelfNumber || 0, shelf?.shelfType || '', shelf?.trayRows || 0, shelf?.productPerShelf || 0, shelf?.label || '' ];
500
+ sheet.getRow( rowStart ).values = [ result.data[i]?.fixtureCategory || '', result.data[i]?.fixtureType || 'Wall', height, width, headerHeight, footerHeight, shelf?.shelfNumber || 0, shelf?.shelfType || '', shelf?.trayRows || 0, shelf?.productPerShelf || 0, shelf?.label || '' ];
487
501
  if ( result.data[i].status == 'active' || result.data[i].templateId.length ) {
488
502
  lockedRowNumber.push( rowStart );
489
503
  }
@@ -494,32 +508,32 @@ export async function FixtureLibraryList( req, res ) {
494
508
 
495
509
  const maxRows = 1048576;
496
510
 
497
- let unlockCellValues = 20000;
498
- let splitLoop = [];
499
-
500
- for ( let i=1; i<=unlockCellValues; i+=2000 ) {
501
- splitLoop.push( { start: i, end: i + 1999 } );
502
- }
503
-
504
- await Promise.all( splitLoop.map( ( item ) => {
505
- for ( let i=item.start; i<=item.end; i++ ) {
506
- const row = sheet.getRow( i );
507
- if ( i > rowStart - 1 ) {
508
- row.values = [ '', '', '', '', '', '', '', '', '', '', '', '' ];
509
- }
510
- if ( !lockedRowNumber.includes( i ) && i != 1 ) {
511
- row.eachCell( ( cell ) => {
512
- const columnLetter = cell.address.replace( /[0-9]/g, '' );
513
- if ( columnLetter != 'A' ) {
514
- cell.protection = { locked: false };
515
- }
516
- } );
517
- }
518
- }
519
- } ) );
520
-
521
-
522
- let dropDownRange = [ { key: `C2:C${maxRows}`, optionList: [ '"wall,floor"' ] }, { key: `I2:I${maxRows}`, optionList: [ '"shelf,tray"' ] } ];
511
+ // let unlockCellValues = 20000;
512
+ // let splitLoop = [];
513
+
514
+ // for ( let i=1; i<=unlockCellValues; i+=2000 ) {
515
+ // splitLoop.push( { start: i, end: i + 1999 } );
516
+ // }
517
+
518
+ // await Promise.all( splitLoop.map( ( item ) => {
519
+ // for ( let i=item.start; i<=item.end; i++ ) {
520
+ // const row = sheet.getRow( i );
521
+ // if ( i > rowStart - 1 ) {
522
+ // row.values = [ '', '', '', '', '', '', '', '', '', '', '', '' ];
523
+ // }
524
+ // if ( !lockedRowNumber.includes( i ) && i != 1 ) {
525
+ // row.eachCell( ( cell ) => {
526
+ // const columnLetter = cell.address.replace( /[0-9]/g, '' );
527
+ // if ( columnLetter != 'A' ) {
528
+ // cell.protection = { locked: false };
529
+ // }
530
+ // } );
531
+ // }
532
+ // }
533
+ // } ) );
534
+
535
+
536
+ let dropDownRange = [ { key: `B2:B${maxRows}`, optionList: [ '"wall,floor"' ] }, { key: `H2:H${maxRows}`, optionList: [ '"shelf,tray"' ] } ];
523
537
 
524
538
  dropDownRange.forEach( ( ele ) => {
525
539
  sheet.dataValidations.add( ele.key, {
@@ -533,10 +547,10 @@ export async function FixtureLibraryList( req, res ) {
533
547
  } );
534
548
 
535
549
 
536
- await sheet.protect( 'password123', {
537
- selectLockedCells: false,
538
- selectUnlockedCells: true,
539
- } );
550
+ // await sheet.protect( 'password123', {
551
+ // selectLockedCells: false,
552
+ // selectUnlockedCells: true,
553
+ // } );
540
554
 
541
555
  sheet.columns.forEach( ( column ) => {
542
556
  let maxLength = 10;
@@ -565,7 +579,7 @@ export async function duplicateFixture( req, res ) {
565
579
  if ( !req.body?.fixtureId ) {
566
580
  return res.sendError( 'FixtureId is required', 400 );
567
581
  }
568
- let fixtureLibDetails = await planoLibraryService.findOne( { _id: req.body?.fixtureId } );
582
+ let fixtureLibDetails = await planoLibraryService.findOne( { _id: req.body?.fixtureId }, { createdAt: 0, updatedAt: 0 } );
569
583
  if ( !fixtureLibDetails ) {
570
584
  return res.sendError( 'No data found', 204 );
571
585
  }
@@ -1160,8 +1174,12 @@ export async function getVmLibList( req, res ) {
1160
1174
  } else {
1161
1175
  const workbook = new ExcelJS.Workbook();
1162
1176
  const sheet = workbook.addWorksheet( 'Fixture Library' );
1177
+ const hiddenSheet = workbook.addWorksheet( 'Hidden' );
1178
+ hiddenSheet.state = 'veryHidden';
1179
+
1180
+ // 'VM Lib Code',
1163
1181
 
1164
- sheet.getRow( 1 ).values = [ 'VM Lib Code', 'VM Name', 'VM Type', 'VM Brand', 'VM Category', 'VM SubCategory', 'Unit', 'VM Height', 'VM Width', 'VM ImageUrl' ];
1182
+ sheet.getRow( 1 ).values = [ 'VM Name', 'VM Type', 'VM Brand', 'VM Category', 'VM SubCategory', 'Unit', 'VM Height', 'VM Width', 'VM ImageUrl' ];
1165
1183
 
1166
1184
  let rowStart = 2;
1167
1185
  let lockedRowNumber = [];
@@ -1183,7 +1201,8 @@ export async function getVmLibList( req, res ) {
1183
1201
  if ( result.data[i]?.vmImageUrl ) {
1184
1202
  result.data[i].vmImageUrl = process.env.PLANOCDNURL +'/'+result.data[i].vmImageUrl;
1185
1203
  }
1186
- sheet.getRow( rowStart ).values = [ result.data[i]?.vmLibCode || '', result.data[i]?.vmName || '', result.data[i]?.vmType || '', result.data[i]?.vmBrand || '', result.data[i]?.vmCategory || '', result.data[i]?.vmSubCategory ||'', unit, height, width, result.data[i]?.vmImageUrl || '' ];
1204
+ // result.data[i]?.vmLibCode || '',
1205
+ sheet.getRow( rowStart ).values = [ result.data[i]?.vmName || '', result.data[i]?.vmType || '', result.data[i]?.vmBrand || '', result.data[i]?.vmCategory || '', result.data[i]?.vmSubCategory ||'', unit, height, width, result.data[i]?.vmImageUrl || '' ];
1187
1206
  if ( result.data[i].templateId.length || result.data[i].status == 'active' ) {
1188
1207
  lockedRowNumber.push( rowStart );
1189
1208
  }
@@ -1193,15 +1212,27 @@ export async function getVmLibList( req, res ) {
1193
1212
  let productBrandDetails = await planoProductService.find( { clientId: req.body.clientId } );
1194
1213
  let vmTypeList = await vmTypeService.find( { clientId: req.body.clientId } );
1195
1214
  vmTypeList = vmTypeList.map( ( ele ) => ele.vmType );
1196
- let brand = productBrandDetails.map( ( ele ) => ele.brandName );
1215
+ let brandList = productBrandDetails.map( ( ele ) => ele.brandName );
1216
+ brandList.forEach( ( brand, index ) => {
1217
+ hiddenSheet.getCell( `A${index + 1}` ).value = brand;
1218
+ } );
1197
1219
  let brandCategories = productBrandDetails.flatMap( ( ele ) => [ ...ele.category ] );
1198
1220
  let brandSubCategories = productBrandDetails.flatMap( ( ele ) => [ ...ele.subCategory ] );
1199
1221
  brandCategories = [ ...new Set( brandCategories.map( ( ele ) => ele ) ) ];
1222
+ brandCategories = brandCategories.length ? brandCategories : [ '' ];
1223
+ brandSubCategories = brandSubCategories.length ? brandSubCategories : [ '' ];
1224
+ brandCategories.forEach( ( brand, index ) => {
1225
+ hiddenSheet.getCell( `B${index + 1}` ).value = brand;
1226
+ } );
1200
1227
  brandSubCategories = [ ...new Set( brandSubCategories.map( ( ele ) => ele ) ) ];
1228
+ brandSubCategories.forEach( ( brand, index ) => {
1229
+ hiddenSheet.getCell( `C${index + 1}` ).value = brand;
1230
+ } );
1201
1231
 
1202
1232
  const maxRows = 1048576;
1203
1233
 
1204
- let dropDownRange = [ { key: `C2:C${maxRows}`, optionList: [ `"${vmTypeList.toString()}"` ] }, { key: `D2:D${maxRows}`, optionList: [ `"${brand.toString()}"` ] }, { key: `E2:E${maxRows}`, optionList: [ `"${brandCategories.toString()}"` ] }, { key: `F2:F${maxRows}`, optionList: [ `"${brandSubCategories.toString()}"` ] }, { key: `G2:G${maxRows}`, optionList: [ '"mm,cm,inches,feet"' ] } ];
1234
+ let dropDownRange = [ { key: `B2:B${maxRows}`, optionList: [ `"${vmTypeList.toString()}"` ] }, { key: `C2:C${maxRows}`, optionList: [ `=Hidden!$A$1:$A$${brandList.length}` ] }, { key: `D2:D${maxRows}`, optionList: [ `=Hidden!$B$1:$B$${brandCategories.length}` ] }, { key: `E2:E${maxRows}`, optionList: [ `=Hidden!$C$1:$C$${brandSubCategories.length}` ] }, { key: `F2:F${maxRows}`, optionList: [ '"mm,cm,inches,feet"' ] } ];
1235
+
1205
1236
 
1206
1237
  dropDownRange.forEach( ( ele ) => {
1207
1238
  sheet.dataValidations.add( ele.key, {
@@ -1214,34 +1245,34 @@ export async function getVmLibList( req, res ) {
1214
1245
  } );
1215
1246
  } );
1216
1247
 
1217
- let unlockCellValues = 20000;
1218
- let splitLoop = [];
1219
-
1220
- for ( let i=1; i<=unlockCellValues; i+=2000 ) {
1221
- splitLoop.push( { start: i, end: i + 1999 } );
1222
- }
1223
-
1224
- await Promise.all( splitLoop.map( ( item ) => {
1225
- for ( let i=item.start; i<=item.end; i++ ) {
1226
- const row = sheet.getRow( i );
1227
- if ( i > rowStart - 1 ) {
1228
- row.values = [ '', '', '', '', '', '', '', '', '', '' ];
1229
- }
1230
- if ( !lockedRowNumber.includes( i ) && i != 1 ) {
1231
- row.eachCell( ( cell ) => {
1232
- const columnLetter = cell.address.replace( /[0-9]/g, '' );
1233
- if ( columnLetter != 'A' ) {
1234
- cell.protection = { locked: false };
1235
- }
1236
- } );
1237
- }
1238
- }
1239
- } ) );
1240
-
1241
- await sheet.protect( 'password123', {
1242
- selectLockedCells: false,
1243
- selectUnlockedCells: true,
1244
- } );
1248
+ // let unlockCellValues = 20000;
1249
+ // let splitLoop = [];
1250
+
1251
+ // for ( let i=1; i<=unlockCellValues; i+=2000 ) {
1252
+ // splitLoop.push( { start: i, end: i + 1999 } );
1253
+ // }
1254
+
1255
+ // await Promise.all( splitLoop.map( ( item ) => {
1256
+ // for ( let i=item.start; i<=item.end; i++ ) {
1257
+ // const row = sheet.getRow( i );
1258
+ // if ( i > rowStart - 1 ) {
1259
+ // row.values = [ '', '', '', '', '', '', '', '', '', '' ];
1260
+ // }
1261
+ // if ( !lockedRowNumber.includes( i ) && i != 1 ) {
1262
+ // row.eachCell( ( cell ) => {
1263
+ // const columnLetter = cell.address.replace( /[0-9]/g, '' );
1264
+ // if ( columnLetter != 'A' ) {
1265
+ // cell.protection = { locked: false };
1266
+ // }
1267
+ // } );
1268
+ // }
1269
+ // }
1270
+ // } ) );
1271
+
1272
+ // await sheet.protect( 'password123', {
1273
+ // selectLockedCells: false,
1274
+ // selectUnlockedCells: true,
1275
+ // } );
1245
1276
 
1246
1277
  sheet.columns.forEach( ( column ) => {
1247
1278
  let maxLength = 10;
@@ -1270,7 +1301,7 @@ export async function duplicateVmLib( req, res ) {
1270
1301
  if ( !req.body?.vmId ) {
1271
1302
  return res.sendError( 'VmId is required', 400 );
1272
1303
  }
1273
- let vmDetails = await vmService.findOne( { _id: req.body?.vmId } );
1304
+ let vmDetails = await vmService.findOne( { _id: req.body?.vmId }, { createdAt: 0, updatedAt: 0 } );
1274
1305
  if ( !vmDetails ) {
1275
1306
  return res.sendError( 'No data found', 204 );
1276
1307
  }
@@ -1354,20 +1385,11 @@ export async function getVmDetails( req, res ) {
1354
1385
  export async function vmBulkUpload( req, res ) {
1355
1386
  try {
1356
1387
  let inputData = req.body;
1357
- await Promise.all( inputData.vmData.map( async ( ele ) => {
1388
+
1389
+ for ( let ele of inputData.vmData ) {
1358
1390
  ele = { ...ele, clientId: req.body.clientId, vmWidth: { value: ele.vmWidth, unit: ele.unit }, vmHeight: { value: ele.vmHeight, unit: ele.unit } };
1359
- let vmLibData;
1360
- if ( !ele?.vmLibCode ) {
1361
- ele.vmLibCode = await getMaxVMLibCode();
1362
- ele.status = inputData.newVmStatus;
1363
- vmLibData = await vmService.create( ele );
1364
- } else {
1365
- if ( typeof ele?.isEdit == undefined ) {
1366
- ele.status = inputData.updateVmStatus;
1367
- await vmService.updateOne( { vmLibCode: ele.vmLibCode }, ele );
1368
- vmLibData = await vmService.findOne( { vmLibCode: ele.vmLibCode } );
1369
- }
1370
- }
1391
+ ele.vmLibCode = await getMaxVMLibCode();
1392
+ ele.status = inputData.newVmStatus;
1371
1393
  if ( vmLibData && !ele?.vmImageUrl.includes( '/vmType/' ) && ele?.vmImageUrl ) {
1372
1394
  let response = await fetch( ele?.vmImageUrl );
1373
1395
  let arrayBuffer = await response.arrayBuffer();
@@ -1380,13 +1402,42 @@ export async function vmBulkUpload( req, res ) {
1380
1402
  };
1381
1403
  let fileRes = await fileUpload( params );
1382
1404
  ele.vmImageUrl = fileRes?.Key;
1383
- await vmService.updateOne( { _id: vmLibData._id }, { vmImageUrl: ele.vmImageUrl } );
1384
1405
  }
1385
- } ) );
1386
- let deleteList = inputData.deleteVmList.map( ( ele ) => new ObjectId( ele ) );
1387
- if ( deleteList.length ) {
1388
- await vmService.deleteMany( { _id: { $in: deleteList } } );
1406
+ vmLibData = await vmService.updateOne( { vmName: ele?.vmName, clientId: inputData.clientId }, ele );
1389
1407
  }
1408
+ // await Promise.all( inputData.vmData.map( async ( ele ) => {
1409
+ // ele = { ...ele, clientId: req.body.clientId, vmWidth: { value: ele.vmWidth, unit: ele.unit }, vmHeight: { value: ele.vmHeight, unit: ele.unit } };
1410
+ // let vmLibData;
1411
+ // if ( !ele?.vmLibCode ) {
1412
+ // ele.vmLibCode = await getMaxVMLibCode();
1413
+ // ele.status = inputData.newVmStatus;
1414
+ // vmLibData = await vmService.create( ele );
1415
+ // } else {
1416
+ // if ( typeof ele?.isEdit == undefined ) {
1417
+ // ele.status = inputData.updateVmStatus;
1418
+ // await vmService.updateOne( { vmLibCode: ele.vmLibCode }, ele );
1419
+ // vmLibData = await vmService.findOne( { vmLibCode: ele.vmLibCode } );
1420
+ // }
1421
+ // }
1422
+ // if ( vmLibData && !ele?.vmImageUrl.includes( '/vmType/' ) && ele?.vmImageUrl ) {
1423
+ // let response = await fetch( ele?.vmImageUrl );
1424
+ // let arrayBuffer = await response.arrayBuffer();
1425
+ // let params = {
1426
+ // Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
1427
+ // Key: `vmType/${vmLibData._id}/${Date.now()}/${path.basename( ele?.vmImageUrl )}`,
1428
+ // fileName: path.basename( ele?.vmImageUrl ),
1429
+ // ContentType: response.headers.get( 'content-type' ),
1430
+ // body: Buffer.from( arrayBuffer ),
1431
+ // };
1432
+ // let fileRes = await fileUpload( params );
1433
+ // ele.vmImageUrl = fileRes?.Key;
1434
+ // await vmService.updateOne( { _id: vmLibData._id }, { vmImageUrl: ele.vmImageUrl } );
1435
+ // }
1436
+ // } ) );
1437
+ // let deleteList = inputData.deleteVmList.map( ( ele ) => new ObjectId( ele ) );
1438
+ // if ( deleteList.length ) {
1439
+ // await vmService.deleteMany( { _id: { $in: deleteList } } );
1440
+ // }
1390
1441
  return res.sendSuccess( 'Vmlibrary details uploaded successfully' );
1391
1442
  } catch ( e ) {
1392
1443
  console.log( e );