tango-app-api-store-builder 1.0.0-beta-211 → 1.0.0-beta-213

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-211",
3
+ "version": "1.0.0-beta-213",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -30,17 +30,37 @@ export async function getplanoFeedback( req, res ) {
30
30
  const pipeline = buildPipelineByType( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask );
31
31
 
32
32
  let data = await planoTaskService.aggregate( pipeline );
33
- if ( filterByApprovalStatus && filterByApprovalStatus !== '' ) {
34
- data.forEach( ( element ) => {
35
- element.answers?.forEach( ( ans ) => {
36
- ans.issues = ans.issues?.filter(
37
- ( issue ) => issue.Details && issue.Details.length > 0,
33
+ if ( filterByApprovalStatus && filterByApprovalStatus?.length ) {
34
+ if ( type == 'fixture' ) {
35
+ let pendingData = [];
36
+ let agreeData = [];
37
+ let disAgreeData = [];
38
+ if ( filterByApprovalStatus.includes( 'pending' ) ) {
39
+ pendingData = data.filter( ( element ) => {
40
+ return element?.approvalStatus == 'pending';
41
+ } );
42
+ } if ( filterByApprovalStatus.includes( 'agree' ) ) {
43
+ agreeData = data.filter( ( element ) => {
44
+ return element?.answers?.[0]?.status == 'agree';
45
+ } );
46
+ } if ( filterByApprovalStatus.includes( 'disagree' ) ) {
47
+ disAgreeData = data.filter( ( element ) => {
48
+ return element?.answers?.[0]?.status == 'disagree';
49
+ } );
50
+ }
51
+ data = [ ...pendingData, ...agreeData, ...disAgreeData ];
52
+ } else {
53
+ data.forEach( ( element ) => {
54
+ element.answers?.forEach( ( ans ) => {
55
+ ans.issues = ans.issues?.filter(
56
+ ( issue ) => issue.Details && issue.Details.length > 0,
57
+ );
58
+ } );
59
+ element.answers = element.answers?.filter(
60
+ ( ans ) => ans.issues && ans.issues.length > 0,
38
61
  );
39
62
  } );
40
- element.answers = element.answers?.filter(
41
- ( ans ) => ans.issues && ans.issues.length > 0,
42
- );
43
- } );
63
+ }
44
64
  data = data.filter(
45
65
  ( element ) => element.answers && element.answers.length > 0,
46
66
  );
@@ -354,7 +374,7 @@ function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByAp
354
374
  ...vmStages,
355
375
  { $sort: { _id: -1 } },
356
376
  ];
357
- if ( filterByApprovalStatus && filterByApprovalStatus != '' ) {
377
+ if ( filterByApprovalStatus && filterByApprovalStatus != '' && type !== 'fixture' ) {
358
378
  pipeline = [];
359
379
  pipeline.push( matchStage );
360
380
  pipeline.push(
@@ -960,6 +980,19 @@ export async function updateFixtureStatus( req, res ) {
960
980
  ] );
961
981
 
962
982
  await planoTaskService.updateOne( { _id: req.body._id }, { approvalStatus: 'approved' } );
983
+ let fixtureTask = await planoTaskService.find(
984
+ {
985
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
986
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
987
+ type: 'fixture',
988
+ },
989
+ );
990
+ if ( fixtureTask.length > 0 ) {
991
+ let allTaskDone = fixtureTask.filter( ( data ) => !data?.answers?.[0]?.status || data?.answers?.[0]?.status == 'disagree' );
992
+ if ( allTaskDone.length === 0 ) {
993
+ await floorService.updateOne( { _id: new mongoose.Types.ObjectId( req.body.floorId ) }, { planoProgress: 100 } );
994
+ }
995
+ }
963
996
  } else {
964
997
  let updateResponse = await planoTaskService.updateOnefilters(
965
998
  { _id: new mongoose.Types.ObjectId( req.body._id ) },
@@ -9698,45 +9698,44 @@ function transformProducts( products, shelvesByZone, fixtureData ) {
9698
9698
 
9699
9699
  // ---------------------Plano Migrate-------------------------
9700
9700
 
9701
- export async function getAllPlanoIds(req, res){
9701
+ export async function getAllPlanoIds( req, res ) {
9702
9702
  try {
9703
-
9704
- if (!req.query?.clientId) {
9705
- return res.sendError('Client id is required', 400);
9703
+ if ( !req.query?.clientId ) {
9704
+ return res.sendError( 'Client id is required', 400 );
9706
9705
  }
9707
- const floorsData = await storeBuilderService.aggregate([
9706
+ const floorsData = await storeBuilderService.aggregate( [
9708
9707
  {
9709
- '$match': {
9710
- 'clientId': '11'
9711
- }
9708
+ '$match': {
9709
+ 'clientId': '11',
9710
+ },
9712
9711
  }, {
9713
- '$group': {
9714
- '_id': '$planoId',
9715
- 'storeName': {
9716
- '$first': '$storeName'
9712
+ '$group': {
9713
+ '_id': '$planoId',
9714
+ 'storeName': {
9715
+ '$first': '$storeName',
9716
+ },
9717
+ 'storeId': {
9718
+ '$first': '$storeId',
9719
+ },
9717
9720
  },
9718
- 'storeId': {
9719
- '$first': '$storeId'
9720
- }
9721
- }
9722
- }, {
9723
- '$project': {
9724
- 'planoId': '$_id',
9725
- 'storeName': 1,
9726
- 'storeId': 1
9727
- }
9728
9721
  }, {
9729
- '$sort': { storeName: 1 }
9730
- }
9731
- ]);
9722
+ '$project': {
9723
+ 'planoId': '$_id',
9724
+ 'storeName': 1,
9725
+ 'storeId': 1,
9726
+ },
9727
+ }, {
9728
+ '$sort': { storeName: 1 },
9729
+ },
9730
+ ] );
9732
9731
 
9733
- if (floorsData) {
9734
- return res.sendSuccess(floorsData);
9732
+ if ( floorsData ) {
9733
+ return res.sendSuccess( floorsData );
9735
9734
  } else {
9736
- return res.sendError("No floor data found", 204)
9735
+ return res.sendError( 'No floor data found', 204 );
9737
9736
  }
9738
- } catch (error) {
9739
- console.log("@@ ~ getAllPlanoIds [ERR]:", error);
9740
- return res.sendError(e, 500);
9737
+ } catch ( error ) {
9738
+ console.log( '@@ ~ getAllPlanoIds [ERR]:', error );
9739
+ return res.sendError( e, 500 );
9741
9740
  }
9742
- }
9741
+ }
@@ -25,8 +25,9 @@ import * as fixtureShelfDuplicateService from '../service/fixtureShelfDuplicate.
25
25
  import * as planoMappingDuplicateService from '../service/planoMappingDuplicate.service.js';
26
26
  import * as fixtureConfigDuplicateService from '../service/fixtureConfigDuplicate.service.js';
27
27
  import * as planoVmDuplicateService from '../service/planoVmDuplicate.service.js';
28
+ import advancedFormat from 'dayjs/plugin/advancedFormat.js';
28
29
 
29
-
30
+ dayjs.extend( advancedFormat );
30
31
  dayjs.extend( utc );
31
32
  dayjs.extend( customParseFormat );
32
33
 
@@ -2800,7 +2801,7 @@ export async function storeFixturesv2( req, res ) {
2800
2801
  planograms.map( async ( planogram ) => {
2801
2802
  const floors = await storeBuilderService.find(
2802
2803
  { planoId: planogram._id, ...( req.body?.floorId && { _id: req.body.floorId } ) },
2803
- { floorName: 1, layoutPolygon: 1, planoId: 1, isEdited: 1, planoProgress: 1 },
2804
+ { floorName: 1, layoutPolygon: 1, planoId: 1, isEdited: 1, planoProgress: 1, updatedAt: 1 },
2804
2805
  );
2805
2806
 
2806
2807
  const floorsWithFixtures = await Promise.all(
@@ -2811,12 +2812,12 @@ export async function storeFixturesv2( req, res ) {
2811
2812
  const masterTemplateIds = new Set();
2812
2813
  const layoutPolygonWithFixtures = await Promise.all(
2813
2814
  floor.layoutPolygon.map( async ( element ) => {
2814
- const fixtures = await storeFixtureService.findAndSort( {
2815
+ const fixtures = await storeFixtureService.findAndSort( {
2815
2816
  floorId: floor._id,
2816
2817
  associatedElementType: element.elementType,
2817
2818
  associatedElementNumber: element.elementNumber,
2818
2819
  fixtureType: { $ne: 'other' },
2819
- }, { shelfcount: 0 }, { associatedElementFixtureNumber: 1 } );
2820
+ }, { shelfcount: 0 }, { associatedElementFixtureNumber: 1 } );
2820
2821
 
2821
2822
  const fixturesWithStatus = await Promise.all(
2822
2823
  fixtures.map( async ( fixture ) => {
@@ -2917,7 +2918,7 @@ export async function storeFixturesv2( req, res ) {
2917
2918
  $and: [
2918
2919
  { associatedElementType: { $exists: false } },
2919
2920
  { associatedElementNumber: { $exists: false } },
2920
- { fixtureType: { $ne: 'other' } }
2921
+ { fixtureType: { $ne: 'other' } },
2921
2922
  ],
2922
2923
  }, { shelfcount: 0 }, { associatedElementFixtureNumber: 1 } );
2923
2924
 
@@ -3020,6 +3021,7 @@ export async function storeFixturesv2( req, res ) {
3020
3021
 
3021
3022
  return {
3022
3023
  ...floor.toObject(),
3024
+ updatedAt: dayjs( floor?.updatedAt ).format( 'Do MMM YYYY' ),
3023
3025
  fixtureCount: fixtureCount,
3024
3026
  vmCount: totalVmCount,
3025
3027
  layoutPolygon: layoutPolygonWithFixtures,
@@ -3495,7 +3497,7 @@ export async function storeFixturesTaskv2( req, res ) {
3495
3497
  floorId: floor._id,
3496
3498
  associatedElementType: element.elementType,
3497
3499
  associatedElementNumber: element.elementNumber,
3498
- fixtureType: { $ne: 'other' }
3500
+ fixtureType: { $ne: 'other' },
3499
3501
  }, { shelfcount: 0 }, { associatedElementFixtureNumber: 1 } );
3500
3502
 
3501
3503
  const fixturesWithStatus = await Promise.all(
@@ -3550,7 +3552,7 @@ export async function storeFixturesTaskv2( req, res ) {
3550
3552
  let disabled = true;
3551
3553
  if ( compliance?.status ) {
3552
3554
  const hasDisagree = compliance?.answers?.some( ( answer ) =>
3553
- answer?.status === 'disagree' ||
3555
+ answer?.status === 'disagree' || ( req.body?.type == 'fixture' && req?.body?.redo && compliance.status == 'complete' && !answer?.status ) ||
3554
3556
  answer?.issues?.some( ( issue ) =>
3555
3557
  issue?.Details?.some( ( detail ) => detail.status === 'disagree' ),
3556
3558
  ),
@@ -3598,7 +3600,7 @@ export async function storeFixturesTaskv2( req, res ) {
3598
3600
  $and: [
3599
3601
  { associatedElementType: { $exists: false } },
3600
3602
  { associatedElementNumber: { $exists: false } },
3601
- { fixtureType: { $ne: 'other' } }
3603
+ { fixtureType: { $ne: 'other' } },
3602
3604
  ],
3603
3605
  }, { shelfcount: 0 }, { associatedElementFixtureNumber: 1 } );
3604
3606
 
@@ -3653,7 +3655,7 @@ export async function storeFixturesTaskv2( req, res ) {
3653
3655
  let disabled = true;
3654
3656
  if ( compliance?.status ) {
3655
3657
  const hasDisagree = compliance?.answers?.some( ( answer ) =>
3656
- answer?.status === 'disagree' ||
3658
+ answer?.status === 'disagree' || ( req.body?.type == 'fixture' && req?.body?.redo && compliance.status == 'complete' && !answer?.status ) ||
3657
3659
  answer?.issues?.some( ( issue ) =>
3658
3660
  issue?.Details?.some( ( detail ) => detail.status === 'disagree' ),
3659
3661
  ),
@@ -4864,6 +4866,7 @@ export async function getTaskDetails( req, res ) {
4864
4866
  isPlano: true,
4865
4867
  date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) },
4866
4868
  floorId: new mongoose.Types.ObjectId( req.query.floorId ),
4869
+ planoType: { $in: [ 'layout', 'fixture', 'vm' ] },
4867
4870
  },
4868
4871
  },
4869
4872
  {
@@ -5301,8 +5304,12 @@ export async function getTaskDetails( req, res ) {
5301
5304
  let taskInfo = await planotaskService.aggregate( query );
5302
5305
  let disabledInfo = [];
5303
5306
  let floorDetails = await layoutService.findOne( { _id: req.query.floorId }, { isEdited: 1, planoProgress: 1 } );
5304
- if ( floorDetails && !floorDetails?.isEdited ) {
5305
- disabledInfo = taskInfo?.[0]?.taskStatus?.filter( ( ele ) => ( ( ele.feedbackStatus && ![ 'complete', 'disagree' ].includes( ele.feedbackStatus ) ) || ele.status != 'submit' ) && !ele?.breach );
5307
+ disabledInfo = taskInfo?.[0]?.taskStatus?.filter( ( ele ) => ( ( ele.feedbackStatus && ![ 'complete', 'disagree' ].includes( ele.feedbackStatus ) ) || ele.status != 'submit' ) && !ele?.breach );
5308
+ if ( floorDetails.isEdited ) {
5309
+ let findPending = taskInfo?.[0]?.taskStatus?.findIndex( ( ele ) => ele.type == 'fixture' && ele.feedbackStatus == 'pending' );
5310
+ if ( findPending != -1 ) {
5311
+ disabledInfo = [];
5312
+ }
5306
5313
  }
5307
5314
  return res.sendSuccess( { taskDetails: taskInfo?.[0]?.taskStatus, disabled: disabledInfo?.length ? true : false, planoProgress: floorDetails?.planoProgress ?? 25 } );
5308
5315
  } catch ( e ) {
@@ -694,6 +694,7 @@ export async function updateAnswersv2( req, res ) {
694
694
  storeName: req.body?.storeName,
695
695
  storeId: req.body?.storeId,
696
696
  date_string: dayjs().format( 'YYYY-MM-DD' ),
697
+ approvalStatus: 'pending',
697
698
  };
698
699
  if ( req.body.type === 'layout' ) {
699
700
  await planoTaskService.updateOne( { planoId: req.body.planoId, taskType: req.body.taskType, floorId: req.body.floorId, fixtureId: req.body.fixtureId, type: req.body.type, ...( taskDetails?._id ) ? { taskId: taskDetails?._id } : {} }, data );