tango-app-api-store-zone 3.0.3-dev → 3.0.5-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-dev",
3
+ "version": "3.0.5-dev",
4
4
  "description": "zone",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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 {
@@ -88,12 +88,23 @@ export const tagging = async ( req, res ) => {
88
88
  let taggingDetails = await taggingService.findOne( { clientId: InputData.clientId, storeId: InputData.storeId, cameraId: InputData.cameraId, tagName: InputData.tagName } );
89
89
  if ( !taggingDetails ) {
90
90
  await taggingService.create( InputData );
91
+ await taggingService.deleteOne( { clientId: InputData.clientId, storeId: InputData.storeId, cameraId: { $exists: false }, tagName: InputData.tagName } );
91
92
  } else {
92
93
  taggingDetails.cameraId = InputData.cameraId;
93
94
  taggingDetails.streamName = InputData.streamName;
94
- taggingDetails.coordinates.push( InputData.coordinates[0] );
95
- taggingDetails.save();
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
+ }
96
106
  }
107
+ await updatezoneTagging( req, res );
97
108
  // if ( data?._id ) {
98
109
  // let camDetails = await cameraService.findOne( { _id: InputData.cameraId } );
99
110
  // if ( camDetails ) {
@@ -110,7 +121,7 @@ export const tagging = async ( req, res ) => {
110
121
  // camDetails.save();
111
122
  // }
112
123
  // }
113
- return res.sendSuccess( 'Tagging Created Successfully' );
124
+ // return res.sendSuccess( 'Tagging Created Successfully' );
114
125
  } catch ( e ) {
115
126
  logger.error( { error: e, function: 'tagging' } );
116
127
  return res.sendError( e, 500 );
@@ -128,7 +139,7 @@ export const getCameraList = async ( req, res ) => {
128
139
  };
129
140
  let fileList = await listFileByPath( folderPath );
130
141
  const TaggedfolderPath = { file_path: `${req.query.storeId}/zone_tagged_image/`,
131
- Bucket: appConfig.cloud.aws.bucket.zoneBaseImage, MaxKeys: 1000,
142
+ Bucket: appConfig.cloud.aws.bucket.zoneTaggingImage, MaxKeys: 1000,
132
143
  };
133
144
  let tagFileList = await listFileByPath( TaggedfolderPath );
134
145
  for ( let [ index, camera ] of cameraDetails.entries() ) {
@@ -140,10 +151,12 @@ export const getCameraList = async ( req, res ) => {
140
151
  baseImg: '',
141
152
  tagImg: '',
142
153
  };
143
- 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 } );
144
155
  if ( taggingDetails.length ) {
145
156
  tagList = taggingDetails.map( ( item ) => {
146
- return { tagName: item.tagName, color: item.coordinates[0].color };
157
+ if ( item.coordinates.length ) {
158
+ return { tagName: item.tagName, color: item.coordinates[0].color };
159
+ }
147
160
  } );
148
161
  }
149
162
 
@@ -170,7 +183,7 @@ export const getCameraList = async ( req, res ) => {
170
183
  }
171
184
  if ( tagPath ) {
172
185
  const params = { file_path: tagPath,
173
- Bucket: appConfig.cloud.aws.bucket.zoneBaseImage,
186
+ Bucket: appConfig.cloud.aws.bucket.zoneTaggingImage,
174
187
  };
175
188
  const cameraTagImage = await signedUrl( params );
176
189
  camera.tagImg = cameraTagImage;
@@ -223,7 +236,8 @@ export const deleteTag = async ( req, res ) => {
223
236
  // console.log( tagList );
224
237
  // await cameraService.updateMany( { _id: { $in: cameraList } }, { $pull: { tagging: { $in: tagList } } } );
225
238
  await taggingService.deleteMany( { clientId: req.body.clientId, tagName: req.body.tagName } );
226
- return res.sendSuccess( 'Tag Deleted Successfully' );
239
+ await updatezoneTagging( req, res );
240
+ // return res.sendSuccess( 'Tag Deleted Successfully' );
227
241
  } catch ( e ) {
228
242
  logger.error( { error: e, function: 'deleteTag' } );
229
243
  return res.sendError( e, 500 );
@@ -239,11 +253,13 @@ export const getCameraTagging = async ( req, res ) => {
239
253
  return res.sendError( 'no data found', 204 );
240
254
  }
241
255
  if ( camDetails ) {
242
- if ( req.query?.tagName != 'undefined' ) {
243
- query = { tagName: req.query.tagName, storeId: req.query.storeId, cameraId: camDetails._id, streamName: camDetails.streamName };
244
- } else {
245
- 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;
246
259
  }
260
+ // else {
261
+ // query = { clientId: req.query.clientId, cameraId: camDetails._id, streamName: camDetails.streamName, storeId: req.query.storeId };
262
+ // }
247
263
  let taggingDetails = await taggingService.find( query );
248
264
  if ( taggingDetails.length ) {
249
265
  let coordinates = [];
@@ -300,7 +316,7 @@ async function getCamTaggingDetails( req, res ) {
300
316
  }
301
317
  let result = [];
302
318
  for ( let camera of camDetails ) {
303
- 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 } );
304
320
  let zoneList = [];
305
321
  if ( taggingDetails.length ) {
306
322
  taggingDetails.forEach( ( zone ) => {
@@ -317,13 +333,16 @@ async function getCamTaggingDetails( req, res ) {
317
333
  coordinates: zone.coordinates,
318
334
  } );
319
335
  } );
320
- result.push( {
321
- stream_id: camera.streamName,
322
- zones: zoneList,
323
- totalZone: zoneList.length,
324
- storeId: req.body.storeId,
325
- } );
336
+ } else {
337
+ zoneList = [];
326
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
+ } );
327
346
  }
328
347
 
329
348
  return result;
@@ -341,7 +360,19 @@ export const updatezoneTagging = async ( req, res ) => {
341
360
  }
342
361
  const response = await axios.post( appConfig.url.zoneTaggingLamdaUrl, camDetails );
343
362
  if ( response?.data?.status && response?.data?.status == 'success' ) {
344
- return res.sendSuccess( 'Zone Updated Successfully' );
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
+ }
345
376
  } else {
346
377
  return res.sendError( 'Something went wrong', 500 );
347
378
  }
@@ -350,3 +381,47 @@ export const updatezoneTagging = async ( req, res ) => {
350
381
  return res.sendError( e, 500 );
351
382
  }
352
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().empty(),
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().empty(),
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
 
@@ -16,6 +16,10 @@ export const deleteMany = async ( query = {} ) => {
16
16
  return await model.taggingModel.deleteMany( query );
17
17
  };
18
18
 
19
+ export const deleteOne = async ( query = {} ) => {
20
+ return await model.taggingModel.deleteOne( query );
21
+ };
22
+
19
23
  export const insertMany = async ( data = [] ) => {
20
24
  return await model.taggingModel.insertMany( data );
21
25
  };
@@ -24,6 +28,10 @@ export const updateMany = async ( query = {}, record ={} ) => {
24
28
  return await model.taggingModel.updateMany( query, record );
25
29
  };
26
30
 
31
+ export const updateOne = async ( query = {}, record ={} ) => {
32
+ return await model.taggingModel.updateOne( query, record );
33
+ };
34
+
27
35
  export const create = async ( data = [] ) => {
28
36
  return await model.taggingModel.create( data );
29
37
  };