tango-app-api-store-builder 1.0.11-dont-user → 1.0.13

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.11-dont-user",
3
+ "version": "1.0.13",
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.5.3",
35
+ "tango-api-schema": "^2.5.11",
36
36
  "tango-app-api-middleware": "3.1.48",
37
37
  "url": "^0.11.4",
38
38
  "winston": "^3.17.0",
@@ -1,5 +1,5 @@
1
1
  import * as floorService from '../service/storeBuilder.service.js';
2
- import { logger, insertOpenSearchData, getOpenSearchData } from 'tango-app-api-middleware';
2
+ import { logger, insertOpenSearchData, getOpenSearchData, updateOpenSearchData, getOpenSearchById } from 'tango-app-api-middleware';
3
3
  // import * as storeService from '../service/store.service.js';
4
4
  import * as planoService from '../service/planogram.service.js';
5
5
  import * as storeFixtureService from '../service/storeFixture.service.js';
@@ -1012,7 +1012,10 @@ export async function updateFixtureStatus( req, res ) {
1012
1012
  await planoTaskService.updateOnefilters(
1013
1013
  { _id: new mongoose.Types.ObjectId( req.body._id ) },
1014
1014
  {
1015
- $set: { 'answers.$[ans].status': req.body.type },
1015
+ $set: {
1016
+ 'answers.$[ans].status': req.body.type,
1017
+ 'answers.$[ans].userAction': req.body.userAction
1018
+ }
1016
1019
  },
1017
1020
  [
1018
1021
  { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
@@ -1277,7 +1280,7 @@ export async function updateStoreFixture( req, res ) {
1277
1280
 
1278
1281
  const currentFixture = await storeFixtureService.findOne( { _id: new mongoose.Types.ObjectId( fixtureId ) } );
1279
1282
  let currentFixtureDoc = currentFixture.toObject();
1280
- if ( req?.body?.taskType?.includes( 'fixture' ) || data?.taskType?.includes( 'fixture' ) ) {
1283
+ if ( data?.userAction === 'editWithAi' || data?.userAction === 'acceptAi' ) {
1281
1284
  let shelfDetails = await fixtureShelfService.find( { fixtureId: fixtureId } );
1282
1285
  data.shelfConfig.forEach( ( ele ) => {
1283
1286
  let findShelfProduct = shelfDetails.find( ( shelf ) => shelf.shelfNumber == ele.shelfNumber );
@@ -1513,7 +1516,8 @@ export async function updateStoreFixture( req, res ) {
1513
1516
  } );
1514
1517
  }
1515
1518
  await planoService.updateOne( { _id: currentFixtureDoc?.planoId }, { $set: { updatedAt: new Date() } } );
1516
- if ( data?.taskType?.includes( 'fixture' ) ) {
1519
+
1520
+ if ( data?.userAction === 'editWithAi' || data?.userAction === 'editWithPlano' ) {
1517
1521
  let comments = {
1518
1522
  userId: req.user._id,
1519
1523
  userName: req.user.userName,
@@ -1521,17 +1525,25 @@ export async function updateStoreFixture( req, res ) {
1521
1525
  responsetype: 'agree',
1522
1526
  comment: '',
1523
1527
  };
1524
- await planoTaskService.updateOne( { planoId: currentFixture.planoId, floorId: currentFixture.floorId, fixtureId: currentFixture._id }, { 'answers.0.status': 'agree', 'approvalStatus': 'approved' } );
1528
+ await planoTaskService.updateOne( { planoId: currentFixture.planoId, floorId: currentFixture.floorId, fixtureId: currentFixture._id }, { 'answers.0.status': 'agree', 'approvalStatus': 'approved','answers.0.userAction': data.userAction } );
1529
+
1525
1530
  await planoTaskService.updateOnefilters(
1526
- { planoId: new mongoose.Types.ObjectId( currentFixture.planoId ), floorId: new mongoose.Types.ObjectId( currentFixture.floorId ), fixtureId: new mongoose.Types.ObjectId( currentFixture._id ) },
1527
- {
1528
- $push: { 'answers.0.comments': comments },
1529
- },
1531
+ { planoId: new mongoose.Types.ObjectId(currentFixture.planoId), floorId: new mongoose.Types.ObjectId(currentFixture.floorId), fixtureId: new mongoose.Types.ObjectId(currentFixture._id) },
1532
+ {
1533
+ $push: { 'answers.0.comments': comments },
1534
+ },
1530
1535
  );
1536
+
1531
1537
  }
1532
- if ( req.body?.editMode ) {
1533
- await floorService.updateOne( { _id: new mongoose.Types.ObjectId( currentFixture.floorId ) }, { isEdited: true } );
1538
+
1539
+ if ( data?.userAction === 'editWithAi' || data?.userAction === 'acceptAi' ) {
1540
+ const op_id = `${data?.storeName}_${data?.storeDate}_${data?._id}`
1541
+ await updateAIFeedbackInOpenSearch(data,op_id);
1534
1542
  }
1543
+
1544
+ // if ( req.body?.editMode ) {
1545
+ // await floorService.updateOne( { _id: new mongoose.Types.ObjectId( currentFixture.floorId ) }, { isEdited: true } );
1546
+ // }
1535
1547
  res.sendSuccess( { message: 'Updated Successfully', ...( configId && { id: configId } ) } );
1536
1548
  } catch ( e ) {
1537
1549
  logger.error( { functionName: 'updateStoreFixture', error: e } );
@@ -1539,6 +1551,64 @@ export async function updateStoreFixture( req, res ) {
1539
1551
  }
1540
1552
  }
1541
1553
 
1554
+ const updateAIFeedbackInOpenSearch = async (fixtureData, id) => {
1555
+
1556
+ try {
1557
+ let openSearchDetails = await getOpenSearchById(JSON.parse(process.env.OPENSEARCH).planoAIValidation, id);
1558
+ if (openSearchDetails && openSearchDetails.statusCode == 200 && openSearchDetails?.body?._source) {
1559
+
1560
+ const doc = {
1561
+ "fixtureId": fixtureData._id,
1562
+ "fixtureCapacity": fixtureData.fixtureCapacity,
1563
+ "fixtureType": fixtureData.fixtureType,
1564
+ "fixtureCategory": fixtureData.fixtureCategory,
1565
+ "header": {
1566
+ "label": fixtureData.header.label,
1567
+ },
1568
+ "vmConfig": fixtureData?.vmConfig.map(vm => {
1569
+ return {
1570
+ "vmType": vm.vmType,
1571
+ "startYPosition": vm.startYPosition,
1572
+ "endYPosition": vm.endYPosition,
1573
+ "xZone": vm.xZone,
1574
+ "yZone": vm.yZone,
1575
+ "vmImage": vm.vmImage,
1576
+ "vmName": vm.vmName,
1577
+ }
1578
+ }) ?? [
1579
+
1580
+ ],
1581
+ "shelfConfig": fixtureData?.shelfConfig.map(s => {
1582
+ return {
1583
+ "shelfNumber": s.shelfNumber,
1584
+ "shelfType": s.shelfType,
1585
+ "productPerShelf": s.productPerShelf,
1586
+ "trayRows": s.trayRows
1587
+ }
1588
+ }) ?? [],
1589
+ "fixtureImage": fixtureData.fixtureImage,
1590
+ "storeDate": fixtureData.storeDate
1591
+ }
1592
+
1593
+ const document = {
1594
+ doc: doc,
1595
+ };
1596
+
1597
+ let updateResult = await updateOpenSearchData(JSON.parse(process.env.OPENSEARCH).planoAIValidation, id, document);
1598
+
1599
+ if (updateResult?.statusCode == 200) {
1600
+ return true;
1601
+ }
1602
+ return false
1603
+ } else {
1604
+ return false
1605
+ }
1606
+ } catch (e) {
1607
+ logger.error({ error: e, function: 'updateAIFeedbackInOpenSearch' });
1608
+ return false
1609
+ }
1610
+ };
1611
+
1542
1612
  export async function updateredostatus( req, res ) {
1543
1613
  try {
1544
1614
  if ( req.body.type === 'layout' ) {