tango-app-api-store-zone 3.1.6 → 3.1.7
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.1.
|
|
3
|
+
"version": "3.1.7",
|
|
4
4
|
"description": "zone",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -21,8 +21,8 @@
|
|
|
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.
|
|
25
|
-
"tango-app-api-middleware": "^3.1.
|
|
24
|
+
"tango-api-schema": "^2.0.115",
|
|
25
|
+
"tango-app-api-middleware": "^3.1.19",
|
|
26
26
|
"winston": "^3.13.0",
|
|
27
27
|
"winston-daily-rotate-file": "^5.0.0"
|
|
28
28
|
},
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
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
|
-
import
|
|
4
|
+
import * as storeService from '../services/store.service.js';
|
|
5
|
+
import * as clientService from '../services/client.service.js';
|
|
6
|
+
import { signedUrl, listFileByPath, fileUpload, insertOpenSearchData } from 'tango-app-api-middleware';
|
|
5
7
|
import axios from 'axios';
|
|
6
8
|
export const addCustomTag = async ( req, res ) => {
|
|
7
9
|
try {
|
|
@@ -29,7 +31,7 @@ export const addCustomTag = async ( req, res ) => {
|
|
|
29
31
|
eventType: '',
|
|
30
32
|
showTo: [ 'client', 'tango' ],
|
|
31
33
|
};
|
|
32
|
-
insertOpenSearchData(
|
|
34
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH )?.activityLog, logObj );
|
|
33
35
|
return res.sendSuccess( 'Tag Created Successfully' );
|
|
34
36
|
} catch ( e ) {
|
|
35
37
|
logger.error( { error: 'e', function: 'addCustomTag' } );
|
|
@@ -39,9 +41,18 @@ export const addCustomTag = async ( req, res ) => {
|
|
|
39
41
|
|
|
40
42
|
export const customTagList = async ( req, res ) => {
|
|
41
43
|
try {
|
|
42
|
-
let customTagList = [];
|
|
43
|
-
let
|
|
44
|
-
|
|
44
|
+
let customTagList = [ 'Front', 'Back' ];
|
|
45
|
+
let storeDetails = await storeService.findOne( { storeId: req.query.storeId }, { product: 1 } );
|
|
46
|
+
let clientDetails = await clientService.findOne( { clientId: req.query.clientId }, { featureConfigs: 1 } );
|
|
47
|
+
if ( clientDetails && clientDetails?.featureConfigs?.isExcludedArea ) {
|
|
48
|
+
customTagList.push( 'Excluded Area' );
|
|
49
|
+
}
|
|
50
|
+
if ( clientDetails && clientDetails?.featureConfigs?.isPasserByData ) {
|
|
51
|
+
customTagList.push( 'Passer By' );
|
|
52
|
+
}
|
|
53
|
+
if ( storeDetails && storeDetails?.product.includes( 'tangoZone' ) ) {
|
|
54
|
+
customTagList = customTagList.concat( [ 'Entry/Exit', 'Billing' ] );
|
|
55
|
+
}
|
|
45
56
|
let tagInfo = await taggingService.find( { clientId: req.query.clientId }, { tagName: 1 } );
|
|
46
57
|
let deletedTag = await taggingService.find( { clientId: req.query.clientId, isDeleted: true }, { storeId: 1, tagName: 1 } );
|
|
47
58
|
tagInfo = [ ...new Set( tagInfo.map( ( item ) => item.tagName ) ) ];
|
|
@@ -53,7 +64,7 @@ export const customTagList = async ( req, res ) => {
|
|
|
53
64
|
} );
|
|
54
65
|
if ( tagInfo.length ) {
|
|
55
66
|
tagInfo.forEach( ( item ) => {
|
|
56
|
-
if ( !customTagList.includes( item ) ) {
|
|
67
|
+
if ( !customTagList.includes( item ) && ![ 'Excluded Area', 'Passer By', 'Entry/Exit', 'Billing' ].includes( item ) ) {
|
|
57
68
|
customTagList.push( item );
|
|
58
69
|
}
|
|
59
70
|
} );
|
|
@@ -94,6 +105,7 @@ export const customTagList = async ( req, res ) => {
|
|
|
94
105
|
}
|
|
95
106
|
return { tagName: item, count: count };
|
|
96
107
|
} );
|
|
108
|
+
customTagList.sort( ( a, b ) => a.count > b.count ? -1 : 1 );
|
|
97
109
|
return res.sendSuccess( customTagList );
|
|
98
110
|
} catch ( e ) {
|
|
99
111
|
logger.error( { error: e, function: 'customTagList' } );
|
|
@@ -121,10 +133,10 @@ export const tagging = async ( req, res ) => {
|
|
|
121
133
|
eventType: '',
|
|
122
134
|
showTo: [ 'client', 'tango' ],
|
|
123
135
|
};
|
|
124
|
-
insertOpenSearchData(
|
|
136
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH )?.activityLog, logObj );
|
|
125
137
|
let response = await taggingService.create( InputData );
|
|
126
138
|
await taggingService.deleteOne( { clientId: InputData.clientId, storeId: InputData.storeId, cameraId: { $exists: false }, tagName: InputData.tagName } );
|
|
127
|
-
await axios.post( `${
|
|
139
|
+
await 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 } ) );
|
|
128
140
|
} else {
|
|
129
141
|
const logObj = {
|
|
130
142
|
clientId: InputData.clientId,
|
|
@@ -137,17 +149,21 @@ export const tagging = async ( req, res ) => {
|
|
|
137
149
|
changes: [ `${InputData.tagName} zone Updated tagging` ],
|
|
138
150
|
eventType: '',
|
|
139
151
|
};
|
|
140
|
-
insertOpenSearchData(
|
|
152
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH )?.activityLog, logObj );
|
|
141
153
|
taggingDetails.cameraId = InputData.cameraId;
|
|
142
154
|
taggingDetails.streamName = InputData.streamName;
|
|
143
|
-
if ( req.body?.redoPoint ) {
|
|
144
|
-
|
|
155
|
+
// if ( req.body?.redoPoint ) {
|
|
156
|
+
// taggingDetails.coordinates = InputData.coordinates[0];
|
|
157
|
+
// taggingDetails.save();
|
|
158
|
+
// }
|
|
159
|
+
if ( req.body?.redraw || req.body?.redoPoint ) {
|
|
160
|
+
taggingDetails.coordinates = InputData.coordinates;
|
|
145
161
|
taggingDetails.save();
|
|
146
162
|
} else {
|
|
147
163
|
if ( InputData.coordinates[0].coor.length ) {
|
|
148
164
|
taggingDetails.coordinates.push( InputData.coordinates[0] );
|
|
149
165
|
taggingDetails.save();
|
|
150
|
-
await axios.post( `${
|
|
166
|
+
await axios.post( `${JSON.parse( process.env.URL ).oldapidomain}/tagging/oldTaggingUpdate/${taggingDetails._id}`, taggingDetails, { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( ( res ) => {
|
|
151
167
|
logger.info( res?.data );
|
|
152
168
|
} ).catch( ( error ) => {
|
|
153
169
|
logger.error( { error: error } );
|
|
@@ -158,23 +174,6 @@ export const tagging = async ( req, res ) => {
|
|
|
158
174
|
}
|
|
159
175
|
}
|
|
160
176
|
await updatezoneTagging( req, res );
|
|
161
|
-
// if ( data?._id ) {
|
|
162
|
-
// let camDetails = await cameraService.findOne( { _id: InputData.cameraId } );
|
|
163
|
-
// if ( camDetails ) {
|
|
164
|
-
// if ( camDetails?.tagging ) {
|
|
165
|
-
// if ( !camDetails.tagging.includes( data._id ) ) {
|
|
166
|
-
// camDetails.tagging.push( data._id );
|
|
167
|
-
// }
|
|
168
|
-
// } else {
|
|
169
|
-
// camDetails = {
|
|
170
|
-
// ...camDetails,
|
|
171
|
-
// tagging: [ data._id ],
|
|
172
|
-
// };
|
|
173
|
-
// }
|
|
174
|
-
// camDetails.save();
|
|
175
|
-
// }
|
|
176
|
-
// }
|
|
177
|
-
// return res.sendSuccess( 'Tagging Created Successfully' );
|
|
178
177
|
} catch ( e ) {
|
|
179
178
|
logger.error( { error: e, function: 'tagging' } );
|
|
180
179
|
return res.sendError( e, 500 );
|
|
@@ -183,16 +182,16 @@ export const tagging = async ( req, res ) => {
|
|
|
183
182
|
|
|
184
183
|
export const getCameraList = async ( req, res ) => {
|
|
185
184
|
try {
|
|
186
|
-
let cameraDetails = await cameraService.find( { clientId: req.query.clientId, storeId: req.query.storeId,
|
|
185
|
+
let cameraDetails = await cameraService.find( { clientId: req.query.clientId, storeId: req.query.storeId }, { cameraNumber: 1, streamName: 1, isActivated: 1, isUp: 1 } );
|
|
187
186
|
if ( !cameraDetails.length ) {
|
|
188
187
|
return res.sendError( 'no data found', 204 );
|
|
189
188
|
}
|
|
190
189
|
const folderPath = { file_path: `${req.query.storeId}/zone_base_images/`,
|
|
191
|
-
Bucket:
|
|
190
|
+
Bucket: JSON.parse( process.env.BUCKET ).zoneBaseImage, MaxKeys: 1000,
|
|
192
191
|
};
|
|
193
192
|
let fileList = await listFileByPath( folderPath );
|
|
194
193
|
const TaggedfolderPath = { file_path: `${req.query.storeId}/zone_tagged_image/`,
|
|
195
|
-
Bucket:
|
|
194
|
+
Bucket: JSON.parse( process.env.BUCKET ).zoneTaggingImage, MaxKeys: 1000,
|
|
196
195
|
};
|
|
197
196
|
let tagFileList = await listFileByPath( TaggedfolderPath );
|
|
198
197
|
for ( let [ index, camera ] of cameraDetails.entries() ) {
|
|
@@ -236,14 +235,14 @@ export const getCameraList = async ( req, res ) => {
|
|
|
236
235
|
}
|
|
237
236
|
if ( tagPath ) {
|
|
238
237
|
const params = { file_path: tagPath,
|
|
239
|
-
Bucket:
|
|
238
|
+
Bucket: JSON.parse( process.env.BUCKET ).zoneTaggingImage,
|
|
240
239
|
};
|
|
241
240
|
const cameraTagImage = await signedUrl( params );
|
|
242
241
|
camera.tagImg = cameraTagImage;
|
|
243
242
|
}
|
|
244
243
|
if ( imgPath ) {
|
|
245
244
|
const baseParams = { file_path: imgPath,
|
|
246
|
-
Bucket:
|
|
245
|
+
Bucket: JSON.parse( process.env.BUCKET ).zoneBaseImage,
|
|
247
246
|
};
|
|
248
247
|
const cameraBaseImage = await signedUrl( baseParams );
|
|
249
248
|
camera.baseImg = cameraBaseImage;
|
|
@@ -265,13 +264,22 @@ export const updateTag = async ( req, res ) => {
|
|
|
265
264
|
return res.sendError( 'no data found', 204 );
|
|
266
265
|
}
|
|
267
266
|
let tagUpdate = await taggingService.updateMany( { clientId: req.body.clientId, tagName: req.body.existTag }, { tagName: req.body.tagName } );
|
|
268
|
-
|
|
269
|
-
if (
|
|
270
|
-
|
|
271
|
-
|
|
267
|
+
let taggingCoordinates = await taggingService.find( { clientId: req.body.clientId, tagName: req.body.tagName } );
|
|
268
|
+
if ( taggingCoordinates.length ) {
|
|
269
|
+
for ( let [ index, item ] of taggingCoordinates.entries() ) {
|
|
270
|
+
for ( let [ coIndex ] of item.coordinates.entries() ) {
|
|
271
|
+
taggingCoordinates[index].coordinates[coIndex].zoneName = req.body.tagName;
|
|
272
|
+
}
|
|
273
|
+
await taggingService.updateOne( { _id: item._id }, { $set: taggingCoordinates[index] } );
|
|
274
|
+
}
|
|
275
|
+
taggingCoordinates.forEach( ( item ) => {
|
|
276
|
+
item.coordinates.forEach( ( coor ) => {
|
|
277
|
+
coor.zoneName = req.body.tagName;
|
|
278
|
+
} );
|
|
279
|
+
} );
|
|
272
280
|
}
|
|
273
|
-
|
|
274
|
-
await axios.post( `${
|
|
281
|
+
taggingCoordinates.forEach( async ( item ) => {
|
|
282
|
+
await axios.post( `${JSON.parse( process.env.URL ).oldapidomain}/tagging/oldTaggingUpdate/${item._id}`, item, { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( ( res ) => {
|
|
275
283
|
logger.info( res?.data );
|
|
276
284
|
} ).catch( ( error ) => {
|
|
277
285
|
logger.error( { error: error } );
|
|
@@ -289,7 +297,11 @@ export const updateTag = async ( req, res ) => {
|
|
|
289
297
|
eventType: '',
|
|
290
298
|
showTo: [ 'client', 'tango' ],
|
|
291
299
|
};
|
|
292
|
-
insertOpenSearchData(
|
|
300
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH )?.activityLog, logObj );
|
|
301
|
+
if ( tagUpdate.modifiedCount || tagUpdate.matchedCount ) {
|
|
302
|
+
logger.info( 'Custom Tag Updated Successfully' );
|
|
303
|
+
return res.sendSuccess( 'Custom Tag Updated Successfully' );
|
|
304
|
+
}
|
|
293
305
|
logger.error( { error: 'something went wrong', function: 'updateTag' } );
|
|
294
306
|
return res.sendError( 'something went wrong', 500 );
|
|
295
307
|
} catch ( e ) {
|
|
@@ -331,7 +343,7 @@ export const deleteTag = async ( req, res ) => {
|
|
|
331
343
|
}
|
|
332
344
|
}
|
|
333
345
|
taggingDetails.forEach( async ( item ) => {
|
|
334
|
-
await axios.post( `${
|
|
346
|
+
await axios.post( `${JSON.parse( process.env.URL ).oldapidomain}/tagging/oldTaggingDelete/${item._id}`, '', { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( ( res ) => {
|
|
335
347
|
logger.info( res?.data );
|
|
336
348
|
} ).catch( ( error ) => {
|
|
337
349
|
logger.error( { error: error } );
|
|
@@ -349,7 +361,7 @@ export const deleteTag = async ( req, res ) => {
|
|
|
349
361
|
eventType: '',
|
|
350
362
|
showTo: [ 'client', 'tango' ],
|
|
351
363
|
};
|
|
352
|
-
insertOpenSearchData(
|
|
364
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH )?.activityLog, logObj );
|
|
353
365
|
await updatezoneTagging( req, res );
|
|
354
366
|
// return res.sendSuccess( 'Tag Deleted Successfully' );
|
|
355
367
|
} catch ( e ) {
|
|
@@ -455,7 +467,7 @@ async function getCamTaggingDetails( req, res ) {
|
|
|
455
467
|
zones: zoneList,
|
|
456
468
|
// totalZone: zoneList.length,
|
|
457
469
|
storeId: req.body.storeId,
|
|
458
|
-
bucketName:
|
|
470
|
+
bucketName: JSON.parse( process.env.BUCKET ).zoneTaggingImage,
|
|
459
471
|
} );
|
|
460
472
|
}
|
|
461
473
|
|
|
@@ -469,15 +481,15 @@ async function getCamTaggingDetails( req, res ) {
|
|
|
469
481
|
export const updatezoneTagging = async ( req, res ) => {
|
|
470
482
|
try {
|
|
471
483
|
let camDetails = await getCamTaggingDetails( req, res );
|
|
472
|
-
if ( !camDetails ) {
|
|
484
|
+
if ( !camDetails.length ) {
|
|
473
485
|
return res.sendError( 'Something Went Wrong', 500 );
|
|
474
486
|
}
|
|
475
|
-
const response = await axios.post(
|
|
487
|
+
const response = await axios.post( JSON.parse( process.env.URL ).zoneTaggingLamdaUrl, camDetails );
|
|
476
488
|
if ( response?.data?.status && response?.data?.status == 'success' ) {
|
|
477
489
|
let fileData = {
|
|
478
490
|
Key: `${req.body.storeId}/zonetagging/`,
|
|
479
491
|
fileName: `${req.body.storeId}_zonetagging.json`,
|
|
480
|
-
Bucket:
|
|
492
|
+
Bucket: JSON.parse( process.env.BUCKET ).zoneTaggingImage,
|
|
481
493
|
body: JSON.stringify( camDetails ),
|
|
482
494
|
ContentType: 'application/json',
|
|
483
495
|
};
|
|
@@ -506,12 +518,12 @@ export const updateOldData = async ( req, res ) => {
|
|
|
506
518
|
if ( !camDetails ) {
|
|
507
519
|
logger.error( { message: 'no data', store: item.storeId } );
|
|
508
520
|
}
|
|
509
|
-
const response = await axios.post(
|
|
521
|
+
const response = await axios.post( JSON.parse( process.env.URL ).zoneTaggingLamdaUrl, camDetails );
|
|
510
522
|
if ( response?.data?.status && response?.data?.status == 'success' ) {
|
|
511
523
|
let fileData = {
|
|
512
524
|
Key: `${req.body.storeId}/zonetagging/`,
|
|
513
525
|
fileName: `${req.body.storeId}_zonetagging.json`,
|
|
514
|
-
Bucket:
|
|
526
|
+
Bucket: JSON.parse( process.env.BUCKET ).zoneTaggingImage,
|
|
515
527
|
body: JSON.stringify( camDetails ),
|
|
516
528
|
ContentType: 'application/json',
|
|
517
529
|
};
|
|
@@ -532,4 +544,4 @@ export const updateOldData = async ( req, res ) => {
|
|
|
532
544
|
logger.error( { error: e, function: 'updateOldData' } );
|
|
533
545
|
return res.sendError( e, 500 );
|
|
534
546
|
}
|
|
535
|
-
};
|
|
547
|
+
};
|