tango-app-api-store-zone 3.3.1-beta.0 → 3.3.1-beta.1

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.3.1-beta.0",
3
+ "version": "3.3.1-beta.1",
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.115",
24
+ "tango-api-schema": "^2.1.1",
25
25
  "tango-app-api-middleware": "^3.1.19",
26
26
  "winston": "^3.13.0",
27
27
  "winston-daily-rotate-file": "^5.0.0"
@@ -15,6 +15,8 @@ export const addCustomTag = async ( req, res ) => {
15
15
  clientId: inputData.clientId,
16
16
  storeId: inputData.storeId,
17
17
  tagName: inputData.tagName,
18
+ rgbColor: inputData.rgbColor,
19
+ rgbBorderColor: inputData.rgbBorderColor,
18
20
  };
19
21
  await taggingService.deleteMany( { clientId: inputData.clientId, storeId: inputData.storeId, tagName: inputData.tagName, isDeleted: true } );
20
22
  await taggingService.create( data );
@@ -54,7 +56,10 @@ export const customTagList = async ( req, res ) => {
54
56
  if ( storeDetails && storeDetails?.product.includes( 'tangoZone' ) ) {
55
57
  customTagList = customTagList.concat( [ 'Entry/Exit', 'Billing' ] );
56
58
  }
57
- let tagInfo = await taggingService.find( { clientId: req.query.clientId }, { tagName: 1 } );
59
+ let tagInfo = await taggingService.find( { clientId: req.query.clientId }, { tagName: 1, rgbColor: 1, rgbBorderColor: 1 } );
60
+
61
+ const allTags = tagInfo;
62
+
58
63
  let deletedTag = await taggingService.find( { clientId: req.query.clientId, isDeleted: true }, { storeId: 1, tagName: 1 } );
59
64
  tagInfo = [ ...new Set( tagInfo.map( ( item ) => item.tagName ) ) ];
60
65
  deletedTag.forEach( ( item ) => {
@@ -90,10 +95,13 @@ export const customTagList = async ( req, res ) => {
90
95
  tagName: '$_id',
91
96
  count: 1,
92
97
 
98
+
93
99
  },
94
100
  },
95
101
  ];
96
102
  let taggingDetails = await taggingService.aggregate( query );
103
+
104
+
97
105
  customTagList = customTagList.map( ( item ) => {
98
106
  let count = '';
99
107
  if ( taggingDetails.length ) {
@@ -107,6 +115,42 @@ export const customTagList = async ( req, res ) => {
107
115
  return { tagName: item, count: count };
108
116
  } );
109
117
  customTagList.sort( ( a, b ) => a.count > b.count ? -1 : 1 );
118
+
119
+ const allTagsMap = new Map( allTags.map( ( tag ) => [ tag.tagName, tag ] ) );
120
+
121
+ customTagList.forEach( ( i ) => {
122
+ const matchingTag = allTagsMap.get( i.tagName );
123
+ if ( matchingTag ) {
124
+ i.rgbColor = matchingTag.rgbColor;
125
+ i.rgbBorderColor = matchingTag.rgbBorderColor;
126
+ }
127
+
128
+ if ( i.tagName === 'Front' ) {
129
+ i.rgbColor = 'rgba(89, 80, 5, 0.5)';
130
+ i.rgbBorderColor = 'rgb(99, 90, 15)';
131
+ }
132
+ if ( i.tagName === 'Back' ) {
133
+ i.rgbColor = 'rgba(94, 60, 107, 0.5)';
134
+ i.rgbBorderColor = 'rgb(104, 70, 117)';
135
+ }
136
+ if ( i.tagName === 'Excluded Area' ) {
137
+ i.rgbColor = 'rgba(186, 60, 214, 0.5)';
138
+ i.rgbBorderColor = 'rgb(196, 70, 224)';
139
+ }
140
+ if ( i.tagName === 'Passer By' ) {
141
+ i.rgbColor = 'rgba(81, 153, 247, 0.5)';
142
+ i.rgbBorderColor = 'rgb(91, 163, 257)';
143
+ }
144
+ if ( i.tagName === 'Entry/Exit' ) {
145
+ i.rgbColor = 'rgba(224, 43, 170, 0.5)';
146
+ i.rgbBorderColor = 'rgb(234, 53, 180)';
147
+ }
148
+ if ( i.tagName === 'Billing' ) {
149
+ i.rgbColor = 'rgba(193, 214, 114, 0.5)';
150
+ i.rgbBorderColor = 'rgb(203, 224, 124)';
151
+ }
152
+ } );
153
+
110
154
  return res.sendSuccess( customTagList );
111
155
  } catch ( e ) {
112
156
  logger.error( { error: e, function: 'customTagList' } );
@@ -128,6 +172,8 @@ export const tagging = async ( req, res ) => {
128
172
  }
129
173
  } );
130
174
  let taggingDetails = await taggingService.findOne( { clientId: InputData.clientId, storeId: InputData.storeId, cameraId: InputData.cameraId, tagName: InputData.tagName, isDeleted: false } );
175
+
176
+ const previousTagging = await taggingService.findOne( { clientId: InputData.clientId, storeId: InputData.storeId, tagName: InputData.tagName } );
131
177
  if ( !taggingDetails ) {
132
178
  const logObj = {
133
179
  clientId: InputData.clientId,
@@ -142,6 +188,13 @@ export const tagging = async ( req, res ) => {
142
188
  showTo: [ 'client', 'tango' ],
143
189
  };
144
190
  insertOpenSearchData( JSON.parse( process.env.OPENSEARCH )?.activityLog, logObj );
191
+ if ( previousTagging?.rgbColor ) {
192
+ InputData = { ...InputData, rgbColor: previousTagging.rgbColor };
193
+ }
194
+
195
+ if ( previousTagging?.rgbBorderColor ) {
196
+ InputData = { ...InputData, rgbBorderColor: previousTagging.rgbBorderColor };
197
+ }
145
198
  let response = await taggingService.create( InputData );
146
199
  await taggingService.deleteOne( { clientId: InputData.clientId, storeId: InputData.storeId, cameraId: { $exists: false }, tagName: InputData.tagName } );
147
200
  axios.post( `${JSON.parse( process.env.URL ).oldapidomain}/tagging/oldTaggingAdd`, [ response ], { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( ( res ) => logger.info( res?.data ) ).catch( ( error ) => logger.error( { error: error } ) );
@@ -370,11 +423,14 @@ export const updateTag = async ( req, res ) => {
370
423
  };
371
424
  insertOpenSearchData( JSON.parse( process.env.OPENSEARCH )?.activityLog, logObj );
372
425
  if ( tagUpdate.modifiedCount || tagUpdate.matchedCount ) {
426
+ await externalService.updateMany( { zoneName: req.body.existTag, clientId: req.body.clientId }, { zoneName: req.body.tagName } );
373
427
  logger.info( 'Custom Tag Updated Successfully' );
374
- return res.sendSuccess( 'Custom Tag Updated Successfully' );
428
+ updateJsonFile( req, res );
429
+ res.sendSuccess( 'Custom Tag Updated Successfully' );
430
+ } else {
431
+ logger.error( { error: 'something went wrong', function: 'updateTag' } );
432
+ return res.sendError( 'something went wrong', 500 );
375
433
  }
376
- logger.error( { error: 'something went wrong', function: 'updateTag' } );
377
- return res.sendError( 'something went wrong', 500 );
378
434
  } catch ( e ) {
379
435
  logger.error( { error: e, function: 'updateTag' } );
380
436
  return res.sendError( e, 500 );
@@ -634,3 +690,29 @@ export const deletezoneTagging = async ( req, res ) => {
634
690
  await updatezoneTagging( req, res );
635
691
  } );
636
692
  };
693
+
694
+ async function updateJsonFile( req, res ) {
695
+ if ( req.body.clientId ) {
696
+ let tagDetails = await taggingService.find( { clientId: req.body.clientId, tagName: req.body.tagName }, { storeId: 1 } );
697
+ if ( tagDetails.length ) {
698
+ for ( let item of tagDetails ) {
699
+ req.body.storeId = item.storeId;
700
+ let camDetails = await getCamTaggingDetails( req, res );
701
+ if ( !camDetails ) {
702
+ logger.error( { message: 'no data', store: item.storeId } );
703
+ }
704
+ let fileData = {
705
+ Key: `${req.body.storeId}/zonetagging/`,
706
+ fileName: `${req.body.storeId}_zonetagging.json`,
707
+ Bucket: JSON.parse( process.env.BUCKET ).zoneTaggingImage,
708
+ body: JSON.stringify( camDetails ),
709
+ ContentType: 'application/json',
710
+ };
711
+ let upload = await fileUpload( fileData );
712
+ if ( !upload.Key ) {
713
+ logger.error( { message: `JSON Upload Error`, store: item.storeId } );
714
+ }
715
+ }
716
+ }
717
+ }
718
+ };
@@ -4,6 +4,8 @@ export const addTagSchema = joi.object( {
4
4
  clientId: joi.string().required(),
5
5
  tagName: joi.string().required(),
6
6
  storeId: joi.string().required(),
7
+ rgbColor: joi.string().required(),
8
+ rgbBorderColor: joi.string().required(),
7
9
  } );
8
10
 
9
11
  export const validateAddTagParams = {
@@ -17,4 +17,8 @@ export const deleteMany = async ( query = {} ) => {
17
17
  return await model.externalParameterModel.deleteMany( query );
18
18
  };
19
19
 
20
+ export const updateMany = async ( query = {}, record={} ) => {
21
+ return await model.externalParameterModel.updateMany( query, { $set: record } );
22
+ };
23
+
20
24