tango-app-api-audit 1.0.0
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 +41 -0
- package/README.md +29 -0
- package/app.js +180 -0
- package/index.js +9 -0
- package/package.json +35 -0
- package/src/controllers/audit.controllers.js +0 -0
- package/src/controllers/auditMetrics.controllers.js +21 -0
- package/src/docs/auditMetrics.docs.js +27 -0
- package/src/dtos/auditMetrics.dtos.js +29 -0
- package/src/routes/audit.routes.js +6 -0
- package/src/routes/auditMetrics.routes.js +12 -0
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
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/app.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import { auditRouter } from './index.js';
|
|
4
|
+
|
|
5
|
+
import dotenv from 'dotenv';
|
|
6
|
+
import { logger } from 'tango-app-api-middleware';
|
|
7
|
+
import { connectdb } from './config/database/database.js';
|
|
8
|
+
import responseMiddleware from './config/response/response.js';
|
|
9
|
+
import errorMiddleware from './config/response/error.js';
|
|
10
|
+
import pkg from 'body-parser';
|
|
11
|
+
import { auditMetricsRouter } from './index.js';
|
|
12
|
+
|
|
13
|
+
const { json, urlencoded } = pkg;
|
|
14
|
+
const env=dotenv.config();
|
|
15
|
+
|
|
16
|
+
const app = express();
|
|
17
|
+
const PORT = process.env.PORT || 3000;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
app.use( json( { limit: '500mb' } ) );
|
|
21
|
+
app.use(
|
|
22
|
+
urlencoded( {
|
|
23
|
+
extended: true,
|
|
24
|
+
} ),
|
|
25
|
+
);
|
|
26
|
+
app.use( responseMiddleware );
|
|
27
|
+
app.use( errorMiddleware );
|
|
28
|
+
|
|
29
|
+
if ( env.error ) {
|
|
30
|
+
logger.error( '.env not found' );
|
|
31
|
+
process.exit( 1 );
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports.cameraupdate = async () => {
|
|
35
|
+
try {
|
|
36
|
+
console.log("cameraMigrate===============<>");
|
|
37
|
+
const targetUrl =
|
|
38
|
+
"mongodb+srv://tango-api-production:5TdxKKSkZiRVtjta@production.qc4rw.mongodb.net/tango-api-prod?retryWrites=true&w=majority";
|
|
39
|
+
// const targetUrl =
|
|
40
|
+
// "mongodb+srv://tangoeye:SUTONQosEUijJKWC@non-prod.jaups.mongodb.net/prod-dump?retryWrites=true&w=majority";
|
|
41
|
+
|
|
42
|
+
const sourceUrl =
|
|
43
|
+
"mongodb+srv://tango-api-production:5TdxKKSkZiRVtjta@production.qc4rw.mongodb.net/tango-retail?retryWrites=true&w=majority";
|
|
44
|
+
|
|
45
|
+
const sourceClient = await MongoClient.connect(sourceUrl, {
|
|
46
|
+
useNewUrlParser: true,
|
|
47
|
+
useUnifiedTopology: true,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const sourceDB = sourceClient.db("tango-api-prod");
|
|
51
|
+
const sourceCollection = sourceDB.collection("cameras");
|
|
52
|
+
const data = await sourceCollection
|
|
53
|
+
.find({
|
|
54
|
+
storeId: {
|
|
55
|
+
$in: [
|
|
56
|
+
"11-982",
|
|
57
|
+
"11-1256",
|
|
58
|
+
"11-892",
|
|
59
|
+
"11-1023",
|
|
60
|
+
"11-1110",
|
|
61
|
+
"11-1022",
|
|
62
|
+
"11-1075",
|
|
63
|
+
"11-931",
|
|
64
|
+
"11-1003",
|
|
65
|
+
"11-1136",
|
|
66
|
+
"11-1169",
|
|
67
|
+
"11-1428",
|
|
68
|
+
"11-1300",
|
|
69
|
+
"11-1505",
|
|
70
|
+
"11-1376",
|
|
71
|
+
"11-1271",
|
|
72
|
+
"11-1286",
|
|
73
|
+
"11-1419",
|
|
74
|
+
"11-411",
|
|
75
|
+
"11-1514",
|
|
76
|
+
"11-1569",
|
|
77
|
+
"11-1458",
|
|
78
|
+
"11-1551",
|
|
79
|
+
"11-1531",
|
|
80
|
+
"11-1601",
|
|
81
|
+
"11-1762",
|
|
82
|
+
"11-1678",
|
|
83
|
+
"11-1608",
|
|
84
|
+
"11-1652",
|
|
85
|
+
"11-1680",
|
|
86
|
+
"11-1829",
|
|
87
|
+
"11-1775",
|
|
88
|
+
"11-1814",
|
|
89
|
+
"11-198",
|
|
90
|
+
"11-448",
|
|
91
|
+
"11-404",
|
|
92
|
+
"11-628",
|
|
93
|
+
"11-809",
|
|
94
|
+
"11-757",
|
|
95
|
+
"11-525",
|
|
96
|
+
"11-744",
|
|
97
|
+
"11-690",
|
|
98
|
+
"11-748",
|
|
99
|
+
"11-663",
|
|
100
|
+
"11-778",
|
|
101
|
+
"11-806",
|
|
102
|
+
"11-1179",
|
|
103
|
+
"11-867",
|
|
104
|
+
"11-872"
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
})
|
|
108
|
+
.toArray();
|
|
109
|
+
|
|
110
|
+
// // // Connect to the target database
|
|
111
|
+
const targetClient = await MongoClient.connect(targetUrl, {
|
|
112
|
+
useNewUrlParser: true,
|
|
113
|
+
useUnifiedTopology: true,
|
|
114
|
+
});
|
|
115
|
+
const targetDB = targetClient.db("tango-retail");
|
|
116
|
+
const targetCollection = targetDB.collection("cameras");
|
|
117
|
+
|
|
118
|
+
for (const cameraData of data) {
|
|
119
|
+
console.log(cameraData, "!!!!!!!!!");
|
|
120
|
+
const inputData = {
|
|
121
|
+
storeId: cameraData.storeId,
|
|
122
|
+
masterServer:
|
|
123
|
+
cameraData?.masterServer == null || undefined
|
|
124
|
+
? null
|
|
125
|
+
: cameraData?.masterServer,
|
|
126
|
+
client_id: cameraData.clientId,
|
|
127
|
+
ip: cameraData.ip,
|
|
128
|
+
manufacturer:
|
|
129
|
+
cameraData.manufacturer == undefined ? "" : cameraData.manufacturer,
|
|
130
|
+
cameraNumber: cameraData.no,
|
|
131
|
+
userName: cameraData.username,
|
|
132
|
+
password: cameraData.password,
|
|
133
|
+
subType: cameraData.subType == undefined ? 0 : cameraData.subType,
|
|
134
|
+
RTSP: cameraData.RTSP,
|
|
135
|
+
retentionPeriod: cameraData?.retentionPeriod || 0,
|
|
136
|
+
streamName: cameraData.streamName,
|
|
137
|
+
isActivated: cameraData.isActivated,
|
|
138
|
+
isUp: cameraData.isUp,
|
|
139
|
+
macId: cameraData.macId == undefined ? "" : "",
|
|
140
|
+
timeElapsed: cameraData.timeElapsed,
|
|
141
|
+
filters: {
|
|
142
|
+
yolo: cameraData.filters["yolo"],
|
|
143
|
+
yoloProcess: cameraData.filters["yoloProcess"],
|
|
144
|
+
},
|
|
145
|
+
isVideoStream:
|
|
146
|
+
cameraData?.IsVideoStream == undefined ||
|
|
147
|
+
cameraData?.IsVideoStream == null ||
|
|
148
|
+
cameraData?.IsVideoStream == false
|
|
149
|
+
? false
|
|
150
|
+
: true,
|
|
151
|
+
width: cameraData.width == undefined ? 0 : 0,
|
|
152
|
+
height: cameraData.height == undefined ? 0 : 0,
|
|
153
|
+
createdAt: cameraData.createdAt,
|
|
154
|
+
updatedAt: cameraData.updatedAt,
|
|
155
|
+
productModule: null,
|
|
156
|
+
thumbnailImage: cameraData.thumbnailImage,
|
|
157
|
+
};
|
|
158
|
+
console.log(inputData, "***********<>");
|
|
159
|
+
|
|
160
|
+
const result = await targetCollection.update(
|
|
161
|
+
{ streamName: cameraData.streamName },
|
|
162
|
+
{ $set: inputData },
|
|
163
|
+
{ upsert: true, setDefaultsOnInsert: true }
|
|
164
|
+
);
|
|
165
|
+
console.log( result );
|
|
166
|
+
}
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error(error);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
app.use( '/audit', auditRouter );
|
|
174
|
+
app.use( '/audit-metrics', auditMetricsRouter );
|
|
175
|
+
|
|
176
|
+
app.listen( PORT, () => {
|
|
177
|
+
logger.info( `server is running on port= ${PORT} ` );
|
|
178
|
+
connectdb();
|
|
179
|
+
} );
|
|
180
|
+
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tango-app-api-audit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "audit & audit metrics apis",
|
|
5
|
+
"main": "app.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"start": "nodemon --exec \"eslint --fix . && node app.js\""
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=18.10.0"
|
|
12
|
+
},
|
|
13
|
+
"author": "praveenraj",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"aws-sdk": "^2.1643.0",
|
|
17
|
+
"dotenv": "^16.4.5",
|
|
18
|
+
"express": "^4.19.2",
|
|
19
|
+
"handlebars": "^4.7.8",
|
|
20
|
+
"mongodb": "^6.7.0",
|
|
21
|
+
"nodemon": "^3.1.3",
|
|
22
|
+
"tango-api-schema": "^2.0.105",
|
|
23
|
+
"tango-app-api-middleware": "^1.0.81-dev",
|
|
24
|
+
"winston": "^3.13.0",
|
|
25
|
+
"winston-daily-rotate-file": "^5.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"eslint": "^8.57.0",
|
|
29
|
+
"eslint-config-google": "^0.14.0",
|
|
30
|
+
"eslint-config-semistandard": "^17.0.0",
|
|
31
|
+
"eslint-config-standard": "^17.1.0",
|
|
32
|
+
"eslint-plugin-import": "^2.29.1",
|
|
33
|
+
"eslint-plugin-promise": "^6.2.0"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export async function getAuditImageList( req, res ) {
|
|
4
|
+
try {
|
|
5
|
+
const inputData = req.body;
|
|
6
|
+
return res.sendSuccess( { result: inputData } );
|
|
7
|
+
} catch ( error ) {
|
|
8
|
+
logger.info( { error: error, message: req.body, function: 'getAuditImageList' } );
|
|
9
|
+
return res.sendError( error );
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function userAuditHistory( req, res ) {
|
|
14
|
+
try {
|
|
15
|
+
const inputData = req.body;
|
|
16
|
+
return res.sendSuccess( { result: inputData } );
|
|
17
|
+
} catch ( error ) {
|
|
18
|
+
logger.info( { error: error, message: req.body, function: 'userAuditHistory' } );
|
|
19
|
+
return res.sendError( error );
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import j2s from 'joi-to-swagger';
|
|
2
|
+
|
|
3
|
+
export const auditMetricsDocs = {
|
|
4
|
+
|
|
5
|
+
'/v3/audit-metrics/get-audit-images': {
|
|
6
|
+
post: {
|
|
7
|
+
tags: [ 'Audit Metrics' ],
|
|
8
|
+
description: `Get list of client with date range`,
|
|
9
|
+
operationId: 'client-list-table',
|
|
10
|
+
parameters: {},
|
|
11
|
+
requestBody: {
|
|
12
|
+
content: {
|
|
13
|
+
'application/json': {
|
|
14
|
+
schema: j2s( clientListTableSchema ).swagger,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
responses: {
|
|
19
|
+
200: { description: 'Get user permission successfully' },
|
|
20
|
+
401: { description: 'Unauthorized User' },
|
|
21
|
+
422: { description: 'Field Error' },
|
|
22
|
+
500: { description: 'Server Error' },
|
|
23
|
+
204: { description: 'Not Found' },
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import joi from 'joi';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const getAuditImagesSchema = joi.object(
|
|
5
|
+
{
|
|
6
|
+
fileDate: joi.string().required(),
|
|
7
|
+
fileType: joi.string().required(),
|
|
8
|
+
storeId: joi.string().required(),
|
|
9
|
+
},
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export const getAuditImagesValid = {
|
|
13
|
+
body: getAuditImagesSchema,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const userAuditHistorySchema = joi.object(
|
|
17
|
+
{
|
|
18
|
+
fromDate: joi.string().required(), // need to clarify about keys --userId
|
|
19
|
+
toDate: joi.string().required(),
|
|
20
|
+
storeId: joi.string().required(),
|
|
21
|
+
fileDate: joi.string().required(),
|
|
22
|
+
fileType: joi.string().required(),
|
|
23
|
+
storeId: joi.string().required(),
|
|
24
|
+
},
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export const userAuditHistoryValid = {
|
|
28
|
+
body: userAuditHistorySchema,
|
|
29
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
+
import { getAuditImageList, userAuditHistory } from '../controllers/auditMetrics.controllers.js';
|
|
5
|
+
import { getAuditImagesValid, userAuditHistoryValid } from '../dtos/auditMetrics.dtos.js';
|
|
6
|
+
|
|
7
|
+
export const auditMetricsRouter = express.Router();
|
|
8
|
+
|
|
9
|
+
auditMetricsRouter.post( '/get-audit-images', validate( getAuditImagesValid ), isAllowedSessionHandler, getAuditImageList );
|
|
10
|
+
auditMetricsRouter.post('/user-audit-history', validate(userAuditHistoryValid), isAllowedSessionHandler, userAuditHistory)
|
|
11
|
+
|
|
12
|
+
export default auditMetricsRouter;
|