tango-app-api-store-zone 3.0.4-dev → 3.0.6-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.6-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.69-dev",
|
|
26
26
|
"winston": "^3.13.0",
|
|
27
27
|
"winston-daily-rotate-file": "^5.0.0"
|
|
28
28
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
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 } from 'tango-app-api-middleware';
|
|
4
|
+
import { appConfig, signedUrl, listFileByPath, fileUpload } from 'tango-app-api-middleware';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
export const addCustomTag = async ( req, res ) => {
|
|
7
7
|
try {
|
|
@@ -92,9 +92,19 @@ export const tagging = async ( req, res ) => {
|
|
|
92
92
|
} else {
|
|
93
93
|
taggingDetails.cameraId = InputData.cameraId;
|
|
94
94
|
taggingDetails.streamName = InputData.streamName;
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
if ( req.body?.redoPoint ) {
|
|
96
|
+
taggingDetails.coordinates = InputData.coordinates[0];
|
|
97
|
+
taggingDetails.save();
|
|
98
|
+
} else {
|
|
99
|
+
if ( InputData.coordinates[0].coor.length ) {
|
|
100
|
+
taggingDetails.coordinates.push( InputData.coordinates[0] );
|
|
101
|
+
taggingDetails.save();
|
|
102
|
+
} else {
|
|
103
|
+
return res.sendError( 'coordinate is required', 500 );
|
|
104
|
+
}
|
|
105
|
+
}
|
|
97
106
|
}
|
|
107
|
+
await updatezoneTagging( req, res );
|
|
98
108
|
// if ( data?._id ) {
|
|
99
109
|
// let camDetails = await cameraService.findOne( { _id: InputData.cameraId } );
|
|
100
110
|
// if ( camDetails ) {
|
|
@@ -111,7 +121,7 @@ export const tagging = async ( req, res ) => {
|
|
|
111
121
|
// camDetails.save();
|
|
112
122
|
// }
|
|
113
123
|
// }
|
|
114
|
-
return res.sendSuccess( 'Tagging Created Successfully' );
|
|
124
|
+
// return res.sendSuccess( 'Tagging Created Successfully' );
|
|
115
125
|
} catch ( e ) {
|
|
116
126
|
logger.error( { error: e, function: 'tagging' } );
|
|
117
127
|
return res.sendError( e, 500 );
|
|
@@ -129,7 +139,7 @@ export const getCameraList = async ( req, res ) => {
|
|
|
129
139
|
};
|
|
130
140
|
let fileList = await listFileByPath( folderPath );
|
|
131
141
|
const TaggedfolderPath = { file_path: `${req.query.storeId}/zone_tagged_image/`,
|
|
132
|
-
Bucket: appConfig.cloud.aws.bucket.
|
|
142
|
+
Bucket: appConfig.cloud.aws.bucket.zoneTaggingImage, MaxKeys: 1000,
|
|
133
143
|
};
|
|
134
144
|
let tagFileList = await listFileByPath( TaggedfolderPath );
|
|
135
145
|
for ( let [ index, camera ] of cameraDetails.entries() ) {
|
|
@@ -141,10 +151,12 @@ export const getCameraList = async ( req, res ) => {
|
|
|
141
151
|
baseImg: '',
|
|
142
152
|
tagImg: '',
|
|
143
153
|
};
|
|
144
|
-
let taggingDetails = await taggingService.find( { cameraId: camera._id, streamName: camera.streamName }, { tagName: 1, coordinates: 1 } );
|
|
154
|
+
let taggingDetails = await taggingService.find( { cameraId: camera._id, streamName: camera.streamName, clientId: req.query.clientId }, { tagName: 1, coordinates: 1 } );
|
|
145
155
|
if ( taggingDetails.length ) {
|
|
146
156
|
tagList = taggingDetails.map( ( item ) => {
|
|
147
|
-
|
|
157
|
+
if ( item.coordinates.length ) {
|
|
158
|
+
return { tagName: item.tagName, color: item.coordinates[0].color };
|
|
159
|
+
}
|
|
148
160
|
} );
|
|
149
161
|
}
|
|
150
162
|
|
|
@@ -171,7 +183,7 @@ export const getCameraList = async ( req, res ) => {
|
|
|
171
183
|
}
|
|
172
184
|
if ( tagPath ) {
|
|
173
185
|
const params = { file_path: tagPath,
|
|
174
|
-
Bucket: appConfig.cloud.aws.bucket.
|
|
186
|
+
Bucket: appConfig.cloud.aws.bucket.zoneTaggingImage,
|
|
175
187
|
};
|
|
176
188
|
const cameraTagImage = await signedUrl( params );
|
|
177
189
|
camera.tagImg = cameraTagImage;
|
|
@@ -224,7 +236,8 @@ export const deleteTag = async ( req, res ) => {
|
|
|
224
236
|
// console.log( tagList );
|
|
225
237
|
// await cameraService.updateMany( { _id: { $in: cameraList } }, { $pull: { tagging: { $in: tagList } } } );
|
|
226
238
|
await taggingService.deleteMany( { clientId: req.body.clientId, tagName: req.body.tagName } );
|
|
227
|
-
|
|
239
|
+
await updatezoneTagging( req, res );
|
|
240
|
+
// return res.sendSuccess( 'Tag Deleted Successfully' );
|
|
228
241
|
} catch ( e ) {
|
|
229
242
|
logger.error( { error: e, function: 'deleteTag' } );
|
|
230
243
|
return res.sendError( e, 500 );
|
|
@@ -240,11 +253,13 @@ export const getCameraTagging = async ( req, res ) => {
|
|
|
240
253
|
return res.sendError( 'no data found', 204 );
|
|
241
254
|
}
|
|
242
255
|
if ( camDetails ) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
query = { cameraId: camDetails._id, streamName: camDetails.streamName, storeId: req.query.storeId };
|
|
256
|
+
query = { clientId: req.query.clientId, cameraId: camDetails._id, streamName: camDetails.streamName, storeId: req.query.storeId };
|
|
257
|
+
if ( req.query?.tagName != 'undefined' && req.query?.tagName != '' ) {
|
|
258
|
+
query.tagName = req.query.tagName;
|
|
247
259
|
}
|
|
260
|
+
// else {
|
|
261
|
+
// query = { clientId: req.query.clientId, cameraId: camDetails._id, streamName: camDetails.streamName, storeId: req.query.storeId };
|
|
262
|
+
// }
|
|
248
263
|
let taggingDetails = await taggingService.find( query );
|
|
249
264
|
if ( taggingDetails.length ) {
|
|
250
265
|
let coordinates = [];
|
|
@@ -301,7 +316,7 @@ async function getCamTaggingDetails( req, res ) {
|
|
|
301
316
|
}
|
|
302
317
|
let result = [];
|
|
303
318
|
for ( let camera of camDetails ) {
|
|
304
|
-
let taggingDetails = await taggingService.find( { cameraId: camera._id, streamName: camera.streamName, storeId: req.body.storeId } );
|
|
319
|
+
let taggingDetails = await taggingService.find( { cameraId: camera._id, streamName: camera.streamName, storeId: req.body.storeId, clientId: camera.clientId } );
|
|
305
320
|
let zoneList = [];
|
|
306
321
|
if ( taggingDetails.length ) {
|
|
307
322
|
taggingDetails.forEach( ( zone ) => {
|
|
@@ -318,13 +333,16 @@ async function getCamTaggingDetails( req, res ) {
|
|
|
318
333
|
coordinates: zone.coordinates,
|
|
319
334
|
} );
|
|
320
335
|
} );
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
zones: zoneList,
|
|
324
|
-
totalZone: zoneList.length,
|
|
325
|
-
storeId: req.body.storeId,
|
|
326
|
-
} );
|
|
336
|
+
} else {
|
|
337
|
+
zoneList = [];
|
|
327
338
|
}
|
|
339
|
+
result.push( {
|
|
340
|
+
stream_id: camera.streamName,
|
|
341
|
+
zones: zoneList,
|
|
342
|
+
// totalZone: zoneList.length,
|
|
343
|
+
storeId: req.body.storeId,
|
|
344
|
+
bucketName: appConfig.cloud.aws.bucket.zoneTaggingImage,
|
|
345
|
+
} );
|
|
328
346
|
}
|
|
329
347
|
|
|
330
348
|
return result;
|
|
@@ -342,7 +360,19 @@ export const updatezoneTagging = async ( req, res ) => {
|
|
|
342
360
|
}
|
|
343
361
|
const response = await axios.post( appConfig.url.zoneTaggingLamdaUrl, camDetails );
|
|
344
362
|
if ( response?.data?.status && response?.data?.status == 'success' ) {
|
|
345
|
-
|
|
363
|
+
let fileData = {
|
|
364
|
+
Key: `${req.body.storeId}/zonetagging/`,
|
|
365
|
+
fileName: `${req.body.storeId}_zonetagging.json`,
|
|
366
|
+
Bucket: appConfig.cloud.aws.bucket.zoneTaggingImage,
|
|
367
|
+
body: JSON.stringify( camDetails ),
|
|
368
|
+
ContentType: 'application/json',
|
|
369
|
+
};
|
|
370
|
+
let upload = await fileUpload( fileData );
|
|
371
|
+
if ( upload.Key ) {
|
|
372
|
+
return res.sendSuccess( 'Zone Updated Successfully' );
|
|
373
|
+
} else {
|
|
374
|
+
return res.sendError( 'something went wrong', 500 );
|
|
375
|
+
}
|
|
346
376
|
} else {
|
|
347
377
|
return res.sendError( 'Something went wrong', 500 );
|
|
348
378
|
}
|
|
@@ -351,3 +381,47 @@ export const updatezoneTagging = async ( req, res ) => {
|
|
|
351
381
|
return res.sendError( e, 500 );
|
|
352
382
|
}
|
|
353
383
|
};
|
|
384
|
+
|
|
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
|
+
export const updateOldData = async ( req, res ) => {
|
|
403
|
+
try {
|
|
404
|
+
let tagDetails = await taggingService.find( {}, { storeId: 1 } );
|
|
405
|
+
if ( tagDetails.length ) {
|
|
406
|
+
for ( let [ index, item ] of tagDetails.entries() ) {
|
|
407
|
+
req.body.storeId = item.storeId;
|
|
408
|
+
let camDetails = await getCamTaggingDetails( req, res );
|
|
409
|
+
if ( !camDetails ) {
|
|
410
|
+
logger.error( { message: 'no data', store: item.storeId } );
|
|
411
|
+
}
|
|
412
|
+
const response = await axios.post( appConfig.url.zoneTaggingLamdaUrl, camDetails );
|
|
413
|
+
if ( response?.data?.status && response?.data?.status == 'success' ) {
|
|
414
|
+
if ( index == tagDetails.length-1 ) {
|
|
415
|
+
return res.sendSuccess( 'Zone Updated Successfully' );
|
|
416
|
+
}
|
|
417
|
+
} else {
|
|
418
|
+
logger.error( { message: 'no data', store: item.storeId } );
|
|
419
|
+
return res.sendError( 'something went wrong', 500 );
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
} catch ( e ) {
|
|
424
|
+
logger.error( { error: e, function: 'updateOldData' } );
|
|
425
|
+
return res.sendError( e, 500 );
|
|
426
|
+
}
|
|
427
|
+
};
|
|
@@ -48,6 +48,7 @@ export const validateTaggingSchema = joi.object( {
|
|
|
48
48
|
tagName: joi.string().required(),
|
|
49
49
|
coordinates: joi.array().required(),
|
|
50
50
|
streamName: joi.string().required(),
|
|
51
|
+
redoPoint: joi.boolean().optional(),
|
|
51
52
|
} );
|
|
52
53
|
|
|
53
54
|
export const validateTaggingParams = {
|
|
@@ -55,8 +56,9 @@ export const validateTaggingParams = {
|
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
export const validateCameraTagSchema = joi.object( {
|
|
59
|
+
clientId: joi.string().required(),
|
|
58
60
|
cameraId: joi.string().required(),
|
|
59
|
-
tagName: joi.string().optional().
|
|
61
|
+
tagName: joi.string().optional().allow( '' ),
|
|
60
62
|
storeId: joi.string().required(),
|
|
61
63
|
} );
|
|
62
64
|
|
|
@@ -66,7 +68,7 @@ export const validateCameraTagParams = {
|
|
|
66
68
|
|
|
67
69
|
export const validateZonetagSchema = joi.object( {
|
|
68
70
|
tagName: joi.string().required(),
|
|
69
|
-
storeId: joi.string().optional().
|
|
71
|
+
storeId: joi.string().optional().allow( '' ),
|
|
70
72
|
} );
|
|
71
73
|
|
|
72
74
|
export const validateZonetagParams = {
|
|
@@ -80,3 +82,15 @@ export const validateCamZonetagSchema= joi.object( {
|
|
|
80
82
|
export const validateCamZonetagParams = {
|
|
81
83
|
body: validateCamZonetagSchema,
|
|
82
84
|
};
|
|
85
|
+
|
|
86
|
+
export const updateCoordinatesSchema= joi.object( {
|
|
87
|
+
storeId: joi.string().required(),
|
|
88
|
+
cameraId: joi.string().required(),
|
|
89
|
+
clientId: joi.string().required(),
|
|
90
|
+
streamName: joi.string().required(),
|
|
91
|
+
tagName: joi.string().required(),
|
|
92
|
+
} );
|
|
93
|
+
|
|
94
|
+
export const updateCoordinatesParams = {
|
|
95
|
+
body: updateCoordinatesSchema,
|
|
96
|
+
};
|
|
@@ -16,5 +16,7 @@ zoneTaggingRouter.post( '/deleteCustomTag', isAllowedSessionHandler, validate( v
|
|
|
16
16
|
zoneTaggingRouter.get( '/getCameraTagging', isAllowedSessionHandler, validate( validation.validateCameraTagParams ), tagController.getCameraTagging );
|
|
17
17
|
zoneTaggingRouter.get( '/getZoneTagging', isAllowedSessionHandler, validate( validation.validateZonetagParams ), tagController.getZoneList );
|
|
18
18
|
zoneTaggingRouter.post( '/updatezoneTagging', isAllowedSessionHandler, validate( validation.validateCamZonetagParams ), tagController.updatezoneTagging );
|
|
19
|
+
// zoneTaggingRouter.post( '/updateCoordinates', isAllowedSessionHandler, validate( validation.updateCoordinatesParams ), tagController.updateCoordinates );
|
|
20
|
+
zoneTaggingRouter.get( '/updateOldZone', tagController.updateOldData );
|
|
19
21
|
|
|
20
22
|
|