tango-app-api-store-zone 3.0.14-dev → 3.0.15-dev

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-zone",
3
- "version": "3.0.14-dev",
3
+ "version": "3.0.15-dev",
4
4
  "description": "zone",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  "mongodb": "^6.5.0",
22
22
  "nodemon": "^3.1.0",
23
23
  "swagger-ui-express": "^5.0.0",
24
- "tango-api-schema": "^2.0.110",
24
+ "tango-api-schema": "^2.0.115",
25
25
  "tango-app-api-middleware": "^1.0.73-test",
26
26
  "winston": "^3.13.0",
27
27
  "winston-daily-rotate-file": "^5.0.0"
@@ -2,6 +2,7 @@ import { logger } from 'tango-app-api-middleware';
2
2
  import * as cameraService from '../services/camera.service.js';
3
3
  import * as taggingService from '../services/tagging.service.js';
4
4
  import * as storeService from '../services/store.service.js';
5
+ import * as clientService from '../services/client.service.js';
5
6
  import { appConfig, signedUrl, listFileByPath, fileUpload, insertOpenSearchData } from 'tango-app-api-middleware';
6
7
  import axios from 'axios';
7
8
  export const addCustomTag = async ( req, res ) => {
@@ -42,13 +43,16 @@ export const customTagList = async ( req, res ) => {
42
43
  try {
43
44
  let customTagList = [];
44
45
  let storeDetails = await storeService.findOne( { storeId: req.query.storeId }, { product: 1 } );
45
- let defaultZone;
46
+ let clientDetails = await clientService.findOne( { clientId: req.query.clientId } );
47
+ if ( clientDetails && clientDetails?.featureConfigs?.isExcludedArea ) {
48
+ customTagList.push( 'Excluded Area' );
49
+ }
50
+ if ( clientDetails && clientDetails?.featureConfigs?.isPasserByData ) {
51
+ customTagList.push( 'Passer By' );
52
+ }
46
53
  if ( storeDetails && storeDetails?.product.includes( 'tangoZone' ) ) {
47
- defaultZone = [ 'Excluded Area', 'Passer By', 'Entry/Exit', 'Billing' ];
48
- } else {
49
- defaultZone = [ 'Excluded Area', 'Passer By' ];
54
+ customTagList = customTagList.concat( [ 'Entry/Exit', 'Billing' ] );
50
55
  }
51
- customTagList.push( ...defaultZone );
52
56
  let tagInfo = await taggingService.find( { clientId: req.query.clientId }, { tagName: 1 } );
53
57
  let deletedTag = await taggingService.find( { clientId: req.query.clientId, isDeleted: true }, { storeId: 1, tagName: 1 } );
54
58
  tagInfo = [ ...new Set( tagInfo.map( ( item ) => item.tagName ) ) ];
@@ -169,23 +173,6 @@ export const tagging = async ( req, res ) => {
169
173
  }
170
174
  }
171
175
  await updatezoneTagging( req, res );
172
- // if ( data?._id ) {
173
- // let camDetails = await cameraService.findOne( { _id: InputData.cameraId } );
174
- // if ( camDetails ) {
175
- // if ( camDetails?.tagging ) {
176
- // if ( !camDetails.tagging.includes( data._id ) ) {
177
- // camDetails.tagging.push( data._id );
178
- // }
179
- // } else {
180
- // camDetails = {
181
- // ...camDetails,
182
- // tagging: [ data._id ],
183
- // };
184
- // }
185
- // camDetails.save();
186
- // }
187
- // }
188
- // return res.sendSuccess( 'Tagging Created Successfully' );
189
176
  } catch ( e ) {
190
177
  logger.error( { error: e, function: 'tagging' } );
191
178
  return res.sendError( e, 500 );
@@ -276,12 +263,21 @@ export const updateTag = async ( req, res ) => {
276
263
  return res.sendError( 'no data found', 204 );
277
264
  }
278
265
  let tagUpdate = await taggingService.updateMany( { clientId: req.body.clientId, tagName: req.body.existTag }, { tagName: req.body.tagName } );
279
- // await taggingService.deleteMany( { clientId: req.body.clientId, tagName: req.body.existTag, isDeleted: true } );
280
- if ( tagUpdate.modifiedCount ) {
281
- logger.info( 'Custom Tag Updated Successfully' );
282
- return res.sendSuccess( 'Custom Tag Updated Successfully' );
266
+ let taggingCoordinates = await taggingService.find( { clientId: req.body.clientId, tagName: req.body.tagName } );
267
+ if ( taggingCoordinates.length ) {
268
+ for ( let [ index, item ] of taggingCoordinates.entries() ) {
269
+ for ( let [ coIndex ] of item.coordinates.entries() ) {
270
+ taggingCoordinates[index].coordinates[coIndex].zoneName = req.body.tagName;
271
+ }
272
+ await taggingService.updateOne( { _id: item._id }, { $set: taggingCoordinates[index] } );
273
+ }
274
+ taggingCoordinates.forEach( ( item ) => {
275
+ item.coordinates.forEach( ( coor ) => {
276
+ coor.zoneName = req.body.tagName;
277
+ } );
278
+ } );
283
279
  }
284
- taggingDetails.forEach( async ( item ) => {
280
+ taggingCoordinates.forEach( async ( item ) => {
285
281
  await axios.post( `${appConfig.url.oldapidomain}/tagging/oldTaggingUpdate/${item._id}`, item, { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( ( res ) => {
286
282
  logger.info( res?.data );
287
283
  } ).catch( ( error ) => {
@@ -301,6 +297,10 @@ export const updateTag = async ( req, res ) => {
301
297
  showTo: [ 'client', 'tango' ],
302
298
  };
303
299
  insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
300
+ if ( tagUpdate.modifiedCount || tagUpdate.matchedCount ) {
301
+ logger.info( 'Custom Tag Updated Successfully' );
302
+ return res.sendSuccess( 'Custom Tag Updated Successfully' );
303
+ }
304
304
  logger.error( { error: 'something went wrong', function: 'updateTag' } );
305
305
  return res.sendError( 'something went wrong', 500 );
306
306
  } catch ( e ) {
@@ -543,4 +543,4 @@ export const updateOldData = async ( req, res ) => {
543
543
  logger.error( { error: e, function: 'updateOldData' } );
544
544
  return res.sendError( e, 500 );
545
545
  }
546
- };
546
+ };
@@ -0,0 +1,5 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export const findOne = async ( query = {}, record = {} ) => {
4
+ return await model.clientModel.findOne( query, record );
5
+ };