tango-app-api-store-builder 1.0.0-beta-114 → 1.0.0-beta-115

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-114",
3
+ "version": "1.0.0-beta-115",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -489,22 +489,84 @@ export async function updateFixtureStatus( req, res ) {
489
489
  }
490
490
  }
491
491
 
492
- export async function updateStoreFixture( req, res ) {
492
+ export async function updateStoreFixture(req, res) {
493
493
  try {
494
494
  const { fixtureId, data } = req.body;
495
495
 
496
- const update = await storeFixtureService.updateOne( { _id: new mongoose.Types.ObjectId( fixtureId ) }, data );
496
+ const currentFixture = await storeFixtureService.findOne({ _id: new mongoose.Types.ObjectId(fixtureId) });
497
+ let currentFixtureDoc = currentFixture.toObject()
497
498
 
498
- console.log( update );
499
+ const productBrandName = new Set();
500
+ const productCategory = new Set();
501
+ const productSubCategory = new Set();
499
502
 
500
- data.shelfConfig.forEach( async ( shelf ) => {
501
- await fixtureShelfService.updateOne( { _id: new mongoose.Types.ObjectId( shelf._id ) }, shelf );
502
- } );
503
+ data.shelfConfig.forEach((shelf) => {
504
+ const { productBrandName: brand, productCategory: category, productSubCategory: subCategory } = shelf;
503
505
 
506
+ if (Array.isArray(brand)) {
507
+ brand.forEach((b) => productBrandName.add(b));
508
+ }
504
509
 
505
- res.sendSuccess( 'Updated Successfully' );
506
- } catch ( e ) {
507
- logger.error( { functionName: 'updateStoreFixture', error: e } );
508
- return res.sendError( e, 500 );
510
+ if (Array.isArray(category)) {
511
+ category.forEach((c) => productCategory.add(c));
512
+ }
513
+
514
+ if (Array.isArray(subCategory)) {
515
+ subCategory.forEach((s) => productSubCategory.add(s));
516
+ }
517
+ });
518
+
519
+
520
+
521
+ if (currentFixtureDoc.fixtureConfigId.toString() !== data.fixtureConfigId) {
522
+ const newTemplate = await fixtureConfigService.findOne({_id: data.fixtureConfigId})
523
+ currentFixtureDoc = {
524
+ ...currentFixtureDoc,
525
+ ...newTemplate.toObject(),
526
+ fixtureConfigDoc:newTemplate.toObject()._id,
527
+ productBrandName:[...productBrandName],
528
+ productCategory:[...productCategory],
529
+ productSubCategory:[...productSubCategory]
530
+ }
531
+ }else{
532
+ currentFixtureDoc = {
533
+ ...currentFixtureDoc,
534
+ ...data,
535
+ productBrandName:[...productBrandName],
536
+ productCategory:[...productCategory],
537
+ productSubCategory:[...productSubCategory]
538
+ }
539
+ }
540
+
541
+ delete currentFixtureDoc._id
542
+
543
+
544
+ await storeFixtureService.updateOne({ _id: new mongoose.Types.ObjectId(fixtureId) }, currentFixtureDoc);
545
+
546
+ if (data?.shelfConfig?.length) {
547
+ await fixtureShelfService.deleteMany({ fixtureId: new mongoose.Types.ObjectId(fixtureId) })
548
+
549
+
550
+ data.shelfConfig.forEach(async (shelf) => {
551
+ delete shelf?._id
552
+ const additionalMeta = {
553
+ clientId: currentFixture.clientId,
554
+ storeId: currentFixture.storeId,
555
+ storeName: currentFixture.storeName,
556
+ planoId: currentFixture.planoId,
557
+ floorId: currentFixture.floorId,
558
+ fixtureId: currentFixture._id,
559
+ }
560
+
561
+ await fixtureShelfService.create({ ...additionalMeta, ...shelf });
562
+ });
563
+
564
+ }
565
+
566
+ res.sendSuccess('Updated Successfully');
567
+ } catch (e) {
568
+ logger.error({ functionName: 'updateStoreFixture', error: e });
569
+ return res.sendError(e, 500);
509
570
  }
510
571
  }
572
+