tango-app-api-store-zone 3.1.0 → 3.1.2
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 +0 -1
- package/index.js +3 -3
- package/package.json +5 -7
- package/script-new.js +388 -0
- package/src/controllers/zone.controllers.js +0 -0
- package/src/controllers/zoneTagging.controller.js +74 -40
- package/src/routes/zone.routes.js +10 -0
- package/src/docs/zoneTagging.docs.js +0 -9
package/.eslintrc.cjs
CHANGED
package/index.js
CHANGED
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.2",
|
|
4
4
|
"description": "zone",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -13,16 +13,14 @@
|
|
|
13
13
|
"author": "praveenraj",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"aws-sdk": "^2.
|
|
16
|
+
"aws-sdk": "^2.1617.0",
|
|
17
17
|
"dotenv": "^16.4.5",
|
|
18
18
|
"express": "^4.19.2",
|
|
19
|
-
"
|
|
20
|
-
"joi-to-swagger": "^6.2.0",
|
|
21
|
-
"mongodb": "^6.5.0",
|
|
19
|
+
"mongodb": "^6.6.1",
|
|
22
20
|
"nodemon": "^3.1.0",
|
|
23
21
|
"swagger-ui-express": "^5.0.0",
|
|
24
|
-
"tango-api-schema": "^2.0.
|
|
25
|
-
"tango-app-api-middleware": "^3.1.
|
|
22
|
+
"tango-api-schema": "^2.0.104",
|
|
23
|
+
"tango-app-api-middleware": "^3.1.11",
|
|
26
24
|
"winston": "^3.13.0",
|
|
27
25
|
"winston-daily-rotate-file": "^5.0.0"
|
|
28
26
|
},
|
package/script-new.js
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
const fs = require( 'fs' );
|
|
2
|
+
const path = require( 'path' );
|
|
3
|
+
const { execSync } = require( 'child_process' );
|
|
4
|
+
// Define folder structure
|
|
5
|
+
const createProjectStructure = async ( folderName ) => {
|
|
6
|
+
const folders = [
|
|
7
|
+
`src`,
|
|
8
|
+
`src/controllers`,
|
|
9
|
+
`src/routes`,
|
|
10
|
+
`config`,
|
|
11
|
+
`config/database`,
|
|
12
|
+
`config/response`,
|
|
13
|
+
`config/env`,
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
// Create folders
|
|
17
|
+
folders.forEach( ( folder ) => {
|
|
18
|
+
const folderPath = path.join( __dirname, folder );
|
|
19
|
+
fs.mkdirSync( folderPath, { recursive: true } );
|
|
20
|
+
} );
|
|
21
|
+
|
|
22
|
+
// Create index.js file
|
|
23
|
+
const indexjsContent = `
|
|
24
|
+
|
|
25
|
+
import { ${folderName}Router } from './src/routes/${folderName}.routes.js';
|
|
26
|
+
|
|
27
|
+
export { ${folderName}Router };
|
|
28
|
+
|
|
29
|
+
`;
|
|
30
|
+
fs.writeFileSync(
|
|
31
|
+
path.join( __dirname, `/`, 'index.js' ),
|
|
32
|
+
indexjsContent,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// Create app.js file
|
|
36
|
+
const appContent = `
|
|
37
|
+
import express from 'express';
|
|
38
|
+
import { ${folderName}Router } from './index.js';
|
|
39
|
+
|
|
40
|
+
import dotenv from 'dotenv';
|
|
41
|
+
import { logger } from 'tango-app-api-middleware';
|
|
42
|
+
import { connectdb } from './config/database/database.js';
|
|
43
|
+
import responseMiddleware from './config/response/response.js';
|
|
44
|
+
import errorMiddleware from './config/response/error.js';
|
|
45
|
+
import pkg from 'body-parser';
|
|
46
|
+
|
|
47
|
+
const { json, urlencoded } = pkg;
|
|
48
|
+
const env=dotenv.config();
|
|
49
|
+
|
|
50
|
+
const app = express();
|
|
51
|
+
const PORT = process.env.PORT || 3000;
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
app.use( json( { limit: '500mb' } ) );
|
|
55
|
+
app.use(
|
|
56
|
+
urlencoded( {
|
|
57
|
+
extended: true,
|
|
58
|
+
} ),
|
|
59
|
+
);
|
|
60
|
+
app.use( responseMiddleware );
|
|
61
|
+
app.use( errorMiddleware );
|
|
62
|
+
|
|
63
|
+
if ( env.error ) {
|
|
64
|
+
logger.error( '.env not found' );
|
|
65
|
+
process.exit( 1 );
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
app.use(\`/\${folderName}\', ${folderName}Router);
|
|
70
|
+
|
|
71
|
+
app.listen(PORT, () => {
|
|
72
|
+
logger.info(\`server is running on port= \${PORT} \`);
|
|
73
|
+
connectdb();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
`;
|
|
77
|
+
fs.writeFileSync(
|
|
78
|
+
path.join( __dirname, `/`, 'app.js' ),
|
|
79
|
+
appContent,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// Create route.js file
|
|
83
|
+
const appJsContent = `
|
|
84
|
+
import express from 'express';
|
|
85
|
+
|
|
86
|
+
export const ${folderName}Router = express.Router();
|
|
87
|
+
|
|
88
|
+
${folderName}Router.get('/', (req, res) => {
|
|
89
|
+
res.send('Hello, world!');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
`;
|
|
94
|
+
fs.writeFileSync(
|
|
95
|
+
path.join( __dirname, `/src/routes`, `${folderName}.routes.js` ),
|
|
96
|
+
appJsContent,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// Create package.json file
|
|
100
|
+
const packageJsonContent = `
|
|
101
|
+
{
|
|
102
|
+
"name": "${folderName}",
|
|
103
|
+
"version": "1.0.0",
|
|
104
|
+
"description": "${folderName}",
|
|
105
|
+
"main": "app.js",
|
|
106
|
+
"type": "module",
|
|
107
|
+
"scripts": {
|
|
108
|
+
"start": "nodemon --exec \\"eslint --fix . && node app.js\\""
|
|
109
|
+
},
|
|
110
|
+
"engines": {
|
|
111
|
+
"node": ">=18.10.0"
|
|
112
|
+
},
|
|
113
|
+
"author": "praveenraj",
|
|
114
|
+
"license": "ISC"
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
118
|
+
fs.writeFileSync(
|
|
119
|
+
path.join( __dirname, 'package.json' ),
|
|
120
|
+
packageJsonContent,
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
// Create .eslintrc.js file
|
|
124
|
+
const eslintrcContent = `
|
|
125
|
+
module.exports = {
|
|
126
|
+
'env': {
|
|
127
|
+
'es2021': true,
|
|
128
|
+
'node': true,
|
|
129
|
+
},
|
|
130
|
+
'extends': 'google',
|
|
131
|
+
'overrides': [
|
|
132
|
+
{
|
|
133
|
+
'env': {
|
|
134
|
+
'node': true,
|
|
135
|
+
},
|
|
136
|
+
'files': [
|
|
137
|
+
'.eslintrc.{js,cjs}',
|
|
138
|
+
],
|
|
139
|
+
'parserOptions': {
|
|
140
|
+
'sourceType': 'script',
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
'parserOptions': {
|
|
145
|
+
'ecmaVersion': 'latest',
|
|
146
|
+
'sourceType': 'module',
|
|
147
|
+
},
|
|
148
|
+
'rules': {
|
|
149
|
+
'linebreak-style': [ 'error', 'windows' ],
|
|
150
|
+
'require-jsdoc': 'off',
|
|
151
|
+
'arrow-spacing': 'error',
|
|
152
|
+
'key-spacing': [ 'error', { 'beforeColon': false, 'afterColon': true } ],
|
|
153
|
+
'object-curly-spacing': [ 'error', 'always' ],
|
|
154
|
+
'space-in-parens': [ 'error', 'always' ],
|
|
155
|
+
'keyword-spacing': 'error',
|
|
156
|
+
'array-bracket-spacing': [ 'error', 'always' ],
|
|
157
|
+
'spaced-comment': [ 'error', 'always' ],
|
|
158
|
+
'max-len': [ 'error', { 'code': 700 } ],
|
|
159
|
+
'no-unused-vars': 'error',
|
|
160
|
+
'new-cap': [ 'error', { 'newIsCap': true, 'capIsNew': false } ],
|
|
161
|
+
'prefer-const': 'off',
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
`;
|
|
166
|
+
fs.writeFileSync(
|
|
167
|
+
path.join( __dirname, '.eslintrc.cjs' ),
|
|
168
|
+
eslintrcContent,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// Create .env file
|
|
172
|
+
const envContent = `
|
|
173
|
+
PORT=3001
|
|
174
|
+
AWS_ACCESS_KEY_ID=AKIAQSSPN5BZSDAZHWB2
|
|
175
|
+
AWS_SECRET_ACCESS_KEY=WkkH2+s4mPbaM48EEHP+ZZHGdkixvNsHHAgS8rMT
|
|
176
|
+
|
|
177
|
+
mongo_username= tangoeye
|
|
178
|
+
mongo_password= SUTONQosEUijJKWC
|
|
179
|
+
|
|
180
|
+
ELASTIC_CLOUD_ID=
|
|
181
|
+
ELASTIC_USERNAME=
|
|
182
|
+
ELASTIC_PASSWORD=
|
|
183
|
+
ELASTIC_NODE=
|
|
184
|
+
|
|
185
|
+
`;
|
|
186
|
+
fs.writeFileSync( path.join( __dirname, '.env' ), envContent );
|
|
187
|
+
|
|
188
|
+
// Create database.js file
|
|
189
|
+
const databaseContent = `
|
|
190
|
+
import appConfig from '../../config/env/env.js';
|
|
191
|
+
import mongoose from 'mongoose';
|
|
192
|
+
import { logger } from 'tango-app-api-middleware';
|
|
193
|
+
|
|
194
|
+
export function getConnection() {
|
|
195
|
+
appConfig.database.mongo.username = process.env.mongo_username;
|
|
196
|
+
appConfig.database.mongo.password = process.env.mongo_password;
|
|
197
|
+
|
|
198
|
+
const options = {
|
|
199
|
+
useNewUrlParser: true,
|
|
200
|
+
useUnifiedTopology: true,
|
|
201
|
+
};
|
|
202
|
+
let connectionString;
|
|
203
|
+
|
|
204
|
+
if (appConfig.database.mongo.authSource) {
|
|
205
|
+
connectionString = \`\${appConfig.database.mongo.hostname}/\${appConfig.database.mongo.name}?\${appConfig.database.mongo.authSource}\`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (appConfig.database.mongo.username && appConfig.database.mongo.password) {
|
|
209
|
+
connectionString = \`\${appConfig.database.mongo.username}:\${appConfig.database.mongo.password}@\${appConfig.database.mongo.hostname}/\${appConfig.database.mongo.name}\`;
|
|
210
|
+
} else {
|
|
211
|
+
connectionString = \`\${appConfig.database.mongo.hostname}/\${appConfig.database.mongo.name}\`;
|
|
212
|
+
}
|
|
213
|
+
if (appConfig.database.mongo.authSource) {
|
|
214
|
+
connectionString = \`mongodb+srv://\${connectionString}\`;
|
|
215
|
+
} else {
|
|
216
|
+
connectionString = \`mongodb://\${connectionString}\`;
|
|
217
|
+
}
|
|
218
|
+
return { uri: \`\${connectionString}\`, options };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export function connectdb() {
|
|
222
|
+
const db = getConnection();
|
|
223
|
+
// Establish Connection
|
|
224
|
+
mongoose.connect(db.uri, db.options);
|
|
225
|
+
|
|
226
|
+
// Mongoose Events
|
|
227
|
+
mongoose.connection.on('connected', () => {
|
|
228
|
+
logger.info('Mongoose connected with MongoDB: ' + new Date().toISOString());
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// Event: Disconnected
|
|
232
|
+
mongoose.connection.on('disconnected', () => {
|
|
233
|
+
logger.log('MongoDB Connection Closed: ' + new Date().toISOString());
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// Event: Error
|
|
237
|
+
mongoose.connection.on('error', (error) => {
|
|
238
|
+
logger.error(error);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
`;
|
|
242
|
+
|
|
243
|
+
fs.writeFileSync(
|
|
244
|
+
path.join( __dirname, `/config/database`, `database.js` ),
|
|
245
|
+
|
|
246
|
+
databaseContent,
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
// Create logger.js file
|
|
250
|
+
// const loggerContent = `
|
|
251
|
+
// import winston from 'winston';
|
|
252
|
+
// import DailyRotateFile from 'winston-daily-rotate-file';
|
|
253
|
+
|
|
254
|
+
// export const logger = winston.createLogger( {
|
|
255
|
+
// level: 'info',
|
|
256
|
+
// format: winston.format.combine(
|
|
257
|
+
// winston.format.errors( { stack: true } ),
|
|
258
|
+
// winston.format.timestamp(),
|
|
259
|
+
// winston.format.prettyPrint(),
|
|
260
|
+
// winston.format.colorize(),
|
|
261
|
+
// ),
|
|
262
|
+
// transports: [
|
|
263
|
+
// new DailyRotateFile( {
|
|
264
|
+
// filename: \`error-%DATE%.log\`,
|
|
265
|
+
// dirname: \`storage/logs/\`,
|
|
266
|
+
// datePattern: 'YYYY-MM-DD',
|
|
267
|
+
// zippedArchive: true,
|
|
268
|
+
// maxFiles: '2d',
|
|
269
|
+
// maxSize: '2g',
|
|
270
|
+
// level: 'error',
|
|
271
|
+
// } ),
|
|
272
|
+
// new DailyRotateFile( {
|
|
273
|
+
// filename: \`application-%DATE%.log\`,
|
|
274
|
+
// dirname: \`storage/logs/\`,
|
|
275
|
+
// datePattern: 'YYYY-MM-DD',
|
|
276
|
+
// zippedArchive: true,
|
|
277
|
+
// maxFiles: '2d',
|
|
278
|
+
// maxSize: '2g',
|
|
279
|
+
// } ),
|
|
280
|
+
// ],
|
|
281
|
+
// } );
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
// `;
|
|
285
|
+
// fs.writeFileSync(
|
|
286
|
+
// path.join( __dirname, `/config/logger`, `logger.js` ),
|
|
287
|
+
|
|
288
|
+
// loggerContent,
|
|
289
|
+
// );
|
|
290
|
+
// console.log( `Folder structure for ${folderName} created successfully.` );
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
// Create database.js file
|
|
294
|
+
const envjsContent = `
|
|
295
|
+
const appConfig = {
|
|
296
|
+
app: {
|
|
297
|
+
environment: 'development',
|
|
298
|
+
},
|
|
299
|
+
api: {
|
|
300
|
+
version: [ 'v3' ],
|
|
301
|
+
},
|
|
302
|
+
url: {
|
|
303
|
+
admin: '',
|
|
304
|
+
audit: '',
|
|
305
|
+
},
|
|
306
|
+
database: {
|
|
307
|
+
mongo: {
|
|
308
|
+
hostname: 'serverlessinstance-1.o0iqto1.mongodb.net',
|
|
309
|
+
name: 'tango-api-uat',
|
|
310
|
+
},
|
|
311
|
+
postgre: {},
|
|
312
|
+
},
|
|
313
|
+
cloud: {
|
|
314
|
+
aws: {
|
|
315
|
+
region: 'ap-south-1',
|
|
316
|
+
secertManager: 'tango-api-dev',
|
|
317
|
+
sqs: {
|
|
318
|
+
url: '',
|
|
319
|
+
},
|
|
320
|
+
bucket: {
|
|
321
|
+
name: '',
|
|
322
|
+
},
|
|
323
|
+
version: 'v4',
|
|
324
|
+
},
|
|
325
|
+
elasticSearch: {
|
|
326
|
+
cloud: {
|
|
327
|
+
id: process.env.ELASTIC_CLOUD_ID,
|
|
328
|
+
},
|
|
329
|
+
auth: {
|
|
330
|
+
username: process.env.ELASTIC_USERNAME,
|
|
331
|
+
password: process.env.ELASTIC_PASSWORD,
|
|
332
|
+
},
|
|
333
|
+
// node: process.env.ELASTIC_NODE,
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
export default appConfig;
|
|
340
|
+
|
|
341
|
+
`;
|
|
342
|
+
|
|
343
|
+
fs.writeFileSync(
|
|
344
|
+
path.join( __dirname, `/config/env`, `env.js` ),
|
|
345
|
+
envjsContent,
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
// Install specific dependencies
|
|
349
|
+
console.log( 'Installing dependencies...', {
|
|
350
|
+
cwd: path.join( __dirname ),
|
|
351
|
+
} );
|
|
352
|
+
try {
|
|
353
|
+
const gitignoreContent = [
|
|
354
|
+
'node_modules/',
|
|
355
|
+
'package-lock.json',
|
|
356
|
+
'storage/',
|
|
357
|
+
'config/',
|
|
358
|
+
'app.js',
|
|
359
|
+
'.env',
|
|
360
|
+
].join( '\r\n' ); // Use Windows-style line endings
|
|
361
|
+
|
|
362
|
+
// Write content to .gitignore
|
|
363
|
+
fs.writeFileSync( path.join( __dirname, '.gitignore' ), gitignoreContent );
|
|
364
|
+
|
|
365
|
+
// Install npm dependencies
|
|
366
|
+
const npmCommand = 'npm install express mongodb aws-sdk nodemon tango-api-schema tango-app-api-middleware winston winston-daily-rotate-file dotenv';
|
|
367
|
+
execSync( npmCommand, { cwd: path.join( __dirname ), stdio: 'inherit' } );
|
|
368
|
+
|
|
369
|
+
console.log( 'Dependencies installed successfully.' );
|
|
370
|
+
} catch ( error ) {
|
|
371
|
+
console.error( 'Error occurred while installing dependencies:', error );
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// Install specific dependencies as devDependencies
|
|
375
|
+
console.log( 'Installing devDependencies...' );
|
|
376
|
+
try {
|
|
377
|
+
await execSync(
|
|
378
|
+
' npm install --save-dev eslint eslint-config-google eslint-config-semistandard eslint-config-standard eslint-plugin-import eslint-plugin-promise',
|
|
379
|
+
{ cwd: path.join( __dirname ) },
|
|
380
|
+
);
|
|
381
|
+
console.log( 'devDependencies installed successfully.' );
|
|
382
|
+
} catch ( error ) {
|
|
383
|
+
console.error( 'Error occurred while installing devDependencies:', error );
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
// Usage: node createProjectStructure.js myapi
|
|
388
|
+
createProjectStructure( process.argv[2] );
|
|
File without changes
|
|
@@ -13,7 +13,7 @@ export const addCustomTag = async ( req, res ) => {
|
|
|
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
|
+
await taggingService.deleteMany( { clientId: inputData.clientId, storeId: inputData.storeId, tagName: inputData.tagName, isDeleted: true } );
|
|
17
17
|
await taggingService.create( data );
|
|
18
18
|
}
|
|
19
19
|
logger.info( 'Tag Created Successfully' );
|
|
@@ -23,12 +23,13 @@ export const addCustomTag = async ( req, res ) => {
|
|
|
23
23
|
userName: req.user?.userName,
|
|
24
24
|
email: req.user?.email,
|
|
25
25
|
date: new Date(),
|
|
26
|
-
logType: '
|
|
27
|
-
logSubType:
|
|
28
|
-
changes: [ ],
|
|
29
|
-
eventType: '
|
|
26
|
+
logType: 'zone',
|
|
27
|
+
logSubType: 'addCustomTag',
|
|
28
|
+
changes: [ `${inputData.tagName} customtag Created.` ],
|
|
29
|
+
eventType: '',
|
|
30
|
+
showTo: [ 'client', 'tango' ],
|
|
30
31
|
};
|
|
31
|
-
insertOpenSearchData(
|
|
32
|
+
insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
|
|
32
33
|
return res.sendSuccess( 'Tag Created Successfully' );
|
|
33
34
|
} catch ( e ) {
|
|
34
35
|
logger.error( { error: 'e', function: 'addCustomTag' } );
|
|
@@ -43,16 +44,17 @@ export const customTagList = async ( req, res ) => {
|
|
|
43
44
|
customTagList.push( ...defaultZone );
|
|
44
45
|
let tagInfo = await taggingService.find( { clientId: req.query.clientId }, { tagName: 1 } );
|
|
45
46
|
let deletedTag = await taggingService.find( { clientId: req.query.clientId, isDeleted: true }, { storeId: 1, tagName: 1 } );
|
|
47
|
+
tagInfo = [ ...new Set( tagInfo.map( ( item ) => item.tagName ) ) ];
|
|
46
48
|
deletedTag.forEach( ( item ) => {
|
|
47
|
-
let findTag = tagInfo.findIndex( ( tag ) => tag
|
|
49
|
+
let findTag = tagInfo.findIndex( ( tag ) => tag == item.tagName && item.storeId == req.query.storeId );
|
|
48
50
|
if ( findTag != -1 ) {
|
|
49
51
|
tagInfo.splice( findTag, 1 );
|
|
50
52
|
}
|
|
51
53
|
} );
|
|
52
54
|
if ( tagInfo.length ) {
|
|
53
55
|
tagInfo.forEach( ( item ) => {
|
|
54
|
-
if ( !customTagList.includes( item
|
|
55
|
-
customTagList.push( item
|
|
56
|
+
if ( !customTagList.includes( item ) ) {
|
|
57
|
+
customTagList.push( item );
|
|
56
58
|
}
|
|
57
59
|
} );
|
|
58
60
|
}
|
|
@@ -113,14 +115,16 @@ export const tagging = async ( req, res ) => {
|
|
|
113
115
|
userName: req.user?.userName,
|
|
114
116
|
email: req.user?.email,
|
|
115
117
|
date: new Date(),
|
|
116
|
-
logType: '
|
|
117
|
-
logSubType:
|
|
118
|
-
changes: [
|
|
119
|
-
eventType: '
|
|
118
|
+
logType: 'zone',
|
|
119
|
+
logSubType: 'addZoneTagging',
|
|
120
|
+
changes: [ `${InputData.tagName} zone added tagging` ],
|
|
121
|
+
eventType: '',
|
|
122
|
+
showTo: [ 'client', 'tango' ],
|
|
120
123
|
};
|
|
121
|
-
insertOpenSearchData(
|
|
122
|
-
await taggingService.create( InputData );
|
|
124
|
+
insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
|
|
125
|
+
let response = await taggingService.create( InputData );
|
|
123
126
|
await taggingService.deleteOne( { clientId: InputData.clientId, storeId: InputData.storeId, cameraId: { $exists: false }, tagName: InputData.tagName } );
|
|
127
|
+
await axios.post( `${appConfig.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 } ) );
|
|
124
128
|
} else {
|
|
125
129
|
const logObj = {
|
|
126
130
|
clientId: InputData.clientId,
|
|
@@ -128,12 +132,12 @@ export const tagging = async ( req, res ) => {
|
|
|
128
132
|
userName: req.user?.userName,
|
|
129
133
|
email: req.user?.email,
|
|
130
134
|
date: new Date(),
|
|
131
|
-
logType: '
|
|
132
|
-
logSubType:
|
|
133
|
-
changes: [
|
|
134
|
-
eventType: '
|
|
135
|
+
logType: 'zone',
|
|
136
|
+
logSubType: 'updateZoneTagging',
|
|
137
|
+
changes: [ `${InputData.tagName} zone Updated tagging` ],
|
|
138
|
+
eventType: '',
|
|
135
139
|
};
|
|
136
|
-
insertOpenSearchData(
|
|
140
|
+
insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
|
|
137
141
|
taggingDetails.cameraId = InputData.cameraId;
|
|
138
142
|
taggingDetails.streamName = InputData.streamName;
|
|
139
143
|
if ( req.body?.redoPoint ) {
|
|
@@ -143,6 +147,11 @@ export const tagging = async ( req, res ) => {
|
|
|
143
147
|
if ( InputData.coordinates[0].coor.length ) {
|
|
144
148
|
taggingDetails.coordinates.push( InputData.coordinates[0] );
|
|
145
149
|
taggingDetails.save();
|
|
150
|
+
await axios.post( `${appConfig.url.oldapidomain}/tagging/oldTaggingUpdate/${taggingDetails._id}`, taggingDetails, { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( ( res ) => {
|
|
151
|
+
logger.info( res?.data );
|
|
152
|
+
} ).catch( ( error ) => {
|
|
153
|
+
logger.error( { error: error } );
|
|
154
|
+
} );
|
|
146
155
|
} else {
|
|
147
156
|
return res.sendError( 'coordinate is required', 500 );
|
|
148
157
|
}
|
|
@@ -195,7 +204,7 @@ export const getCameraList = async ( req, res ) => {
|
|
|
195
204
|
baseImg: '',
|
|
196
205
|
tagImg: '',
|
|
197
206
|
};
|
|
198
|
-
let taggingDetails = await taggingService.find( { cameraId: camera._id, streamName: camera.streamName, clientId: req.query.clientId }, { tagName: 1, coordinates: 1 } );
|
|
207
|
+
let taggingDetails = await taggingService.find( { cameraId: camera._id, streamName: camera.streamName, clientId: req.query.clientId, isDeleted: false }, { tagName: 1, coordinates: 1 } );
|
|
199
208
|
if ( taggingDetails.length ) {
|
|
200
209
|
tagList = taggingDetails.map( ( item ) => {
|
|
201
210
|
if ( item.coordinates.length ) {
|
|
@@ -255,24 +264,32 @@ export const updateTag = async ( req, res ) => {
|
|
|
255
264
|
if ( !taggingDetails ) {
|
|
256
265
|
return res.sendError( 'no data found', 204 );
|
|
257
266
|
}
|
|
258
|
-
let tagUpdate = await taggingService.updateMany( { clientId: req.body.clientId, tagName: req.body.existTag
|
|
259
|
-
await taggingService.deleteMany( { clientId: req.body.clientId, tagName: req.body.
|
|
267
|
+
let tagUpdate = await taggingService.updateMany( { clientId: req.body.clientId, tagName: req.body.existTag }, { tagName: req.body.tagName } );
|
|
268
|
+
// await taggingService.deleteMany( { clientId: req.body.clientId, tagName: req.body.existTag, isDeleted: true } );
|
|
260
269
|
if ( tagUpdate.modifiedCount ) {
|
|
261
270
|
logger.info( 'Custom Tag Updated Successfully' );
|
|
262
271
|
return res.sendSuccess( 'Custom Tag Updated Successfully' );
|
|
263
272
|
}
|
|
273
|
+
taggingDetails.forEach( async ( item ) => {
|
|
274
|
+
await axios.post( `${appConfig.url.oldapidomain}/tagging/oldTaggingUpdate/${item._id}`, item, { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( ( res ) => {
|
|
275
|
+
logger.info( res?.data );
|
|
276
|
+
} ).catch( ( error ) => {
|
|
277
|
+
logger.error( { error: error } );
|
|
278
|
+
} );
|
|
279
|
+
} );
|
|
264
280
|
const logObj = {
|
|
265
281
|
clientId: req.body.clientId,
|
|
266
282
|
storeId: taggingDetails?.storeId,
|
|
267
283
|
userName: req.user?.userName,
|
|
268
284
|
email: req.user?.email,
|
|
269
285
|
date: new Date(),
|
|
270
|
-
logType: '
|
|
271
|
-
logSubType:
|
|
272
|
-
changes: [
|
|
273
|
-
eventType: '
|
|
286
|
+
logType: 'zone',
|
|
287
|
+
logSubType: 'updateCustomTag',
|
|
288
|
+
changes: [ `${req.body.tagName} tagName Updated` ],
|
|
289
|
+
eventType: '',
|
|
290
|
+
showTo: [ 'client', 'tango' ],
|
|
274
291
|
};
|
|
275
|
-
insertOpenSearchData(
|
|
292
|
+
insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
|
|
276
293
|
logger.error( { error: 'something went wrong', function: 'updateTag' } );
|
|
277
294
|
return res.sendError( 'something went wrong', 500 );
|
|
278
295
|
} catch ( e ) {
|
|
@@ -283,7 +300,7 @@ export const updateTag = async ( req, res ) => {
|
|
|
283
300
|
|
|
284
301
|
export const deleteTag = async ( req, res ) => {
|
|
285
302
|
try {
|
|
286
|
-
let taggingDetails = await taggingService.find( { clientId: req.body.clientId, tagName: req.body.tagName
|
|
303
|
+
let taggingDetails = await taggingService.find( { clientId: req.body.clientId, tagName: req.body.tagName }, { storeId: 1 } );
|
|
287
304
|
if ( !taggingDetails.length ) {
|
|
288
305
|
return res.sendError( 'no data found', 204 );
|
|
289
306
|
}
|
|
@@ -302,20 +319,37 @@ export const deleteTag = async ( req, res ) => {
|
|
|
302
319
|
if ( req.user?.role == 'superadmin' || ( req.user?.role == 'admin' && enableDelete ) ) {
|
|
303
320
|
await taggingService.deleteMany( { clientId: req.body.clientId, tagName: req.body.tagName } );
|
|
304
321
|
} else {
|
|
305
|
-
await taggingService.updateOne( { clientId: req.body.clientId, storeId: req.body.storeId, tagName: req.body.tagName }, { isDeleted: true } );
|
|
322
|
+
let deleteTag = await taggingService.updateOne( { clientId: req.body.clientId, storeId: req.body.storeId, tagName: req.body.tagName }, { isDeleted: true } );
|
|
323
|
+
if ( !deleteTag.modifiedCount ) {
|
|
324
|
+
let data = {
|
|
325
|
+
clientId: req.body.clientId,
|
|
326
|
+
storeId: req.body.storeId,
|
|
327
|
+
tagName: req.body.tagName,
|
|
328
|
+
isDeleted: true,
|
|
329
|
+
};
|
|
330
|
+
taggingService.create( data );
|
|
331
|
+
}
|
|
306
332
|
}
|
|
333
|
+
taggingDetails.forEach( async ( item ) => {
|
|
334
|
+
await axios.post( `${appConfig.url.oldapidomain}/tagging/oldTaggingDelete/${item._id}`, '', { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( ( res ) => {
|
|
335
|
+
logger.info( res?.data );
|
|
336
|
+
} ).catch( ( error ) => {
|
|
337
|
+
logger.error( { error: error } );
|
|
338
|
+
} );
|
|
339
|
+
} );
|
|
307
340
|
const logObj = {
|
|
308
341
|
clientId: req.body?.clientId,
|
|
309
342
|
storeId: taggingDetails ? taggingDetails.map( ( item ) => item?.storeId ) : '',
|
|
310
343
|
userName: req.user?.userName,
|
|
311
344
|
email: req.user?.email,
|
|
312
345
|
date: new Date(),
|
|
313
|
-
logType: '
|
|
314
|
-
logSubType:
|
|
315
|
-
changes: [
|
|
316
|
-
eventType: '
|
|
346
|
+
logType: 'zone',
|
|
347
|
+
logSubType: 'deleteTag',
|
|
348
|
+
changes: [ `${req.body.tagName} tag Deleted` ],
|
|
349
|
+
eventType: '',
|
|
350
|
+
showTo: [ 'client', 'tango' ],
|
|
317
351
|
};
|
|
318
|
-
insertOpenSearchData(
|
|
352
|
+
insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
|
|
319
353
|
await updatezoneTagging( req, res );
|
|
320
354
|
// return res.sendSuccess( 'Tag Deleted Successfully' );
|
|
321
355
|
} catch ( e ) {
|
|
@@ -333,7 +367,7 @@ export const getCameraTagging = async ( req, res ) => {
|
|
|
333
367
|
return res.sendError( 'no data found', 204 );
|
|
334
368
|
}
|
|
335
369
|
if ( camDetails ) {
|
|
336
|
-
query = { clientId: req.query.clientId, cameraId: camDetails._id, streamName: camDetails.streamName, storeId: req.query.storeId };
|
|
370
|
+
query = { clientId: req.query.clientId, cameraId: camDetails._id, streamName: camDetails.streamName, storeId: req.query.storeId, isDeleted: false };
|
|
337
371
|
if ( req.query?.tagName != 'undefined' && req.query?.tagName != '' ) {
|
|
338
372
|
query.tagName = req.query.tagName;
|
|
339
373
|
}
|
|
@@ -392,11 +426,11 @@ async function getCamTaggingDetails( req, res ) {
|
|
|
392
426
|
try {
|
|
393
427
|
let camDetails = await cameraService.find( { storeId: req.body.storeId, isActivated: true, isUp: true } );
|
|
394
428
|
if ( !camDetails.length ) {
|
|
395
|
-
return
|
|
429
|
+
return false;
|
|
396
430
|
}
|
|
397
431
|
let result = [];
|
|
398
432
|
for ( let camera of camDetails ) {
|
|
399
|
-
let taggingDetails = await taggingService.find( { cameraId: camera._id, streamName: camera.streamName, storeId: req.body.storeId, clientId: camera.clientId } );
|
|
433
|
+
let taggingDetails = await taggingService.find( { cameraId: camera._id, streamName: camera.streamName, storeId: req.body.storeId, clientId: camera.clientId, isDeleted: false } );
|
|
400
434
|
let zoneList = [];
|
|
401
435
|
if ( taggingDetails.length ) {
|
|
402
436
|
taggingDetails.forEach( ( zone ) => {
|
|
@@ -485,8 +519,8 @@ export const updateOldData = async ( req, res ) => {
|
|
|
485
519
|
if ( !upload.Key ) {
|
|
486
520
|
logger.error( { message: `JSON Upload Error`, store: item.storeId } );
|
|
487
521
|
}
|
|
488
|
-
if ( index ==
|
|
489
|
-
|
|
522
|
+
if ( index == 0 ) {
|
|
523
|
+
res.sendSuccess( 'Zone Updated Successfully' );
|
|
490
524
|
}
|
|
491
525
|
} else {
|
|
492
526
|
logger.error( { message: 'no data', store: item.storeId } );
|