tango-app-api-report 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 +41 -0
- package/README.md +29 -0
- package/index.js +7 -0
- package/package.json +37 -0
- package/src/controllers/report.controllers.js +90 -0
- package/src/dtos/report.dtos.js +57 -0
- package/src/routes/report.routes.js +14 -0
- package/src/service/report.service.js +39 -0
- package/src/service/user.service.js +5 -0
- package/src/validations/report.validations.js +0 -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/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tango-app-api-report",
|
|
3
|
+
"version": "3.0.0-dev",
|
|
4
|
+
"description": "report",
|
|
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.1578.0",
|
|
17
|
+
"cors": "^2.8.5",
|
|
18
|
+
"dotenv": "^16.4.5",
|
|
19
|
+
"express": "^4.18.3",
|
|
20
|
+
"express-fileupload": "^1.5.0",
|
|
21
|
+
"handlebars": "^4.7.8",
|
|
22
|
+
"mongodb": "^6.5.0",
|
|
23
|
+
"nodemon": "^3.1.0",
|
|
24
|
+
"tango-api-schema": "^2.0.22",
|
|
25
|
+
"tango-app-api-middleware": "^1.0.29",
|
|
26
|
+
"winston": "^3.12.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,90 @@
|
|
|
1
|
+
import { reportCreate, reportGet, reportGetSingle, reportUpdate } from '../service/report.service.js';
|
|
2
|
+
import { insertOpenSearchData, logger } from 'tango-app-api-middleware';
|
|
3
|
+
import { getUserNameEmailById } from '../service/user.service.js';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export async function createReport( req, res ) {
|
|
7
|
+
try {
|
|
8
|
+
const createReport = await reportCreate( {
|
|
9
|
+
clientId: req.params?.id, fileName: req.body?.fileName, fileType: req.body?.fileType, email: req.body?.email,
|
|
10
|
+
} );
|
|
11
|
+
|
|
12
|
+
const user = await getUserNameEmailById( req.userId );
|
|
13
|
+
|
|
14
|
+
const logObj = {
|
|
15
|
+
clientId: req.params?.id,
|
|
16
|
+
userName: user?.userName,
|
|
17
|
+
email: user?.email,
|
|
18
|
+
date: new Date(),
|
|
19
|
+
logType: 'configuration',
|
|
20
|
+
logSubType: 'reportConfig',
|
|
21
|
+
changes: [ `${req.body?.fileName}` ],
|
|
22
|
+
eventType: 'create',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
await insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
26
|
+
if ( createReport ) {
|
|
27
|
+
res.sendSuccess( { result: 'Created Successfully' } );
|
|
28
|
+
}
|
|
29
|
+
} catch ( error ) {
|
|
30
|
+
logger.error( { error: error, message: req.params, function: 'createReport' } );
|
|
31
|
+
return res.sendError( error, 500 );
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function getReport( req, res ) {
|
|
36
|
+
try {
|
|
37
|
+
const reports = await reportGet( {
|
|
38
|
+
clientId: req.params?.id,
|
|
39
|
+
} );
|
|
40
|
+
if ( reports ) {
|
|
41
|
+
res.sendSuccess( reports );
|
|
42
|
+
}
|
|
43
|
+
} catch ( error ) {
|
|
44
|
+
logger.error( { error: error, message: req.params, function: 'getReport' } );
|
|
45
|
+
return res.sendError( error, 500 );
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function getSingleReport( req, res ) {
|
|
50
|
+
try {
|
|
51
|
+
const report = await reportGetSingle( {
|
|
52
|
+
_id: req.params?.id,
|
|
53
|
+
} );
|
|
54
|
+
if ( report ) {
|
|
55
|
+
res.sendSuccess( report );
|
|
56
|
+
}
|
|
57
|
+
} catch ( error ) {
|
|
58
|
+
logger.error( { error: error, message: req.params, function: 'getSingleReport' } );
|
|
59
|
+
return res.sendError( error, 500 );
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function updateReport( req, res ) {
|
|
64
|
+
try {
|
|
65
|
+
const updateAck = await reportUpdate( {
|
|
66
|
+
_id: req.params?.id, fileType: req.body?.fileType, email: req.body?.email, clientId: req.body?.clientId,
|
|
67
|
+
} );
|
|
68
|
+
|
|
69
|
+
const user = await getUserNameEmailById( req.userId );
|
|
70
|
+
|
|
71
|
+
const logObj = {
|
|
72
|
+
clientId: req.body?.clientId,
|
|
73
|
+
userName: user?.userName,
|
|
74
|
+
email: user?.email,
|
|
75
|
+
date: new Date(),
|
|
76
|
+
logType: 'configuration',
|
|
77
|
+
logSubType: 'reportConfig',
|
|
78
|
+
changes: [ `Report id ${req.params?.id}` ],
|
|
79
|
+
eventType: 'update',
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
await insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
83
|
+
if ( updateAck ) {
|
|
84
|
+
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
85
|
+
}
|
|
86
|
+
} catch ( error ) {
|
|
87
|
+
logger.error( { error: error, message: req.params, function: 'updateReport' } );
|
|
88
|
+
return res.sendError( error, 500 );
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import joi from 'joi';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const addReportSchemaBody = joi.object(
|
|
5
|
+
{
|
|
6
|
+
fileName: joi.string().required(),
|
|
7
|
+
fileType: joi.string().required(),
|
|
8
|
+
email: joi.array().items( joi.string().email().required() ).required(),
|
|
9
|
+
},
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export const addReportSchemaParam = joi.object( {
|
|
13
|
+
id: joi.string().required(),
|
|
14
|
+
} );
|
|
15
|
+
|
|
16
|
+
export const addReportValid = {
|
|
17
|
+
body: addReportSchemaBody,
|
|
18
|
+
params: addReportSchemaParam,
|
|
19
|
+
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export const getReportSchemaParam = joi.object( {
|
|
24
|
+
id: joi.string().required(),
|
|
25
|
+
} );
|
|
26
|
+
|
|
27
|
+
export const getReportValid = {
|
|
28
|
+
params: getReportSchemaParam,
|
|
29
|
+
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const getSingleReportSchemaParam = joi.object( {
|
|
33
|
+
id: joi.string().required(),
|
|
34
|
+
} );
|
|
35
|
+
|
|
36
|
+
export const getSingleReportValid = {
|
|
37
|
+
params: getSingleReportSchemaParam,
|
|
38
|
+
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const updateReportSchemaBody = joi.object(
|
|
42
|
+
{
|
|
43
|
+
fileType: joi.string().required(),
|
|
44
|
+
email: joi.array().items( joi.string().email().required() ).required(),
|
|
45
|
+
clientId: joi.string().required(),
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
export const updateReportSchemaParam = joi.object( {
|
|
50
|
+
id: joi.string().required(),
|
|
51
|
+
} );
|
|
52
|
+
|
|
53
|
+
export const updateReportValid = {
|
|
54
|
+
body: updateReportSchemaBody,
|
|
55
|
+
params: updateReportSchemaParam,
|
|
56
|
+
|
|
57
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
+
import { addReportValid, getReportValid, getSingleReportValid, updateReportValid } from '../dtos/report.dtos.js';
|
|
5
|
+
import { createReport, getReport, getSingleReport, updateReport } from '../controllers/report.controllers.js';
|
|
6
|
+
|
|
7
|
+
export const reportRouter = express.Router();
|
|
8
|
+
|
|
9
|
+
reportRouter.post( '/create-report/:id', isAllowedSessionHandler, validate( addReportValid ), createReport );
|
|
10
|
+
reportRouter.get( '/get-client-reports/:id', isAllowedSessionHandler, validate( getReportValid ), getReport );
|
|
11
|
+
reportRouter.get( '/get-report/:id', isAllowedSessionHandler, validate( getSingleReportValid ), getSingleReport );
|
|
12
|
+
reportRouter.put( '/update-report/:id', isAllowedSessionHandler, validate( updateReportValid ), updateReport );
|
|
13
|
+
|
|
14
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import reportModel from 'tango-api-schema/schema/report.model.js';
|
|
2
|
+
import mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function reportCreate( { clientId, fileName, fileType, email } ) {
|
|
6
|
+
return reportModel.create( {
|
|
7
|
+
clientId: clientId,
|
|
8
|
+
fileName: fileName,
|
|
9
|
+
fileType: fileType,
|
|
10
|
+
email: email,
|
|
11
|
+
} );
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function reportGet( { clientId } ) {
|
|
15
|
+
return reportModel.find( {
|
|
16
|
+
clientId: clientId,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
'fileName': 1,
|
|
20
|
+
'_id': 1,
|
|
21
|
+
} );
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function reportGetSingle( { _id } ) {
|
|
25
|
+
return reportModel.findOne( {
|
|
26
|
+
_id: new mongoose.Types.ObjectId( _id ),
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function reportUpdate( { _id, fileType, email, clientId } ) {
|
|
32
|
+
return reportModel.updateOne( { _id: new mongoose.Types.ObjectId( _id ), clientId: clientId },
|
|
33
|
+
{
|
|
34
|
+
$set: {
|
|
35
|
+
'fileType': fileType,
|
|
36
|
+
'email': email,
|
|
37
|
+
},
|
|
38
|
+
} );
|
|
39
|
+
}
|
|
File without changes
|