tango-app-api-store-zone 3.0.6-dev → 3.0.7-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.
|
|
3
|
+
"version": "3.0.7-dev",
|
|
4
4
|
"description": "zone",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"nodemon": "^3.1.0",
|
|
23
23
|
"swagger-ui-express": "^5.0.0",
|
|
24
24
|
"tango-api-schema": "^2.0.99",
|
|
25
|
-
"tango-app-api-middleware": "^1.0.
|
|
25
|
+
"tango-app-api-middleware": "^1.0.70-test",
|
|
26
26
|
"winston": "^3.13.0",
|
|
27
27
|
"winston-daily-rotate-file": "^5.0.0"
|
|
28
28
|
},
|
|
@@ -1,21 +1,34 @@
|
|
|
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 { appConfig, signedUrl, listFileByPath, fileUpload } from 'tango-app-api-middleware';
|
|
4
|
+
import { appConfig, signedUrl, listFileByPath, fileUpload, insertOpenSearchData } from 'tango-app-api-middleware';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
export const addCustomTag = async ( req, res ) => {
|
|
7
7
|
try {
|
|
8
8
|
let inputData = req.body;
|
|
9
|
-
let taggingDetails = await taggingService.findOne( { clientId: inputData.clientId, storeId: inputData.storeId, tagName: inputData.tagName } );
|
|
9
|
+
let taggingDetails = await taggingService.findOne( { clientId: inputData.clientId, storeId: inputData.storeId, tagName: inputData.tagName, isDeleted: false } );
|
|
10
10
|
if ( !taggingDetails ) {
|
|
11
11
|
let data = {
|
|
12
12
|
clientId: inputData.clientId,
|
|
13
13
|
storeId: inputData.storeId,
|
|
14
14
|
tagName: inputData.tagName,
|
|
15
15
|
};
|
|
16
|
+
await taggingService.deleteMany( { clientId: inputData.clientId, tagName: inputData.tagName, isDeleted: true } );
|
|
16
17
|
await taggingService.create( data );
|
|
17
18
|
}
|
|
18
19
|
logger.info( 'Tag Created Successfully' );
|
|
20
|
+
const logObj = {
|
|
21
|
+
clientId: inputData.clientId,
|
|
22
|
+
storeId: inputData.storeId,
|
|
23
|
+
userName: req.user?.userName,
|
|
24
|
+
email: req.user?.email,
|
|
25
|
+
date: new Date(),
|
|
26
|
+
logType: 'add Zone',
|
|
27
|
+
logSubType: inputData.tagName,
|
|
28
|
+
changes: [ ],
|
|
29
|
+
eventType: 'add',
|
|
30
|
+
};
|
|
31
|
+
insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
19
32
|
return res.sendSuccess( 'Tag Created Successfully' );
|
|
20
33
|
} catch ( e ) {
|
|
21
34
|
logger.error( { error: 'e', function: 'addCustomTag' } );
|
|
@@ -29,6 +42,13 @@ export const customTagList = async ( req, res ) => {
|
|
|
29
42
|
let defaultZone = [ 'Entry', 'Exit', 'Billing', 'Excluded Area' ];
|
|
30
43
|
customTagList.push( ...defaultZone );
|
|
31
44
|
let tagInfo = await taggingService.find( { clientId: req.query.clientId }, { tagName: 1 } );
|
|
45
|
+
let deletedTag = await taggingService.find( { clientId: req.query.clientId, isDeleted: true }, { storeId: 1, tagName: 1 } );
|
|
46
|
+
deletedTag.forEach( ( item ) => {
|
|
47
|
+
let findTag = tagInfo.findIndex( ( tag ) => tag.tagName == item.tagName && item.storeId == req.query.storeId );
|
|
48
|
+
if ( findTag != -1 ) {
|
|
49
|
+
tagInfo.splice( findTag, 1 );
|
|
50
|
+
}
|
|
51
|
+
} );
|
|
32
52
|
if ( tagInfo.length ) {
|
|
33
53
|
tagInfo.forEach( ( item ) => {
|
|
34
54
|
if ( !customTagList.includes( item.tagName ) ) {
|
|
@@ -85,11 +105,35 @@ export const tagging = async ( req, res ) => {
|
|
|
85
105
|
if ( !InputData?.coordinates?.length ) {
|
|
86
106
|
return res.sendError( 'Tagging is Required', 400 );
|
|
87
107
|
}
|
|
88
|
-
let taggingDetails = await taggingService.findOne( { clientId: InputData.clientId, storeId: InputData.storeId, cameraId: InputData.cameraId, tagName: InputData.tagName } );
|
|
108
|
+
let taggingDetails = await taggingService.findOne( { clientId: InputData.clientId, storeId: InputData.storeId, cameraId: InputData.cameraId, tagName: InputData.tagName, isDeleted: false } );
|
|
89
109
|
if ( !taggingDetails ) {
|
|
110
|
+
const logObj = {
|
|
111
|
+
clientId: InputData.clientId,
|
|
112
|
+
storeId: InputData.storeId,
|
|
113
|
+
userName: req.user?.userName,
|
|
114
|
+
email: req.user?.email,
|
|
115
|
+
date: new Date(),
|
|
116
|
+
logType: 'add Zone Tagging',
|
|
117
|
+
logSubType: InputData.tagName,
|
|
118
|
+
changes: [ 'coordinates' ],
|
|
119
|
+
eventType: 'add Tagging',
|
|
120
|
+
};
|
|
121
|
+
insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
90
122
|
await taggingService.create( InputData );
|
|
91
123
|
await taggingService.deleteOne( { clientId: InputData.clientId, storeId: InputData.storeId, cameraId: { $exists: false }, tagName: InputData.tagName } );
|
|
92
124
|
} else {
|
|
125
|
+
const logObj = {
|
|
126
|
+
clientId: InputData.clientId,
|
|
127
|
+
storeId: InputData.storeId,
|
|
128
|
+
userName: req.user?.userName,
|
|
129
|
+
email: req.user?.email,
|
|
130
|
+
date: new Date(),
|
|
131
|
+
logType: 'add Zone Tagging',
|
|
132
|
+
logSubType: InputData.tagName,
|
|
133
|
+
changes: [ 'coordinates' ],
|
|
134
|
+
eventType: 'update Tagging',
|
|
135
|
+
};
|
|
136
|
+
insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
93
137
|
taggingDetails.cameraId = InputData.cameraId;
|
|
94
138
|
taggingDetails.streamName = InputData.streamName;
|
|
95
139
|
if ( req.body?.redoPoint ) {
|
|
@@ -207,15 +251,28 @@ export const getCameraList = async ( req, res ) => {
|
|
|
207
251
|
|
|
208
252
|
export const updateTag = async ( req, res ) => {
|
|
209
253
|
try {
|
|
210
|
-
let taggingDetails = await taggingService.findOne( { clientId: req.body.clientId } );
|
|
254
|
+
let taggingDetails = await taggingService.findOne( { clientId: req.body.clientId }, { storeId: 1 } );
|
|
211
255
|
if ( !taggingDetails ) {
|
|
212
256
|
return res.sendError( 'no data found', 204 );
|
|
213
257
|
}
|
|
214
|
-
let tagUpdate = await taggingService.updateMany( { clientId: req.body.clientId, tagName: req.body.existTag }, { tagName: req.body.tagName } );
|
|
258
|
+
let tagUpdate = await taggingService.updateMany( { clientId: req.body.clientId, tagName: req.body.existTag, isDeleted: false }, { tagName: req.body.tagName } );
|
|
259
|
+
await taggingService.deleteMany( { clientId: req.body.clientId, tagName: req.body.tagName, isDeleted: true } );
|
|
215
260
|
if ( tagUpdate.modifiedCount ) {
|
|
216
261
|
logger.info( 'Custom Tag Updated Successfully' );
|
|
217
262
|
return res.sendSuccess( 'Custom Tag Updated Successfully' );
|
|
218
263
|
}
|
|
264
|
+
const logObj = {
|
|
265
|
+
clientId: req.body.clientId,
|
|
266
|
+
storeId: taggingDetails?.storeId,
|
|
267
|
+
userName: req.user?.userName,
|
|
268
|
+
email: req.user?.email,
|
|
269
|
+
date: new Date(),
|
|
270
|
+
logType: 'add Zone Tagging',
|
|
271
|
+
logSubType: req.body.existTag,
|
|
272
|
+
changes: [ 'tagName' ],
|
|
273
|
+
eventType: 'update Custom Tag Name',
|
|
274
|
+
};
|
|
275
|
+
insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
219
276
|
logger.error( { error: 'something went wrong', function: 'updateTag' } );
|
|
220
277
|
return res.sendError( 'something went wrong', 500 );
|
|
221
278
|
} catch ( e ) {
|
|
@@ -226,16 +283,39 @@ export const updateTag = async ( req, res ) => {
|
|
|
226
283
|
|
|
227
284
|
export const deleteTag = async ( req, res ) => {
|
|
228
285
|
try {
|
|
229
|
-
let taggingDetails = await taggingService.find( { clientId: req.body.clientId, tagName: req.body.tagName } );
|
|
286
|
+
let taggingDetails = await taggingService.find( { clientId: req.body.clientId, tagName: req.body.tagName, isDeleted: false }, { storeId: 1 } );
|
|
230
287
|
if ( !taggingDetails.length ) {
|
|
231
288
|
return res.sendError( 'no data found', 204 );
|
|
232
289
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
290
|
+
let enableDelete = false;
|
|
291
|
+
if ( req.user.permission ) {
|
|
292
|
+
let permissions = req.user.permission;
|
|
293
|
+
permissions.forEach( ( permission ) => {
|
|
294
|
+
if ( permission.featureName == 'analytics' ) {
|
|
295
|
+
let product = permission.product.find( ( item ) => item.name == 'tangoZone' );
|
|
296
|
+
if ( product ) {
|
|
297
|
+
enableDelete = product.isDelete;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
} );
|
|
301
|
+
}
|
|
302
|
+
if ( req.user?.role == 'superadmin' || ( req.user?.role == 'admin' && enableDelete ) ) {
|
|
303
|
+
await taggingService.deleteMany( { clientId: req.body.clientId, tagName: req.body.tagName } );
|
|
304
|
+
} else {
|
|
305
|
+
await taggingService.updateOne( { clientId: req.body.clientId, storeId: req.body.storeId, tagName: req.body.tagName }, { isDeleted: true } );
|
|
306
|
+
}
|
|
307
|
+
const logObj = {
|
|
308
|
+
clientId: req.body?.clientId,
|
|
309
|
+
storeId: taggingDetails ? taggingDetails.map( ( item ) => item?.storeId ) : '',
|
|
310
|
+
userName: req.user?.userName,
|
|
311
|
+
email: req.user?.email,
|
|
312
|
+
date: new Date(),
|
|
313
|
+
logType: 'add Zone Tagging',
|
|
314
|
+
logSubType: req.body?.tagName,
|
|
315
|
+
changes: [ 'tagName' ],
|
|
316
|
+
eventType: 'Delete Tagging Name',
|
|
317
|
+
};
|
|
318
|
+
insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
239
319
|
await updatezoneTagging( req, res );
|
|
240
320
|
// return res.sendSuccess( 'Tag Deleted Successfully' );
|
|
241
321
|
} catch ( e ) {
|
|
@@ -382,23 +462,6 @@ export const updatezoneTagging = async ( req, res ) => {
|
|
|
382
462
|
}
|
|
383
463
|
};
|
|
384
464
|
|
|
385
|
-
// export const updateCoordinates = async ( req, res ) => {
|
|
386
|
-
// try {
|
|
387
|
-
// let taggingDetails = await taggingService.findOne( { cameraId: req.body.cameraId, streamName: req.body.streamName, storeId: req.body.storeId, clientId: req.body.clientId, tagName: req.body.tagName } );
|
|
388
|
-
// if ( !taggingDetails ) {
|
|
389
|
-
// return res.sendError( 'no data found', 204 );
|
|
390
|
-
// }
|
|
391
|
-
// taggingDetails.coordinates = [];
|
|
392
|
-
// taggingDetails.save().then( () => {
|
|
393
|
-
// return res.sendSuccess( 'coordinates updated successfully' );
|
|
394
|
-
// } );
|
|
395
|
-
// } catch ( e ) {
|
|
396
|
-
// console.log( e, 'e' );
|
|
397
|
-
// logger.error( { error: e, function: 'updateCoordinates' } );
|
|
398
|
-
// return res.sendError( e, 500 );
|
|
399
|
-
// }
|
|
400
|
-
// };
|
|
401
|
-
|
|
402
465
|
export const updateOldData = async ( req, res ) => {
|
|
403
466
|
try {
|
|
404
467
|
let tagDetails = await taggingService.find( {}, { storeId: 1 } );
|
|
@@ -411,12 +474,23 @@ export const updateOldData = async ( req, res ) => {
|
|
|
411
474
|
}
|
|
412
475
|
const response = await axios.post( appConfig.url.zoneTaggingLamdaUrl, camDetails );
|
|
413
476
|
if ( response?.data?.status && response?.data?.status == 'success' ) {
|
|
477
|
+
let fileData = {
|
|
478
|
+
Key: `${req.body.storeId}/zonetagging/`,
|
|
479
|
+
fileName: `${req.body.storeId}_zonetagging.json`,
|
|
480
|
+
Bucket: appConfig.cloud.aws.bucket.zoneTaggingImage,
|
|
481
|
+
body: JSON.stringify( camDetails ),
|
|
482
|
+
ContentType: 'application/json',
|
|
483
|
+
};
|
|
484
|
+
let upload = await fileUpload( fileData );
|
|
485
|
+
if ( !upload.Key ) {
|
|
486
|
+
logger.error( { message: `JSON Upload Error`, store: item.storeId } );
|
|
487
|
+
}
|
|
414
488
|
if ( index == tagDetails.length-1 ) {
|
|
415
489
|
return res.sendSuccess( 'Zone Updated Successfully' );
|
|
416
490
|
}
|
|
417
491
|
} else {
|
|
418
492
|
logger.error( { message: 'no data', store: item.storeId } );
|
|
419
|
-
return res.sendError( 'something went wrong', 500 );
|
|
493
|
+
// return res.sendError( 'something went wrong', 500 );
|
|
420
494
|
}
|
|
421
495
|
}
|
|
422
496
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
3
|
import express from 'express';
|
|
4
|
-
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
+
import { isAllowedSessionHandler, validate, authorize } from 'tango-app-api-middleware';
|
|
5
5
|
import * as validation from '../dtos/validation.dtos.js';
|
|
6
6
|
import * as tagController from '../controllers/zoneTagging.controller.js';
|
|
7
7
|
|
|
8
8
|
export const zoneTaggingRouter = express.Router();
|
|
9
9
|
|
|
10
|
-
zoneTaggingRouter.post( '/addCustomTag', isAllowedSessionHandler, validate( validation.validateAddTagParams ), tagController.addCustomTag );
|
|
11
|
-
zoneTaggingRouter.get( '/customTagList', isAllowedSessionHandler, validate( validation.validateTagParams ), tagController.customTagList );
|
|
12
|
-
zoneTaggingRouter.post( '/tagging', isAllowedSessionHandler, validate( validation.validateTaggingParams ), tagController.tagging );
|
|
13
|
-
zoneTaggingRouter.get( '/cameraList', isAllowedSessionHandler, validate( validation.validateTagParams ), tagController.getCameraList );
|
|
14
|
-
zoneTaggingRouter.post( '/updateCustomTag', isAllowedSessionHandler, validate( validation.validateUpdateTagParams ), tagController.updateTag );
|
|
15
|
-
zoneTaggingRouter.post( '/deleteCustomTag', isAllowedSessionHandler, validate( validation.validateDeleteTagParams ), tagController.deleteTag );
|
|
16
|
-
zoneTaggingRouter.get( '/getCameraTagging', isAllowedSessionHandler, validate( validation.validateCameraTagParams ), tagController.getCameraTagging );
|
|
17
|
-
zoneTaggingRouter.get( '/getZoneTagging', isAllowedSessionHandler, validate( validation.validateZonetagParams ), tagController.getZoneList );
|
|
18
|
-
zoneTaggingRouter.post( '/updatezoneTagging', isAllowedSessionHandler, validate( validation.validateCamZonetagParams ), tagController.updatezoneTagging );
|
|
19
|
-
|
|
10
|
+
zoneTaggingRouter.post( '/addCustomTag', isAllowedSessionHandler, authorize( { userType: [ 'tango', 'client' ], access: [ { featureName: 'analytics', name: 'tangoZone', permissions: [ 'isEdit' ] } ] } ), validate( validation.validateAddTagParams ), tagController.addCustomTag );
|
|
11
|
+
zoneTaggingRouter.get( '/customTagList', isAllowedSessionHandler, authorize( { userType: [ 'tango', 'client' ], access: [ { featureName: 'analytics', name: 'tangoZone', permissions: [ 'isView' ] } ] } ), validate( validation.validateTagParams ), tagController.customTagList );
|
|
12
|
+
zoneTaggingRouter.post( '/tagging', isAllowedSessionHandler, authorize( { userType: [ 'tango', 'client' ], access: [ { featureName: 'analytics', name: 'tangoZone', permissions: [ 'isEdit' ] } ] } ), validate( validation.validateTaggingParams ), tagController.tagging );
|
|
13
|
+
zoneTaggingRouter.get( '/cameraList', isAllowedSessionHandler, authorize( { userType: [ 'tango', 'client' ], access: [ { featureName: 'analytics', name: 'tangoZone', permissions: [ 'isView' ] } ] } ), validate( validation.validateTagParams ), tagController.getCameraList );
|
|
14
|
+
zoneTaggingRouter.post( '/updateCustomTag', isAllowedSessionHandler, authorize( { userType: [ 'tango', 'client' ], access: [ { featureName: 'analytics', name: 'tangoZone', permissions: [ 'isEdit' ] } ] } ), validate( validation.validateUpdateTagParams ), tagController.updateTag );
|
|
15
|
+
zoneTaggingRouter.post( '/deleteCustomTag', isAllowedSessionHandler, authorize( { userType: [ 'tango', 'client' ], access: [ { featureName: 'analytics', name: 'tangoZone', permissions: [ 'isDelete' ] } ] } ), validate( validation.validateDeleteTagParams ), tagController.deleteTag );
|
|
16
|
+
zoneTaggingRouter.get( '/getCameraTagging', isAllowedSessionHandler, authorize( { userType: [ 'tango', 'client' ], access: [ { featureName: 'analytics', name: 'tangoZone', permissions: [ 'isView' ] } ] } ), validate( validation.validateCameraTagParams ), tagController.getCameraTagging );
|
|
17
|
+
zoneTaggingRouter.get( '/getZoneTagging', isAllowedSessionHandler, authorize( { userType: [ 'tango', 'client' ], access: [ { featureName: 'analytics', name: 'tangoZone', permissions: [ 'isView' ] } ] } ), validate( validation.validateZonetagParams ), tagController.getZoneList );
|
|
18
|
+
zoneTaggingRouter.post( '/updatezoneTagging', isAllowedSessionHandler, authorize( { userType: [ 'tango', 'client' ], access: [ { featureName: 'analytics', name: 'tangoZone', permissions: [ 'isEdit' ] } ] } ), validate( validation.validateCamZonetagParams ), tagController.updatezoneTagging );
|
|
19
|
+
|
|
20
20
|
zoneTaggingRouter.get( '/updateOldZone', tagController.updateOldData );
|
|
21
21
|
|
|
22
22
|
|