tango-app-api-store-zone 3.0.0-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/.eslintrc.cjs +42 -0
- package/README.md +29 -0
- package/index.js +7 -0
- package/package.json +37 -0
- package/src/controllers/zoneTagging.controller.js +352 -0
- package/src/docs/zoneTagging.docs.js +9 -0
- package/src/dtos/validation.dtos.js +82 -0
- package/src/routes/zoneTagging.routes.js +20 -0
- package/src/services/camera.service.js +17 -0
- package/src/services/customTagging.service.js +17 -0
- package/src/services/tagging.service.js +30 -0
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = {
|
|
3
|
+
'env': {
|
|
4
|
+
'es2021': true,
|
|
5
|
+
'node': true,
|
|
6
|
+
},
|
|
7
|
+
'extends': 'google',
|
|
8
|
+
'overrides': [
|
|
9
|
+
{
|
|
10
|
+
'env': {
|
|
11
|
+
'node': true,
|
|
12
|
+
},
|
|
13
|
+
'files': [
|
|
14
|
+
'.eslintrc.{js,cjs}',
|
|
15
|
+
],
|
|
16
|
+
'parserOptions': {
|
|
17
|
+
'sourceType': 'script',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
'parserOptions': {
|
|
22
|
+
'ecmaVersion': 'latest',
|
|
23
|
+
'sourceType': 'module',
|
|
24
|
+
},
|
|
25
|
+
'rules': {
|
|
26
|
+
'linebreak-style': [ 'error', 'windows' ],
|
|
27
|
+
'require-jsdoc': 'off',
|
|
28
|
+
'arrow-spacing': 'error',
|
|
29
|
+
'key-spacing': [ 'error', { 'beforeColon': false, 'afterColon': true } ],
|
|
30
|
+
'object-curly-spacing': [ 'error', 'always' ],
|
|
31
|
+
'space-in-parens': [ 'error', 'always' ],
|
|
32
|
+
'keyword-spacing': 'error',
|
|
33
|
+
'array-bracket-spacing': [ 'error', 'always' ],
|
|
34
|
+
'spaced-comment': [ 'error', 'always' ],
|
|
35
|
+
'max-len': [ 'error', { 'code': 700 } ],
|
|
36
|
+
'no-unused-vars': 'error',
|
|
37
|
+
'new-cap': [ 'error', { 'newIsCap': true, 'capIsNew': false } ],
|
|
38
|
+
'prefer-const': 'off',
|
|
39
|
+
'no-console': 'error',
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# README #
|
|
2
|
+
|
|
3
|
+
This README would normally document whatever steps are necessary to get your application up and running.
|
|
4
|
+
|
|
5
|
+
### What is this repository for? ###
|
|
6
|
+
|
|
7
|
+
* Quick summary
|
|
8
|
+
* Version
|
|
9
|
+
* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
|
|
10
|
+
|
|
11
|
+
### How do I get set up? ###
|
|
12
|
+
|
|
13
|
+
* Summary of set up
|
|
14
|
+
* Configuration
|
|
15
|
+
* Dependencies
|
|
16
|
+
* Database configuration
|
|
17
|
+
* How to run tests
|
|
18
|
+
* Deployment instructions
|
|
19
|
+
|
|
20
|
+
### Contribution guidelines ###
|
|
21
|
+
|
|
22
|
+
* Writing tests
|
|
23
|
+
* Code review
|
|
24
|
+
* Other guidelines
|
|
25
|
+
|
|
26
|
+
### Who do I talk to? ###
|
|
27
|
+
|
|
28
|
+
* Repo owner or admin
|
|
29
|
+
* Other community or team contact
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tango-app-api-store-zone",
|
|
3
|
+
"version": "3.0.0-dev",
|
|
4
|
+
"description": "zone",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"start": "nodemon --exec \"eslint --fix . && node index.js\""
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=18.10.0"
|
|
12
|
+
},
|
|
13
|
+
"author": "praveenraj",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"aws-sdk": "^2.1607.0",
|
|
17
|
+
"dotenv": "^16.4.5",
|
|
18
|
+
"express": "^4.19.2",
|
|
19
|
+
"handlebars": "^4.7.8",
|
|
20
|
+
"joi-to-swagger": "^6.2.0",
|
|
21
|
+
"mongodb": "^6.5.0",
|
|
22
|
+
"nodemon": "^3.1.0",
|
|
23
|
+
"swagger-ui-express": "^5.0.0",
|
|
24
|
+
"tango-api-schema": "^2.0.76",
|
|
25
|
+
"tango-app-api-middleware": "^1.0.54-dev",
|
|
26
|
+
"winston": "^3.13.0",
|
|
27
|
+
"winston-daily-rotate-file": "^5.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"eslint": "^8.57.0",
|
|
31
|
+
"eslint-config-google": "^0.14.0",
|
|
32
|
+
"eslint-config-semistandard": "^17.0.0",
|
|
33
|
+
"eslint-config-standard": "^17.1.0",
|
|
34
|
+
"eslint-plugin-import": "^2.29.1",
|
|
35
|
+
"eslint-plugin-promise": "^6.1.1"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { logger } from 'tango-app-api-middleware';
|
|
2
|
+
import * as cameraService from '../services/camera.service.js';
|
|
3
|
+
import * as taggingService from '../services/tagging.service.js';
|
|
4
|
+
import { appConfig, signedUrl, listFileByPath } from 'tango-app-api-middleware';
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
export const addCustomTag = async ( req, res ) => {
|
|
7
|
+
try {
|
|
8
|
+
let inputData = req.body;
|
|
9
|
+
let taggingDetails = await taggingService.findOne( { clientId: inputData.clientId, storeId: inputData.storeId, tagName: inputData.tagName } );
|
|
10
|
+
if ( !taggingDetails ) {
|
|
11
|
+
let data = {
|
|
12
|
+
clientId: inputData.clientId,
|
|
13
|
+
storeId: inputData.storeId,
|
|
14
|
+
tagName: inputData.tagName,
|
|
15
|
+
};
|
|
16
|
+
await taggingService.create( data );
|
|
17
|
+
}
|
|
18
|
+
logger.info( 'Tag Created Successfully' );
|
|
19
|
+
return res.sendSuccess( 'Tag Created Successfully' );
|
|
20
|
+
} catch ( e ) {
|
|
21
|
+
logger.error( { error: 'e', function: 'addCustomTag' } );
|
|
22
|
+
return res.sendError( e, 500 );
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const customTagList = async ( req, res ) => {
|
|
27
|
+
try {
|
|
28
|
+
let customTagList = [];
|
|
29
|
+
let defaultZone = [ 'Entry', 'Exit', 'Billing', 'Excluded Area' ];
|
|
30
|
+
customTagList.push( ...defaultZone );
|
|
31
|
+
let tagInfo = await taggingService.find( { clientId: req.query.clientId }, { tagName: 1 } );
|
|
32
|
+
if ( tagInfo.length ) {
|
|
33
|
+
tagInfo.forEach( ( item ) => {
|
|
34
|
+
if ( !customTagList.includes( item.tagName ) ) {
|
|
35
|
+
customTagList.push( item.tagName );
|
|
36
|
+
}
|
|
37
|
+
} );
|
|
38
|
+
}
|
|
39
|
+
let query = [
|
|
40
|
+
{
|
|
41
|
+
$match: {
|
|
42
|
+
clientId: req.query.clientId,
|
|
43
|
+
storeId: req.query.storeId,
|
|
44
|
+
coordinates: { $exists: true, $ne: [] },
|
|
45
|
+
tagName: { $in: customTagList },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
$group: {
|
|
50
|
+
_id: '$tagName',
|
|
51
|
+
count: { $sum: 1 },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
$project: {
|
|
56
|
+
tagName: '$_id',
|
|
57
|
+
count: 1,
|
|
58
|
+
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
let taggingDetails = await taggingService.aggregate( query );
|
|
63
|
+
customTagList = customTagList.map( ( item ) => {
|
|
64
|
+
let count = '';
|
|
65
|
+
if ( taggingDetails.length ) {
|
|
66
|
+
let tagCount = taggingDetails.find( ( tag ) => tag._id == item );
|
|
67
|
+
if ( tagCount ) {
|
|
68
|
+
count = tagCount.count;
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
count = 'New';
|
|
72
|
+
}
|
|
73
|
+
return { tagName: item, count: count };
|
|
74
|
+
} );
|
|
75
|
+
return res.sendSuccess( customTagList );
|
|
76
|
+
} catch ( e ) {
|
|
77
|
+
logger.error( { error: e, function: 'customTagList' } );
|
|
78
|
+
return res.sendError( e, 500 );
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const tagging = async ( req, res ) => {
|
|
83
|
+
try {
|
|
84
|
+
let InputData = req.body;
|
|
85
|
+
if ( !InputData?.coordinates?.length ) {
|
|
86
|
+
return res.sendError( 'Tagging is Required', 400 );
|
|
87
|
+
}
|
|
88
|
+
let taggingDetails = await taggingService.findOne( { clientId: InputData.clientId, storeId: InputData.storeId, cameraId: InputData.cameraId, tagName: InputData.tagName } );
|
|
89
|
+
if ( !taggingDetails ) {
|
|
90
|
+
await taggingService.create( InputData );
|
|
91
|
+
} else {
|
|
92
|
+
taggingDetails.cameraId = InputData.cameraId;
|
|
93
|
+
taggingDetails.streamName = InputData.streamName;
|
|
94
|
+
taggingDetails.coordinates.push( InputData.coordinates[0] );
|
|
95
|
+
taggingDetails.save();
|
|
96
|
+
}
|
|
97
|
+
// if ( data?._id ) {
|
|
98
|
+
// let camDetails = await cameraService.findOne( { _id: InputData.cameraId } );
|
|
99
|
+
// if ( camDetails ) {
|
|
100
|
+
// if ( camDetails?.tagging ) {
|
|
101
|
+
// if ( !camDetails.tagging.includes( data._id ) ) {
|
|
102
|
+
// camDetails.tagging.push( data._id );
|
|
103
|
+
// }
|
|
104
|
+
// } else {
|
|
105
|
+
// camDetails = {
|
|
106
|
+
// ...camDetails,
|
|
107
|
+
// tagging: [ data._id ],
|
|
108
|
+
// };
|
|
109
|
+
// }
|
|
110
|
+
// camDetails.save();
|
|
111
|
+
// }
|
|
112
|
+
// }
|
|
113
|
+
return res.sendSuccess( 'Tagging Created Successfully' );
|
|
114
|
+
} catch ( e ) {
|
|
115
|
+
logger.error( { error: e, function: 'tagging' } );
|
|
116
|
+
return res.sendError( e, 500 );
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const getCameraList = async ( req, res ) => {
|
|
121
|
+
try {
|
|
122
|
+
let cameraDetails = await cameraService.find( { clientId: req.query.clientId, storeId: req.query.storeId, isActivated: true, isUp: true }, { cameraNumber: 1, streamName: 1 } );
|
|
123
|
+
if ( !cameraDetails.length ) {
|
|
124
|
+
return res.sendError( 'no data found', 204 );
|
|
125
|
+
}
|
|
126
|
+
const folderPath = { file_path: `${req.query.storeId}/zone_base_images/`,
|
|
127
|
+
Bucket: appConfig.cloud.aws.bucket.baseImage, MaxKeys: 1000,
|
|
128
|
+
};
|
|
129
|
+
let fileList = await listFileByPath( folderPath );
|
|
130
|
+
const TaggedfolderPath = { file_path: `${req.query.storeId}/zone_tagged_image/`,
|
|
131
|
+
Bucket: appConfig.cloud.aws.bucket.baseImage, MaxKeys: 1000,
|
|
132
|
+
};
|
|
133
|
+
let tagFileList = await listFileByPath( TaggedfolderPath );
|
|
134
|
+
for ( let [ index, camera ] of cameraDetails.entries() ) {
|
|
135
|
+
let tagList = [];
|
|
136
|
+
let tagPath;
|
|
137
|
+
let imgPath;
|
|
138
|
+
camera = {
|
|
139
|
+
...camera._doc,
|
|
140
|
+
baseImg: '',
|
|
141
|
+
tagImg: '',
|
|
142
|
+
};
|
|
143
|
+
let taggingDetails = await taggingService.find( { cameraId: camera._id, streamName: camera.streamName }, { tagName: 1, coordinates: 1 } );
|
|
144
|
+
if ( taggingDetails.length ) {
|
|
145
|
+
tagList = taggingDetails.map( ( item ) => {
|
|
146
|
+
return { tagName: item.tagName, color: item.coordinates[0].color };
|
|
147
|
+
} );
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if ( tagFileList.data.length ) {
|
|
151
|
+
tagFileList.data.forEach( ( item ) => {
|
|
152
|
+
if ( item.Key.length > 1 ) {
|
|
153
|
+
let splitStream = item.Key.split( '/' );
|
|
154
|
+
let getStream = splitStream[splitStream.length -1].split( '.' );
|
|
155
|
+
|
|
156
|
+
if ( getStream && getStream[0] == `${req.query.storeId}_${camera.streamName}` ) {
|
|
157
|
+
tagPath = item.Key;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} );
|
|
161
|
+
}
|
|
162
|
+
if ( fileList?.data.length ) {
|
|
163
|
+
fileList.data.forEach( ( ele ) => {
|
|
164
|
+
let splitStream = ele.Key.split( '/' );
|
|
165
|
+
let getStream = splitStream[splitStream.length -1].split( '.' );
|
|
166
|
+
if ( getStream && getStream[0] == `${req.query.storeId}_${camera.streamName}` ) {
|
|
167
|
+
imgPath = ele.Key;
|
|
168
|
+
}
|
|
169
|
+
} );
|
|
170
|
+
}
|
|
171
|
+
if ( tagPath ) {
|
|
172
|
+
const params = { file_path: tagPath,
|
|
173
|
+
Bucket: appConfig.cloud.aws.bucket.baseImage,
|
|
174
|
+
};
|
|
175
|
+
const cameraTagImage = await signedUrl( params );
|
|
176
|
+
camera.tagImg = cameraTagImage;
|
|
177
|
+
}
|
|
178
|
+
if ( imgPath ) {
|
|
179
|
+
const baseParams = { file_path: imgPath,
|
|
180
|
+
Bucket: appConfig.cloud.aws.bucket.baseImage,
|
|
181
|
+
};
|
|
182
|
+
const cameraBaseImage = await signedUrl( baseParams );
|
|
183
|
+
camera.baseImg = cameraBaseImage;
|
|
184
|
+
}
|
|
185
|
+
camera.tagging = tagList;
|
|
186
|
+
cameraDetails[index] = camera;
|
|
187
|
+
}
|
|
188
|
+
return res.sendSuccess( cameraDetails );
|
|
189
|
+
} catch ( e ) {
|
|
190
|
+
logger.error( { error: e, function: 'getCameraList' } );
|
|
191
|
+
return res.sendError( e, 500 );
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export const updateTag = async ( req, res ) => {
|
|
196
|
+
try {
|
|
197
|
+
let taggingDetails = await taggingService.findOne( { clientId: req.body.clientId } );
|
|
198
|
+
if ( !taggingDetails ) {
|
|
199
|
+
return res.sendError( 'no data found', 204 );
|
|
200
|
+
}
|
|
201
|
+
let tagUpdate = await taggingService.updateMany( { clientId: req.body.clientId, tagName: req.body.existTag }, { tagName: req.body.tagName } );
|
|
202
|
+
if ( tagUpdate.modifiedCount ) {
|
|
203
|
+
logger.info( 'Custom Tag Updated Successfully' );
|
|
204
|
+
return res.sendSuccess( 'Custom Tag Updated Successfully' );
|
|
205
|
+
}
|
|
206
|
+
logger.error( { error: 'something went wrong', function: 'updateTag' } );
|
|
207
|
+
return res.sendError( 'something went wrong', 500 );
|
|
208
|
+
} catch ( e ) {
|
|
209
|
+
logger.error( { error: e, function: 'updateTag' } );
|
|
210
|
+
return res.sendError( e, 500 );
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
export const deleteTag = async ( req, res ) => {
|
|
215
|
+
try {
|
|
216
|
+
let taggingDetails = await taggingService.find( { clientId: req.body.clientId, tagName: req.body.tagName } );
|
|
217
|
+
if ( !taggingDetails.length ) {
|
|
218
|
+
return res.sendError( 'no data found', 204 );
|
|
219
|
+
}
|
|
220
|
+
// let cameraList = taggingDetails.map( ( item ) => item.cameraId );
|
|
221
|
+
// let tagList = taggingDetails.map( ( item ) => item._id );
|
|
222
|
+
// console.log( cameraList );
|
|
223
|
+
// console.log( tagList );
|
|
224
|
+
// await cameraService.updateMany( { _id: { $in: cameraList } }, { $pull: { tagging: { $in: tagList } } } );
|
|
225
|
+
await taggingService.deleteMany( { clientId: req.body.clientId, tagName: req.body.tagName } );
|
|
226
|
+
return res.sendSuccess( 'Tag Deleted Successfully' );
|
|
227
|
+
} catch ( e ) {
|
|
228
|
+
logger.error( { error: e, function: 'deleteTag' } );
|
|
229
|
+
return res.sendError( e, 500 );
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export const getCameraTagging = async ( req, res ) => {
|
|
234
|
+
try {
|
|
235
|
+
let camDetails = await cameraService.findOne( { _id: req.query.cameraId } );
|
|
236
|
+
let query;
|
|
237
|
+
let details;
|
|
238
|
+
if ( !camDetails ) {
|
|
239
|
+
return res.sendError( 'no data found', 204 );
|
|
240
|
+
}
|
|
241
|
+
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 };
|
|
246
|
+
}
|
|
247
|
+
let taggingDetails = await taggingService.find( query );
|
|
248
|
+
if ( taggingDetails.length ) {
|
|
249
|
+
let coordinates = [];
|
|
250
|
+
details = {
|
|
251
|
+
...camDetails._doc,
|
|
252
|
+
coordinate: coordinates,
|
|
253
|
+
};
|
|
254
|
+
taggingDetails.forEach( ( item ) => {
|
|
255
|
+
if ( item?.coordinates.length ) {
|
|
256
|
+
item.coordinates.forEach( ( coor ) => {
|
|
257
|
+
details.coordinate.push( coor );
|
|
258
|
+
} );
|
|
259
|
+
}
|
|
260
|
+
} );
|
|
261
|
+
}
|
|
262
|
+
} else {
|
|
263
|
+
details = {
|
|
264
|
+
...camDetails._doc,
|
|
265
|
+
coordinate: [],
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if ( !details?.coordinate?.length ) {
|
|
270
|
+
let getColor = await taggingService.findOne( { tagName: req.query.tagName } );
|
|
271
|
+
if ( getColor && getColor.coordinates.length ) {
|
|
272
|
+
return res.sendSuccess( { ...camDetails._doc, coordinate: [], color: getColor.coordinates[0].color, rgbBorderColor: getColor.coordinates[0].rgbBorderColor } );
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return res.sendSuccess( details );
|
|
276
|
+
} catch ( e ) {
|
|
277
|
+
logger.error( { error: e, function: 'getCameraTagging' } );
|
|
278
|
+
return res.sendError( e, 500 );
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
export const getZoneList = async ( req, res ) => {
|
|
283
|
+
try {
|
|
284
|
+
let taggingDetails = await taggingService.find( { tagName: req.query.tagName, storeId: { $ne: req.query.storeId } } );
|
|
285
|
+
if ( taggingDetails ) {
|
|
286
|
+
return res.sendSuccess( true );
|
|
287
|
+
}
|
|
288
|
+
return res.sendSuccess( false );
|
|
289
|
+
} catch ( e ) {
|
|
290
|
+
logger.error( { error: e, function: 'getZoneList' } );
|
|
291
|
+
return res.sendError( e, 500 );
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
async function getCamTaggingDetails( req, res ) {
|
|
296
|
+
try {
|
|
297
|
+
let camDetails = await cameraService.find( { storeId: req.body.storeId, isActivated: true, isUp: true } );
|
|
298
|
+
if ( !camDetails.length ) {
|
|
299
|
+
return res.sendError( 'no data found', 204 );
|
|
300
|
+
}
|
|
301
|
+
let result = [];
|
|
302
|
+
for ( let camera of camDetails ) {
|
|
303
|
+
let taggingDetails = await taggingService.find( { cameraId: camera._id, streamName: camera.streamName, storeId: req.body.storeId } );
|
|
304
|
+
let zoneList = [];
|
|
305
|
+
if ( taggingDetails.length ) {
|
|
306
|
+
taggingDetails.forEach( ( zone ) => {
|
|
307
|
+
zone.coordinates.forEach( ( coor ) => {
|
|
308
|
+
let colorString = coor.color.replace( 'rgba(', '' ).replace( ')', '' );
|
|
309
|
+
let rgbaColorArray = colorString.split( ',' ).map( ( value ) => parseFloat( value.trim() ) );
|
|
310
|
+
let borderColorString = coor.rgbBorderColor.replace( 'rgb(', '' ).replace( ')', '' );
|
|
311
|
+
let rgbBorderColorArray = borderColorString.split( ',' ).map( ( value ) => parseFloat( value.trim() ) );
|
|
312
|
+
coor.color = rgbaColorArray;
|
|
313
|
+
coor.rgbBorderColor = rgbBorderColorArray;
|
|
314
|
+
} );
|
|
315
|
+
zoneList.push( {
|
|
316
|
+
zoneName: zone.tagName,
|
|
317
|
+
coordinates: zone.coordinates,
|
|
318
|
+
} );
|
|
319
|
+
} );
|
|
320
|
+
result.push( {
|
|
321
|
+
stream_id: camera.streamName,
|
|
322
|
+
zones: zoneList,
|
|
323
|
+
totalZone: zoneList.length,
|
|
324
|
+
storeId: req.body.storeId,
|
|
325
|
+
} );
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return result;
|
|
330
|
+
} catch ( e ) {
|
|
331
|
+
logger.error( { error: e, function: 'getCamTaggingDetails' } );
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
export const updatezoneTagging = async ( req, res ) => {
|
|
337
|
+
try {
|
|
338
|
+
let camDetails = await getCamTaggingDetails( req, res );
|
|
339
|
+
if ( !camDetails ) {
|
|
340
|
+
return res.sendError( 'Something Went Wrong', 500 );
|
|
341
|
+
}
|
|
342
|
+
const response = await axios.post( appConfig.url.lamdaUrl, camDetails );
|
|
343
|
+
if ( response?.data?.status && response?.data?.status == 'success' ) {
|
|
344
|
+
return res.sendSuccess( 'Zone Updated Successfully' );
|
|
345
|
+
} else {
|
|
346
|
+
return res.sendError( 'Something went wrong', 500 );
|
|
347
|
+
}
|
|
348
|
+
} catch ( e ) {
|
|
349
|
+
logger.error( { error: e, function: 'getCamTaggingDetails' } );
|
|
350
|
+
return res.sendError( e, 500 );
|
|
351
|
+
}
|
|
352
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import joi from 'joi';
|
|
2
|
+
|
|
3
|
+
export const addTagSchema = joi.object( {
|
|
4
|
+
clientId: joi.string().required(),
|
|
5
|
+
tagName: joi.string().required(),
|
|
6
|
+
storeId: joi.string().required(),
|
|
7
|
+
} );
|
|
8
|
+
|
|
9
|
+
export const validateAddTagParams = {
|
|
10
|
+
body: addTagSchema,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const tagSchema = joi.object( {
|
|
14
|
+
clientId: joi.string().required(),
|
|
15
|
+
storeId: joi.string().required(),
|
|
16
|
+
} );
|
|
17
|
+
|
|
18
|
+
export const validateTagParams = {
|
|
19
|
+
query: tagSchema,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const validateUpdateTagSchema = joi.object( {
|
|
23
|
+
clientId: joi.string().required(),
|
|
24
|
+
// storeId: joi.string().required(),
|
|
25
|
+
existTag: joi.string().required(),
|
|
26
|
+
tagName: joi.string().required(),
|
|
27
|
+
} );
|
|
28
|
+
|
|
29
|
+
export const validateUpdateTagParams = {
|
|
30
|
+
body: validateUpdateTagSchema,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
export const validateDeleteTagSchema = joi.object( {
|
|
35
|
+
tagName: joi.string().required(),
|
|
36
|
+
clientId: joi.string().required(),
|
|
37
|
+
storeId: joi.string().required(),
|
|
38
|
+
} );
|
|
39
|
+
|
|
40
|
+
export const validateDeleteTagParams = {
|
|
41
|
+
body: validateDeleteTagSchema,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const validateTaggingSchema = joi.object( {
|
|
45
|
+
clientId: joi.string().required(),
|
|
46
|
+
storeId: joi.string().required(),
|
|
47
|
+
cameraId: joi.string().required(),
|
|
48
|
+
tagName: joi.string().required(),
|
|
49
|
+
coordinates: joi.array().required(),
|
|
50
|
+
streamName: joi.string().required(),
|
|
51
|
+
} );
|
|
52
|
+
|
|
53
|
+
export const validateTaggingParams = {
|
|
54
|
+
body: validateTaggingSchema,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const validateCameraTagSchema = joi.object( {
|
|
58
|
+
cameraId: joi.string().required(),
|
|
59
|
+
tagName: joi.string().optional().empty(),
|
|
60
|
+
storeId: joi.string().required(),
|
|
61
|
+
} );
|
|
62
|
+
|
|
63
|
+
export const validateCameraTagParams = {
|
|
64
|
+
query: validateCameraTagSchema,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const validateZonetagSchema = joi.object( {
|
|
68
|
+
tagName: joi.string().required(),
|
|
69
|
+
storeId: joi.string().optional().empty(),
|
|
70
|
+
} );
|
|
71
|
+
|
|
72
|
+
export const validateZonetagParams = {
|
|
73
|
+
query: validateZonetagSchema,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const validateCamZonetagSchema= joi.object( {
|
|
77
|
+
storeId: joi.string().required(),
|
|
78
|
+
} );
|
|
79
|
+
|
|
80
|
+
export const validateCamZonetagParams = {
|
|
81
|
+
body: validateCamZonetagSchema,
|
|
82
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import express from 'express';
|
|
4
|
+
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
5
|
+
import * as validation from '../dtos/validation.dtos.js';
|
|
6
|
+
import * as tagController from '../controllers/zoneTagging.controller.js';
|
|
7
|
+
|
|
8
|
+
export const zoneTaggingRouter = express.Router();
|
|
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
|
+
|
|
20
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import model from 'tango-api-schema';
|
|
2
|
+
|
|
3
|
+
export const find = async ( query ={}, record = {} ) => {
|
|
4
|
+
return await model.cameraModel.find( query, record ).collation( { locale: 'en_US', numericOrdering: true } ).sort( { cameraNumber: 1 } );
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const updateOne = async ( query ={}, record = {} ) => {
|
|
8
|
+
return await model.cameraModel.updateOne( query, record );
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const findOne = async ( query ={}, record = {} ) => {
|
|
12
|
+
return await model.cameraModel.findOne( query, record );
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const updateMany = async ( query ={}, record = {} ) => {
|
|
16
|
+
return await model.cameraModel.updateMany( query, record );
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import model from 'tango-api-schema';
|
|
2
|
+
|
|
3
|
+
export const findOne = async ( query = {}, record = {} ) => {
|
|
4
|
+
return await model.customTagModel.findOne( query, record );
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const create = async ( data ) => {
|
|
8
|
+
return await model.customTagModel.create( data );
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const updateOne = async ( query = {}, record = {} ) => {
|
|
12
|
+
return await model.customTagModel.updateOne( query, { $set: record }, { upsert: true } );
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const updateArrayElement = async ( query = {}, record = {}, filter = {} ) => {
|
|
16
|
+
return await model.customTagModel.updateOne( query, record, filter );
|
|
17
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import model from 'tango-api-schema';
|
|
2
|
+
|
|
3
|
+
export const findOne = async ( query ={}, record = {} ) => {
|
|
4
|
+
return await model.taggingModel.findOne( query, record );
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const find = async ( query ={}, record = {} ) => {
|
|
8
|
+
return await model.taggingModel.find( query, record );
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const aggregate = async ( query ={}, record = {} ) => {
|
|
12
|
+
return await model.taggingModel.aggregate( query );
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const deleteMany = async ( query = {} ) => {
|
|
16
|
+
return await model.taggingModel.deleteMany( query );
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const insertMany = async ( data = [] ) => {
|
|
20
|
+
return await model.taggingModel.insertMany( data );
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const updateMany = async ( query = {}, record ={} ) => {
|
|
24
|
+
return await model.taggingModel.updateMany( query, record );
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const create = async ( data = [] ) => {
|
|
28
|
+
return await model.taggingModel.create( data );
|
|
29
|
+
};
|
|
30
|
+
|