tango-app-api-store-builder 1.0.0-beta-142 → 1.0.0-beta-144

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-142",
3
+ "version": "1.0.0-beta-144",
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.185",
35
+ "tango-api-schema": "^2.2.186",
36
36
  "tango-app-api-middleware": "3.1.48",
37
37
  "url": "^0.11.4",
38
38
  "winston": "^3.17.0",
@@ -539,3 +539,32 @@ export async function getAllTemplates( req, res ) {
539
539
  logger.error( { functionName: 'getAllTemplates', error: e } );
540
540
  }
541
541
  }
542
+
543
+ export async function getFixtureTemplate( req, res ) {
544
+ try {
545
+ let fixtureTemplate = await fixtureConfigService.findOne( { _id: new mongoose.Types.ObjectId( req.query.templateId ) } );
546
+
547
+ if ( !fixtureTemplate ) {
548
+ return res.sendError( 'No data found', 204 );
549
+ }
550
+
551
+ const templateDoc = fixtureTemplate.toObject();
552
+
553
+
554
+ if ( templateDoc?.vmConfig?.length ) {
555
+ templateDoc.vmConfig = await Promise.all( templateDoc.vmConfig.map( async ( vm ) => {
556
+ let vmDetails = await vmService.findOne( { _id: vm.vmId } );
557
+ console.log( vmDetails );
558
+ if ( vmDetails ) {
559
+ vm = { ...vm, ...vmDetails.toObject() };
560
+ return vm;
561
+ }
562
+ } ) );
563
+ }
564
+
565
+
566
+ res.sendSuccess( templateDoc );
567
+ } catch ( e ) {
568
+ logger.error( { functionName: 'getFixtureTemplate', error: e } );
569
+ }
570
+ }
@@ -26,7 +26,7 @@ export async function getplanoFeedback( req, res ) {
26
26
  console.log( taskTypes );
27
27
  await Promise.all(
28
28
  taskTypes.map( async ( type, index ) => {
29
- const pipeline = buildPipelineByType( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus );
29
+ const pipeline = buildPipelineByType( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask );
30
30
 
31
31
  const data = await planoTaskService.aggregate( pipeline );
32
32
  console.log( '-------', data );
@@ -56,7 +56,7 @@ export async function getplanoFeedback( req, res ) {
56
56
  return res.sendError( e, 500 );
57
57
  }
58
58
  }
59
- function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByApprovalStatus ) {
59
+ function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask ) {
60
60
  console.log( type, planoId, floorId, filterByStatus );
61
61
  const matchStage = {
62
62
  $match: {
@@ -67,7 +67,7 @@ function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByAp
67
67
  },
68
68
  };
69
69
 
70
- const taskLookup = {
70
+ let taskLookup = {
71
71
  $lookup: {
72
72
  from: 'processedtasks',
73
73
  let: { taskId: '$taskId' },
@@ -104,6 +104,34 @@ function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByAp
104
104
  as: 'taskData',
105
105
  },
106
106
  };
107
+ if ( showtask ) {
108
+ taskLookup = {
109
+ $lookup: {
110
+ from: 'processedtasks',
111
+ let: { taskId: '$taskId' },
112
+ pipeline: [
113
+ {
114
+ $match: {
115
+ $expr: {
116
+ $and: [
117
+ { $eq: [ '$_id', '$$taskId' ] },
118
+ ],
119
+ },
120
+ },
121
+ },
122
+ {
123
+ $project: {
124
+ userName: 1,
125
+ createdAt: 1,
126
+ createdByName: 1,
127
+ submitTime_string: 1,
128
+ },
129
+ },
130
+ ],
131
+ as: 'taskData',
132
+ },
133
+ };
134
+ }
107
135
 
108
136
  const unwindTask = { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: false } };
109
137
 
@@ -231,91 +259,95 @@ function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByAp
231
259
  ];
232
260
  if ( filterByApprovalStatus && filterByApprovalStatus != '' ) {
233
261
  let filterByApprovalCond = { $eq: filterByApprovalStatus };
234
- if ( filterByApprovalStatus != 'pending' ) {
235
- filterByApprovalCond = { $ne: 'pending' };
236
- }
237
- console.log( '*********************' );
262
+
263
+ console.log( '*********************', filterByApprovalCond );
238
264
  pipeline = [];
239
265
  pipeline.push( matchStage );
240
- pipeline.push(
241
- { $unwind: '$answers' },
242
- { $unwind: '$answers.issues' },
243
- { $unwind: '$answers.issues.Details' },
244
- {
245
- $match: {
246
- 'answers.issues.Details.status': filterByApprovalCond,
247
- },
248
- },
249
- {
250
- $group: {
251
- _id: '$_id',
252
- doc: { $first: '$$ROOT' },
253
- },
254
- },
255
- {
256
- $replaceRoot: {
257
- newRoot: {
258
- $mergeObjects: [ '$doc', { answers: '$doc.originalAnswers' } ],
266
+ if ( filterByApprovalStatus === 'pending' ) {
267
+ pipeline.push(
268
+ {
269
+ $addFields: {
270
+ answers: {
271
+ $map: {
272
+ input: '$answers',
273
+ as: 'ans',
274
+ in: {
275
+ $mergeObjects: [
276
+ '$$ans',
277
+ {
278
+ issues: {
279
+ $map: {
280
+ input: '$$ans.issues',
281
+ as: 'issue',
282
+ in: {
283
+ $mergeObjects: [
284
+ '$$issue',
285
+ {
286
+ Details: {
287
+ $filter: {
288
+ input: '$$issue.Details',
289
+ as: 'detail',
290
+ cond: { $eq: [ '$$detail.status', 'pending' ] },
291
+ },
292
+ },
293
+ },
294
+ ],
295
+ },
296
+ },
297
+ },
298
+ },
299
+ ],
300
+ },
301
+ },
302
+ },
259
303
  },
260
304
  },
261
- },
262
- {
263
- $project: {
264
- originalAnswers: 0, // remove the temp field
265
- },
266
- },
267
- {
268
- $addFields: {
269
- answers: {
270
- $map: {
271
- input: {
272
- $cond: [
273
- { $isArray: '$answers' },
274
- '$answers',
275
- { $cond: [ { $gt: [ { $type: '$answers' }, 'missing' ] }, [ '$answers' ], [] ] },
276
- ],
277
- },
278
- as: 'ans',
279
- in: {
280
- $mergeObjects: [
281
- '$$ans',
282
- {
283
- issues: {
284
- $map: {
285
- input: {
286
- $cond: [
287
- { $isArray: '$$ans.issues' },
288
- '$$ans.issues',
289
- { $cond: [ { $gt: [ { $type: '$$ans.issues' }, 'missing' ] }, [ '$$ans.issues' ], [] ] },
290
- ],
291
- },
292
- as: 'issue',
293
- in: {
294
- $mergeObjects: [
295
- '$$issue',
296
- {
297
- Details: {
298
- $cond: [
299
- { $isArray: '$$issue.Details' },
300
- '$$issue.Details',
301
- { $cond: [ { $gt: [ { $type: '$$issue.Details' }, 'missing' ] }, [ '$$issue.Details' ], [] ] },
302
- ],
305
+
306
+
307
+ );
308
+ } else {
309
+ pipeline.push(
310
+ {
311
+ $addFields: {
312
+ answers: {
313
+ $map: {
314
+ input: '$answers',
315
+ as: 'ans',
316
+ in: {
317
+ $mergeObjects: [
318
+ '$$ans',
319
+ {
320
+ issues: {
321
+ $map: {
322
+ input: '$$ans.issues',
323
+ as: 'issue',
324
+ in: {
325
+ $mergeObjects: [
326
+ '$$issue',
327
+ {
328
+ Details: {
329
+ $filter: {
330
+ input: '$$issue.Details',
331
+ as: 'detail',
332
+ cond: { $ne: [ '$$detail.status', 'pending' ] },
333
+ },
334
+ },
303
335
  },
304
- },
305
- ],
336
+ ],
337
+ },
306
338
  },
307
339
  },
308
340
  },
309
- },
310
- ],
341
+ ],
342
+ },
311
343
  },
312
344
  },
313
345
  },
314
346
  },
315
- },
316
347
 
317
348
 
318
- );
349
+ );
350
+ }
319
351
  pipeline.push( taskLookup );
320
352
  pipeline.push( unwindTask );
321
353
  pipeline.push( ...commonLookups );
@@ -644,14 +676,16 @@ export async function updateFixtureStatus( req, res ) {
644
676
  },
645
677
 
646
678
  );
647
- let allTaskDone = vmTask.filter( ( data ) => data.status === 'incomplete' );
648
- if ( allTaskDone.length === 0 ) {
649
- await planoService.updateOne(
650
- {
651
- _id: new mongoose.Types.ObjectId( req.body.planoId ),
652
- },
653
- { $set: { planoProgress: 100 } },
654
- );
679
+ if ( vmTask.length>0 ) {
680
+ let allTaskDone = vmTask.filter( ( data ) => data.status === 'incomplete' );
681
+ if ( allTaskDone.length === 0 ) {
682
+ await planoService.updateOne(
683
+ {
684
+ _id: new mongoose.Types.ObjectId( req.body.planoId ),
685
+ },
686
+ { $set: { planoProgress: 100 } },
687
+ );
688
+ }
655
689
  }
656
690
  res.sendSuccess( 'updated successfully' );
657
691
  } catch ( e ) {
@@ -267,94 +267,37 @@ export async function FixtureLibraryList( req, res ) {
267
267
  {
268
268
  $lookup: {
269
269
  from: 'fixtureconfigs',
270
- let: { libraryId: '$_id' },
271
- pipeline: [
272
- {
273
- $match: {
274
- $expr: {
275
- $eq: [ '$fixtureLibraryId', '$$libraryId' ],
276
- },
277
- },
278
- },
279
- {
280
- $group: {
281
- _id: null,
282
- templateId: { $push: '$_id' },
283
- },
284
- },
285
- {
286
- $project: {
287
- _id: 0,
288
- templateId: 1,
289
- },
290
- },
291
- ],
270
+ localField: '_id',
271
+ foreignField: 'fixtureLibraryId',
292
272
  as: 'fixtureTemplate',
293
273
  },
294
274
  },
295
275
  {
296
- $project: {
297
- fixtureCategorySize: 1,
298
- fixtureWidth: 1,
299
- fixtureHeight: 1,
300
- fixtureLength: 1,
301
- shelfConfig: 1,
302
- shelfCount: { $size: '$shelfConfig' },
303
- fixtureCategory: 1,
304
- clientId: 1,
305
- fixtureType: 1,
306
- status: 1,
307
- header: 1,
308
- footer: 1,
309
- fixtureLibCode: 1,
310
- templateId: { $ifNull: [ { $arrayElemAt: [ '$fixtureTemplate.templateId', 0 ] }, [] ] },
276
+ $set: {
277
+ templateId: {
278
+ $setUnion: [
279
+ { $map: { input: '$fixtureTemplate', as: 'fc', in: '$$fc._id' } },
280
+ [],
281
+ ],
282
+ },
311
283
  },
312
284
  },
313
285
  {
314
286
  $lookup: {
315
287
  from: 'storefixtures',
316
- let: { libraryId: '$_id' },
317
- pipeline: [
318
- {
319
- $match: {
320
- $expr: {
321
- $eq: [ '$fixtureLibraryId', '$$libraryId' ],
322
- },
323
- },
324
- },
325
- {
326
- $group: {
327
- _id: null,
328
- planoId: { $push: '$planoId' },
329
- },
330
- },
331
- {
332
- $project: {
333
- _id: 0,
334
- planoId: 1,
335
- },
336
- },
337
- ],
288
+ localField: '_id',
289
+ foreignField: 'fixtureLibraryId',
338
290
  as: 'storeFixtureDetails',
339
291
  },
340
292
  },
341
293
  {
342
- $project: {
343
- fixtureWidth: 1,
344
- fixtureHeight: 1,
345
- fixtureLength: 1,
346
- shelfConfig: 1,
347
- shelfCount: 1,
348
- fixtureCategory: 1,
349
- clientId: 1,
350
- fixtureType: 1,
351
- status: 1,
352
- templateId: 1,
353
- header: 1,
354
- footer: 1,
355
- fixtureLibCode: 1,
356
- planoId: { $ifNull: [ { $arrayElemAt: [ '$storeFixtureDetails.planoId', 0 ] }, [] ] },
357
- templateCount: { $size: '$templateId' },
294
+ $set: {
295
+ planoId: {
296
+ $setUnion: [
297
+ { $map: { input: '$storeFixtureDetails', as: 'sf', in: '$$sf.planoId' } },
298
+ [],
299
+ ],
300
+ },
358
301
  },
359
302
  },
360
303
  {
@@ -386,14 +329,14 @@ export async function FixtureLibraryList( req, res ) {
386
329
  fixtureLength: 1,
387
330
  fixtureType: 1,
388
331
  shelfConfig: 1,
389
- shelfCount: 1,
332
+ shelfCount: { $size: '$shelfConfig' },
390
333
  fixtureCategory: 1,
391
334
  clientId: 1,
392
335
  planoId: 1,
393
336
  templateId: 1,
394
337
  header: 1,
395
338
  footer: 1,
396
- templateCount: 1,
339
+ templateCount: { $size: '$templateId' },
397
340
  fixtureLibCode: 1,
398
341
  planoStatus: { $ifNull: [ { $arrayElemAt: [ '$planoStatus.statusList', 0 ] }, [] ] },
399
342
  status: {
@@ -698,11 +641,10 @@ export async function uploadVmImage( req, res ) {
698
641
  if ( !req.params?.vmId ) {
699
642
  return res.sendError( 'id is required', 400 );
700
643
  }
701
- console.log( req.files );
702
644
  let params = {
703
645
  Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
704
- Key: `vmType/${req.params.vmId}/${Date.now()}/`,
705
- fileName: req.files.file.name,
646
+ Key: `vmType/${req.params.vmId}/`,
647
+ fileName: Date.now() +'.'+ req.files?.file?.name?.split( '.' )?.slice( -1 )?.[0],
706
648
  ContentType: req.files.file.mimeType,
707
649
  body: req.files.file.data,
708
650
  };
@@ -770,44 +712,44 @@ export async function getBrandList( req, res ) {
770
712
 
771
713
  sheet.getRow( 1 ).values = [ 'Brand Name', 'Brand Category', 'Brand SubCategory' ];
772
714
 
773
- let rowStart = 2;
774
- let lockedRowNumber = [];
715
+ // let rowStart = 2;
716
+ // let lockedRowNumber = [];
775
717
  if ( req.body.emptyDownload ) {
776
718
  getBrandDetails = [];
777
719
  }
778
- getBrandDetails.forEach( ( ele ) => {
779
- sheet.getRow( rowStart ).values = [ ele.brandName, ele.category.toString(), ele.subCategory.toString() ];
780
- if ( ele.isUsed ) {
781
- lockedRowNumber.push( rowStart );
782
- }
783
- rowStart = rowStart + 1;
784
- } );
720
+ // getBrandDetails.forEach( ( ele ) => {
721
+ // sheet.getRow( rowStart ).values = [ ele.brandName, ele.category.toString(), ele.subCategory.toString() ];
722
+ // if ( ele.isUsed ) {
723
+ // lockedRowNumber.push( rowStart );
724
+ // }
725
+ // rowStart = rowStart + 1;
726
+ // } );
785
727
 
786
- let unlockCellValues = 20000;
787
- let splitLoop = [];
728
+ // let unlockCellValues = 20000;
729
+ // let splitLoop = [];
788
730
 
789
- for ( let i=1; i<=unlockCellValues; i+=2000 ) {
790
- splitLoop.push( { start: i, end: i + 1999 } );
791
- }
731
+ // for ( let i=1; i<=unlockCellValues; i+=2000 ) {
732
+ // splitLoop.push( { start: i, end: i + 1999 } );
733
+ // }
792
734
 
793
- await Promise.all( splitLoop.map( ( item ) => {
794
- for ( let i=item.start; i<=item.end; i++ ) {
795
- const row = sheet.getRow( i );
796
- if ( i > rowStart - 1 ) {
797
- row.values = [ '', '', '', '', '', '', '', '', '', '' ];
798
- }
799
- if ( !lockedRowNumber.includes( i ) && i != 1 ) {
800
- row.eachCell( ( cell ) => {
801
- cell.protection = { locked: false };
802
- } );
803
- }
804
- }
805
- } ) );
735
+ // await Promise.all( splitLoop.map( ( item ) => {
736
+ // for ( let i=item.start; i<=item.end; i++ ) {
737
+ // const row = sheet.getRow( i );
738
+ // if ( i > rowStart - 1 ) {
739
+ // row.values = [ '', '', '', '', '', '', '', '', '', '' ];
740
+ // }
741
+ // if ( !lockedRowNumber.includes( i ) && i != 1 ) {
742
+ // row.eachCell( ( cell ) => {
743
+ // cell.protection = { locked: false };
744
+ // } );
745
+ // }
746
+ // }
747
+ // } ) );
806
748
 
807
- await sheet.protect( 'password123', {
808
- selectLockedCells: false,
809
- selectUnlockedCells: true,
810
- } );
749
+ // await sheet.protect( 'password123', {
750
+ // selectLockedCells: false,
751
+ // selectUnlockedCells: true,
752
+ // } );
811
753
 
812
754
  sheet.columns.forEach( ( column ) => {
813
755
  let maxLength = 10;
@@ -841,8 +783,8 @@ export async function addUpdateBrandList( req, res ) {
841
783
  brandData.push( {
842
784
  clientId: inputData.clientId,
843
785
  brandName: ele.brand,
844
- category: [ ...new Set( ele.category ) ],
845
- subCategory: [ ...new Set( ele.subCategory ) ],
786
+ category: [ ...new Set( ele?.category?.map( ( ele ) => ele ) ) ],
787
+ subCategory: [ ...new Set( ele?.subCategory?.map( ( ele ) => ele ) ) ],
846
788
  } );
847
789
  }
848
790
  } );
@@ -860,28 +802,66 @@ export async function uploadBrandList( req, res ) {
860
802
  let inputData = req.body;
861
803
 
862
804
  let brandData = inputData.brandData.reduce( ( acc, ele ) => {
863
- console.log( ele?.category, ele );
864
- if ( !acc[ele.brandName] ) {
865
- acc[ele.brandName] = {
866
- brandName: ele.brandName,
805
+ let category = ele?.['Brand Category'].split( ',' );
806
+ let subCategory = ele?.['Brand SubCategory'].split( ',' );
807
+ if ( !acc[ele['Brand Name']] ) {
808
+ acc[ele['Brand Name']] = {
809
+ brandName: ele['Brand Name'],
867
810
  clientId: inputData.clientId,
868
- category: [ ...new Set( ele?.category?.map( ( ele ) => ele ) ) ],
869
- subCategory: [ ...new Set( ele?.subCategory?.map( ( ele ) => ele ) ) ],
811
+ category: [ ...new Set( category?.filter( ( ele ) => ele ).map( ( ele ) => ele ) ) ],
812
+ subCategory: [ ...new Set( subCategory?.filter( ( ele ) => ele ).map( ( ele ) => ele ) ) ],
870
813
  };
871
814
  } else {
872
- acc[ele.brandName].category.push( ...ele.category );
873
- if ( ele?.subCategory.length ) {
874
- acc[ele.brandName].subCategory.push( ...ele?.subCategory );
815
+ category.forEach( ( cat ) => {
816
+ if ( !acc[ele['Brand Name']].category.includes( cat ) ) {
817
+ acc[ele['Brand Name']].category.push( cat );
818
+ }
819
+ } );
820
+ if ( subCategory.length ) {
821
+ subCategory.forEach( ( cat ) => {
822
+ if ( !acc[ele['Brand Name']].subCategory.includes( cat ) ) {
823
+ acc[ele['Brand Name']].subCategory.push( cat );
824
+ }
825
+ } );
875
826
  }
876
827
  }
877
828
  return acc;
878
829
  }, {} );
830
+ await Promise.all( Object.keys( brandData ).map( async ( brand ) => {
831
+ let brandLower = brand.toLowerCase();
832
+ let query = [
833
+ {
834
+ $addFields: {
835
+ brandLower: { $toLower: '$brandName' },
836
+ },
837
+ },
838
+ {
839
+ $match: {
840
+ brandLower: brandLower,
841
+ clientId: inputData.clientId,
842
+ },
843
+ },
844
+ ];
845
+ let brandDetails = await planoProductService.aggregate( query );
846
+ if ( brandDetails.length ) {
847
+ let getCategory = brandDetails[0]?.category;
848
+ let getsubCategory = brandDetails[0]?.subCategory;
849
+ brandData[brand].category.forEach( ( ele ) => {
850
+ if ( !getCategory.includes( ele ) ) {
851
+ getCategory.push( ele );
852
+ }
853
+ } );
854
+ brandData[brand].subCategory.forEach( ( ele ) => {
855
+ if ( !getsubCategory.includes( ele ) ) {
856
+ getsubCategory.push( ele );
857
+ }
858
+ } );
859
+ await planoProductService.updateOne( { _id: brandDetails[0]._id }, { category: getCategory, subCategory: getsubCategory } );
860
+ } else {
861
+ await planoProductService.create( brandData[brand] );
862
+ }
863
+ } ) );
879
864
 
880
- await planoProductService.deleteMany( { clientId: inputData.clientId, _id: { $nin: inputData.brandUsedList } } );
881
- await planoProductService.insertMany( Object.values( brandData ) );
882
- // await Promise.all( Object.keys( brandData ).map( async ( ele ) => {
883
- // await planoProductService.updateOne( { brandName: { $regex: brandData[ele].brandName, $options: 'i' }, clientId: req.body.clientId }, brandData[ele] );
884
- // } ) );
885
865
  return res.sendSuccess( 'Brand details upload successfully' );
886
866
  } catch ( e ) {
887
867
  logger.error( { functionName: 'uploadBrandList', error: e } );
@@ -993,13 +973,7 @@ export async function getVmLibList( req, res ) {
993
973
  {
994
974
  $group: {
995
975
  _id: null,
996
- templateId: { $push: '$_id' },
997
- },
998
- },
999
- {
1000
- $project: {
1001
- _id: 0,
1002
- templateId: 1,
976
+ templateIds: { $addToSet: '$_id' },
1003
977
  },
1004
978
  },
1005
979
  ],
@@ -1007,66 +981,26 @@ export async function getVmLibList( req, res ) {
1007
981
  },
1008
982
  },
1009
983
  {
1010
- $project: {
1011
- vmName: 1,
1012
- vmType: 1,
1013
- vmBrand: 1,
1014
- vmCategory: 1,
1015
- clientId: 1,
1016
- vmHeight: 1,
1017
- status: 1,
1018
- vmWidth: 1,
1019
- vmImageUrl: 1,
1020
- isDoubleSided: 1,
1021
- vmSubCategory: 1,
1022
- vmLibCode: 1,
1023
- templateId: { $ifNull: [ { $arrayElemAt: [ '$fixtureTemplate.templateId', 0 ] }, [] ] },
984
+ $set: {
985
+ templateId: { $ifNull: [ { $arrayElemAt: [ '$fixtureTemplate.templateIds', 0 ] }, [] ] },
1024
986
  },
1025
987
  },
1026
988
  {
1027
989
  $lookup: {
1028
990
  from: 'storefixtures',
1029
- let: { libraryId: '$_id' },
1030
- pipeline: [
1031
- {
1032
- $match: {
1033
- $expr: {
1034
- $in: [ '$$libraryId', { $ifNull: [ '$vmConfig.vmId', [] ] } ],
1035
- },
1036
- },
1037
- },
1038
- {
1039
- $group: {
1040
- _id: null,
1041
- planoId: { $push: '$planoId' },
1042
- },
1043
- },
1044
- {
1045
- $project: {
1046
- _id: 0,
1047
- planoId: 1,
1048
- },
1049
- },
1050
- ],
991
+ localField: 'templateId',
992
+ foreignField: 'fixtureConfigId',
1051
993
  as: 'storeFixtureDetails',
1052
994
  },
1053
995
  },
1054
996
  {
1055
- $project: {
1056
- vmName: 1,
1057
- vmType: 1,
1058
- vmBrand: 1,
1059
- vmCategory: 1,
1060
- clientId: 1,
1061
- vmHeight: 1,
1062
- status: 1,
1063
- vmWidth: 1,
1064
- vmImageUrl: 1,
1065
- isDoubleSided: 1,
1066
- templateId: 1,
1067
- vmLibCode: 1,
1068
- vmSubCategory: 1,
1069
- planoId: { $ifNull: [ { $arrayElemAt: [ '$storeFixtureDetails.planoId', 0 ] }, [] ] },
997
+ $set: {
998
+ planoId: {
999
+ $setUnion: [
1000
+ { $map: { input: '$storeFixtureDetails', as: 'sf', in: '$$sf.planoId' } },
1001
+ [],
1002
+ ],
1003
+ },
1070
1004
  templateCount: { $size: '$templateId' },
1071
1005
  },
1072
1006
  },
@@ -1472,3 +1406,52 @@ async function getMaxVMLibCode() {
1472
1406
  return false;
1473
1407
  }
1474
1408
  }
1409
+
1410
+ export async function fixtureNameList( req, res ) {
1411
+ try {
1412
+ let getFixtureDetails = await planoLibraryService.aggregate( [
1413
+ {
1414
+ $match: {
1415
+ clientId: req.query.clientId,
1416
+ status: 'complete',
1417
+ },
1418
+ },
1419
+ {
1420
+ $group: {
1421
+ _id: '',
1422
+ fixtureDetails: {
1423
+ $push: { fixtureName: {
1424
+ $concat: [
1425
+ '$fixtureCategory',
1426
+ ' - ',
1427
+ { $toString: '$fixtureWidth.value' },
1428
+ '$fixtureWidth.unit',
1429
+ ] }, id: '$_id',
1430
+ },
1431
+ },
1432
+ },
1433
+ },
1434
+ {
1435
+ $project: {
1436
+ _id: 1,
1437
+ fixtureDetails: 1,
1438
+ },
1439
+ },
1440
+ ] );
1441
+
1442
+ return res.sendSuccess( getFixtureDetails?.[0]?.fixtureDetails || [] );
1443
+ } catch ( e ) {
1444
+ logger.error( { functionName: 'fixtureNameList', error: e } );
1445
+ return res.sendError( e, 500 );
1446
+ }
1447
+ }
1448
+
1449
+ export async function vmNameList( req, res ) {
1450
+ try {
1451
+ let getVmDetails = await vmService.find( { clientId: req.query.clientId, status: 'complete' }, { vmName: 1, vmWidth: 1, vmHeight: 1, vmImageUrl: 1, vmType: 1 } );
1452
+ return res.sendSuccess( getVmDetails );
1453
+ } catch ( e ) {
1454
+ logger.error( { functionName: 'vmNameList', error: e } );
1455
+ return res.sendError( e, 500 );
1456
+ }
1457
+ }
@@ -8920,7 +8920,6 @@ export async function updatePlanoMappings( req, res ) {
8920
8920
  return res.sendError( 'Unauthorized', 401 );
8921
8921
  }
8922
8922
  try {
8923
- console.log( JSON.stringify( req.body ) );
8924
8923
  const floor = await storeBuilderService.findOne( { storeName: req.body.storeName } );
8925
8924
 
8926
8925
  for ( let i = 0; i < req.body?.walls?.length; i++ ) {
@@ -17,6 +17,7 @@ import * as fixtureConfigService from '../service/fixtureConfig.service.js';
17
17
  import * as planoStaticData from '../service/planoStaticData.service.js';
18
18
  import * as planoVmService from '../service/planoVm.service.js';
19
19
  import * as planotaskService from '../service/processedTaskservice.js';
20
+ import * as layoutService from '../service/storeBuilder.service.js';
20
21
 
21
22
 
22
23
  dayjs.extend( utc );
@@ -3639,7 +3640,7 @@ export async function planoList( req, res ) {
3639
3640
  },
3640
3641
  },
3641
3642
  },
3642
- { 'taskDetails.layoutStatus': 'pending' },
3643
+ // { 'taskDetails.layoutStatus': 'pending' },
3643
3644
  );
3644
3645
  query.push( {
3645
3646
  $match: {
@@ -3655,9 +3656,36 @@ export async function planoList( req, res ) {
3655
3656
  orQuery.push( { 'planoTask.taskStatus.status': { $in: [ 'open', 'inprogress' ] } } );
3656
3657
  }
3657
3658
  if ( inputData.filter.status.includes( 'reviewPending' ) ) {
3658
- orQuery.push( { $and: [ { 'taskDetails.layoutStatus': 'pending' }, { 'planoTask.taskStatus.type': 'layout' }, { 'planoTask.taskStatus.status': 'submit' } ] } );
3659
- orQuery.push( { $and: [ { 'taskDetails.fixtureStatus': 'pending' }, { 'planoTask.taskStatus.type': 'fixture' }, { 'planoTask.taskStatus.status': 'submit' } ] } );
3660
- orQuery.push( { $and: [ { 'taskDetails.vmStatus': 'pending' }, { 'planoTask.taskStatus.type': 'vm' }, { 'planoTask.taskStatus.status': 'submit' } ] } );
3659
+ orQuery.push( {
3660
+ $and: [
3661
+ { 'planoTask.taskStatus': {
3662
+ $elemMatch: {
3663
+ type: 'layout',
3664
+ status: 'submit',
3665
+ },
3666
+ } }, { 'taskDetails.layoutStatus': 'pending' },
3667
+ ],
3668
+ } );
3669
+ orQuery.push( {
3670
+ $and: [
3671
+ { 'planoTask.taskStatus': {
3672
+ $elemMatch: {
3673
+ type: 'fixture',
3674
+ status: 'submit',
3675
+ },
3676
+ } }, { 'taskDetails.fixtureStatus': 'pending' },
3677
+ ],
3678
+ } );
3679
+ orQuery.push( {
3680
+ $and: [
3681
+ { 'planoTask.taskStatus': {
3682
+ $elemMatch: {
3683
+ type: 'vm',
3684
+ status: 'submit',
3685
+ },
3686
+ } }, { 'taskDetails.vmStatus': 'pending' },
3687
+ ],
3688
+ } );
3661
3689
  }
3662
3690
  if ( inputData.filter.status.includes( 'completed' ) ) {
3663
3691
  orQuery.push( { $and: [ { 'taskDetails.layoutStatus': 'complete' }, { 'taskDetails.fixtureStatus': 'complete' }, { 'taskDetails.vmStatus': 'complete' } ] } );
@@ -3894,6 +3922,7 @@ export async function getTaskDetails( req, res ) {
3894
3922
  planoId: new mongoose.Types.ObjectId( req.query.planoId ),
3895
3923
  isPlano: true,
3896
3924
  date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) },
3925
+ floorId: new mongoose.Types.ObjectId( req.query.floorId ),
3897
3926
  },
3898
3927
  },
3899
3928
  {
@@ -3987,6 +4016,41 @@ export async function getTaskDetails( req, res ) {
3987
4016
  },
3988
4017
  },
3989
4018
  },
4019
+ hasDisagreeIssues: {
4020
+ $anyElementTrue: {
4021
+ $map: {
4022
+ input: {
4023
+ $reduce: {
4024
+ input: '$answers',
4025
+ initialValue: [],
4026
+ in: {
4027
+ $concatArrays: [
4028
+ '$$value',
4029
+ {
4030
+ $reduce: {
4031
+ input: { $ifNull: [ '$$this.issues', [] ] },
4032
+ initialValue: [],
4033
+ in: {
4034
+ $concatArrays: [
4035
+ '$$value',
4036
+ { $ifNull: [ '$$this.Details', [] ] },
4037
+ ],
4038
+ },
4039
+ },
4040
+ },
4041
+ ],
4042
+ },
4043
+ },
4044
+ },
4045
+ as: 'detail',
4046
+ in: {
4047
+ $or: [
4048
+ { $eq: [ '$$detail.status', 'disagree' ] },
4049
+ ],
4050
+ },
4051
+ },
4052
+ },
4053
+ },
3990
4054
  },
3991
4055
  },
3992
4056
  {
@@ -4028,6 +4092,33 @@ export async function getTaskDetails( req, res ) {
4028
4092
  ],
4029
4093
  },
4030
4094
  },
4095
+ layoutDisagree: {
4096
+ $sum: {
4097
+ $cond: [
4098
+ { $and: [ { $eq: [ '$type', 'layout' ] }, '$hasDisagreeIssues' ] },
4099
+ 1,
4100
+ 0,
4101
+ ],
4102
+ },
4103
+ },
4104
+ fixtureDisagree: {
4105
+ $sum: {
4106
+ $cond: [
4107
+ { $and: [ { $eq: [ '$type', 'fixture' ] }, '$hasDisagreeIssues' ] },
4108
+ 1,
4109
+ 0,
4110
+ ],
4111
+ },
4112
+ },
4113
+ vmDisagree: {
4114
+ $sum: {
4115
+ $cond: [
4116
+ { $and: [ { $eq: [ '$type', 'vm' ] }, '$hasDisagreeIssues' ] },
4117
+ 1,
4118
+ 0,
4119
+ ],
4120
+ },
4121
+ },
4031
4122
  },
4032
4123
  },
4033
4124
  {
@@ -4057,6 +4148,9 @@ export async function getTaskDetails( req, res ) {
4057
4148
  layoutPending: { $sum: '$layoutPending' },
4058
4149
  fixturePending: { $sum: '$fixturePending' },
4059
4150
  vmPending: { $sum: '$vmPending' },
4151
+ layoutDisagree: { $sum: '$layoutDisagree' },
4152
+ fixtureDisagree: { $sum: '$fixtureDisagree' },
4153
+ vmDisagree: { $sum: '$vmDisagree' },
4060
4154
  },
4061
4155
  },
4062
4156
  {
@@ -4068,6 +4162,7 @@ export async function getTaskDetails( req, res ) {
4068
4162
  $and: [
4069
4163
  { $gt: [ '$layoutCount', 0 ] },
4070
4164
  { $eq: [ '$layoutPending', 0 ] },
4165
+ { $eq: [ '$layoutDisagree', 0 ] },
4071
4166
  ],
4072
4167
  },
4073
4168
  then: 'complete',
@@ -4087,7 +4182,25 @@ export async function getTaskDetails( req, res ) {
4087
4182
  ],
4088
4183
  },
4089
4184
  then: 'pending',
4090
- else: '',
4185
+ else: {
4186
+ $cond: {
4187
+ if: {
4188
+ $and: [
4189
+ {
4190
+ $gt: [ '$layoutCount', 0 ],
4191
+ },
4192
+ {
4193
+ $gt: [
4194
+ '$layoutDisagree',
4195
+ 0,
4196
+ ],
4197
+ },
4198
+ ],
4199
+ },
4200
+ then: 'disagree',
4201
+ else: '',
4202
+ },
4203
+ },
4091
4204
  },
4092
4205
  },
4093
4206
  },
@@ -4100,6 +4213,9 @@ export async function getTaskDetails( req, res ) {
4100
4213
  {
4101
4214
  $eq: [ '$fixturePending', 0 ],
4102
4215
  },
4216
+ {
4217
+ $eq: [ '$fixtureDisagree', 0 ],
4218
+ },
4103
4219
  ],
4104
4220
  },
4105
4221
  then: 'complete',
@@ -4122,7 +4238,25 @@ export async function getTaskDetails( req, res ) {
4122
4238
  ],
4123
4239
  },
4124
4240
  then: 'pending',
4125
- else: '',
4241
+ else: {
4242
+ $cond: {
4243
+ if: {
4244
+ $and: [
4245
+ {
4246
+ $gt: [ '$fixtureCount', 0 ],
4247
+ },
4248
+ {
4249
+ $gt: [
4250
+ '$fixtureDisagree',
4251
+ 0,
4252
+ ],
4253
+ },
4254
+ ],
4255
+ },
4256
+ then: 'disagree',
4257
+ else: '',
4258
+ },
4259
+ },
4126
4260
  },
4127
4261
  },
4128
4262
  },
@@ -4133,6 +4267,7 @@ export async function getTaskDetails( req, res ) {
4133
4267
  $and: [
4134
4268
  { $gt: [ '$vmCount', 0 ] },
4135
4269
  { $eq: [ '$vmPending', 0 ] },
4270
+ { $eq: [ '$vmDisagree', 0 ] },
4136
4271
  ],
4137
4272
  },
4138
4273
  then: 'complete',
@@ -4145,7 +4280,25 @@ export async function getTaskDetails( req, res ) {
4145
4280
  ],
4146
4281
  },
4147
4282
  then: 'pending',
4148
- else: '',
4283
+ else: {
4284
+ $cond: {
4285
+ if: {
4286
+ $and: [
4287
+ {
4288
+ $gt: [ '$vmCount', 0 ],
4289
+ },
4290
+ {
4291
+ $gt: [
4292
+ '$vmDisagree',
4293
+ 0,
4294
+ ],
4295
+ },
4296
+ ],
4297
+ },
4298
+ then: 'disagree',
4299
+ else: '',
4300
+ },
4301
+ },
4149
4302
  },
4150
4303
  },
4151
4304
  },
@@ -4157,6 +4310,9 @@ export async function getTaskDetails( req, res ) {
4157
4310
  fixtureCount: 1,
4158
4311
  vmCount: 1,
4159
4312
  completeLayout: 1,
4313
+ layoutDisagree: 1,
4314
+ fixtureDisagree: 1,
4315
+ vmDisagree: 1,
4160
4316
  },
4161
4317
  },
4162
4318
  ],
@@ -4206,8 +4362,11 @@ export async function getTaskDetails( req, res ) {
4206
4362
  ];
4207
4363
 
4208
4364
  let taskInfo = await planotaskService.aggregate( query );
4209
- let disabledInfo = taskInfo?.[0]?.taskStatus?.filter( ( ele ) => ( ( ele.feedbackStatus && ele.feedbackStatus != 'complete' ) || ele.status != 'submit' ) && !ele?.breach );
4210
- console.log( disabledInfo );
4365
+ let disabledInfo = [];
4366
+ let floorDetails = await layoutService.findOne( { _id: req.query.floorId }, { isEdited: 1 } );
4367
+ if ( floorDetails && !floorDetails?.isEdited ) {
4368
+ disabledInfo = taskInfo?.[0]?.taskStatus?.filter( ( ele ) => ( ( ele.feedbackStatus && ![ 'complete', 'disagree' ].includes( ele.feedbackStatus ) ) || ele.status != 'submit' ) && !ele?.breach );
4369
+ }
4211
4370
  return res.sendSuccess( { taskDetails: taskInfo?.[0]?.taskStatus, disabled: disabledInfo?.length ? true : false } );
4212
4371
  } catch ( e ) {
4213
4372
  logger.error( { functionName: 'getTaskDetails', error: e } );
@@ -4,7 +4,7 @@ import * as storeService from '../service/store.service.js';
4
4
  import * as processedChecklistService from '../service/processedchecklist.service.js';
5
5
  import * as userService from '../service/user.service.js';
6
6
  import dayjs from 'dayjs';
7
- import { logger, fileUpload, signedUrl } from 'tango-app-api-middleware';
7
+ import { logger, fileUpload, signedUrl, insertOpenSearchData } from 'tango-app-api-middleware';
8
8
  import * as planoTaskService from '../service/planoTask.service.js';
9
9
  import * as planoService from '../service/planogram.service.js';
10
10
  import * as checklistService from '../service/checklist.service.js';
@@ -215,8 +215,8 @@ export async function createTask( req, res ) {
215
215
  scheduleEndTime_iso: dayjs.utc( endDate, 'YYYY-MM-DD hh:mm A' ).format(),
216
216
  allowedOverTime: false,
217
217
  allowedStoreLocation: req.body?.geoFencing || false,
218
- createdBy: task.createdBy,
219
- createdByName: task.createdByName,
218
+ createdBy: req?.user?._id || task?.createdBy,
219
+ createdByName: req?.user?.userName || task?.createdByName,
220
220
  questionAnswers: [],
221
221
  isdeleted: false,
222
222
  questionCount: 0,
@@ -598,7 +598,8 @@ export async function updateAnswersv2( req, res ) {
598
598
  if ( !taskDetails ) {
599
599
  return res.sendError( 'No data found', 204 );
600
600
  }
601
-
601
+ console.log( req.body.answers[0] );
602
+ console.log( req.body.answers[0].issues[0] );
602
603
  let data = {
603
604
  fixtureId: req.body.fixtureId,
604
605
  answers: req.body.answers,
@@ -612,13 +613,16 @@ export async function updateAnswersv2( req, res ) {
612
613
  storeName: req.body?.storeName,
613
614
  storeId: req.body?.storeId,
614
615
  };
615
- console.log( '111111', data );
616
+ console.log( '111111', data.answers[0] );
617
+ console.log( '111111', data.answers[0].issues[0] );
616
618
  if ( req.body.type==='layout' ) {
617
619
  await planoTaskService.updateOne( { planoId: req.body.planoId, taskType: req.body.taskType, floorId: req.body.floorId, fixtureId: req.body.fixtureId, type: req.body.type, date_string: dayjs().format( 'YYYY-MM-DD' ), ...( taskDetails?._id ) ? { taskId: taskDetails?._id } :{} }, data );
618
620
  } else {
619
621
  await planoTaskService.updateOne( { planoId: req.body.planoId, floorId: req.body.floorId, fixtureId: req.body.fixtureId, type: req.body.type, date_string: dayjs().format( 'YYYY-MM-DD' ), ...( taskDetails?._id ) ? { taskId: taskDetails?._id } :{} }, data );
620
622
  }
621
623
 
624
+ await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).planotaskcompliances, data );
625
+
622
626
  return res.sendSuccess( 'Fixture details updated successfully' );
623
627
  } catch ( e ) {
624
628
  logger.error( { functionName: 'updateAnswers', error: e } );
@@ -14,5 +14,6 @@ fixtureTemplateRouter
14
14
  .post( '/getTemplateList', validate( validateDtos.fixtureVMListSchema ), fixtureTemplateController.getTemplateList )
15
15
  .get( '/getTemplateDetails', validate( validateDtos.queryTemplateId ), fixtureTemplateController.getTemplateDetails )
16
16
  .post( '/updateFixtureTask', validate( validateDtos.updateFixtureTask ), fixtureTemplateController.updateFixtureTask )
17
- .post( '/getAllTemplates', fixtureTemplateController.getAllTemplates );
17
+ .post( '/getAllTemplates', fixtureTemplateController.getAllTemplates )
18
+ .get( '/getTemplate', validate( validateDtos.queryTemplateId ), fixtureTemplateController.getFixtureTemplate );
18
19
 
@@ -14,7 +14,8 @@ planoLibraryRouter
14
14
  .post( '/fixtureList', isAllowedSessionHandler, validate( validateDtos.fixtureVMListSchema ), planoLibraryController.FixtureLibraryList )
15
15
  .post( '/duplicateFixture', isAllowedSessionHandler, validate( validateDtos.bodyFixtureId ), planoLibraryController.duplicateFixture )
16
16
  .post( '/deleteFixture', isAllowedSessionHandler, validate( validateDtos.bodyFixtureId ), planoLibraryController.deleteFixture )
17
- .get( '/fixtureSizeList', isAllowedSessionHandler, validate( validateDtos.getClient ), planoLibraryController.getFixLibWidth );
17
+ .get( '/fixtureSizeList', isAllowedSessionHandler, validate( validateDtos.getClient ), planoLibraryController.getFixLibWidth )
18
+ .get( '/fixtureNameList', isAllowedSessionHandler, validate( validateDtos.getClient ), planoLibraryController.fixtureNameList );
18
19
 
19
20
  planoLibraryRouter
20
21
  .post( '/addVmType', isAllowedSessionHandler, validate( validateDtos.addVmType ), planoLibraryController.addVmType )
@@ -36,5 +37,6 @@ planoLibraryRouter
36
37
  .post( '/duplicateVmLib', isAllowedSessionHandler, validate( validateDtos.deleteVmLib ), planoLibraryController.duplicateVmLib )
37
38
  .post( '/deleteVmLib', isAllowedSessionHandler, validate( validateDtos.deleteVmLib ), planoLibraryController.deleteVmLibrary )
38
39
  .get( '/getVmDetails', isAllowedSessionHandler, validate( validateDtos.getVmDetails ), planoLibraryController.getVmDetails )
39
- .post( '/vmBulkUpload', isAllowedSessionHandler, validate( validateDtos.vmBulkUpload ), planoLibraryController.vmBulkUpload );
40
+ .post( '/vmBulkUpload', isAllowedSessionHandler, validate( validateDtos.vmBulkUpload ), planoLibraryController.vmBulkUpload )
41
+ .get( '/vmNameList', isAllowedSessionHandler, validate( validateDtos.getClient ), planoLibraryController.vmNameList );
40
42