tango-app-api-client 3.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 +42 -0
- package/index.js +6 -0
- package/package.json +35 -0
- package/src/controllers/client.controllers.js +74 -0
- package/src/dtos/client.dtos.js +10 -0
- package/src/routes/client.routes.js +13 -0
- package/src/service/client.service.js +46 -0
- package/src/validations/client.validations.js +15 -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/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tango-app-api-client",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "client",
|
|
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.1560.0",
|
|
17
|
+
"dotenv": "^16.4.4",
|
|
18
|
+
"express": "^4.18.2",
|
|
19
|
+
"handlebars": "^4.7.8",
|
|
20
|
+
"mongodb": "^6.3.0",
|
|
21
|
+
"nodemon": "^3.0.3",
|
|
22
|
+
"tango-api-schema": "^2.0.8",
|
|
23
|
+
"tango-app-api-middleware": "^1.0.16",
|
|
24
|
+
"winston": "^3.11.0",
|
|
25
|
+
"winston-daily-rotate-file": "^5.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"eslint": "^8.56.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.1.1"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { logger } from 'tango-app-api-middleware';
|
|
2
|
+
import { createAuditQueue, findOne, getClientCount, insert, update, find } from '../service/client.service.js';
|
|
3
|
+
|
|
4
|
+
export async function create( req, res ) {
|
|
5
|
+
try {
|
|
6
|
+
const inputData = req.body;
|
|
7
|
+
const query ={ clientName: inputData.clientName };
|
|
8
|
+
const leadRecord = await findOne( query );
|
|
9
|
+
const tangoId = await getClientCount() +1;
|
|
10
|
+
const generatedName =inputData.clientName.replace( /[^A-Z0-9]+/ig, '' );
|
|
11
|
+
const product = leadRecord?.planDetails?.product.map( ( value ) => ( { productName: value } ) );
|
|
12
|
+
const record = {
|
|
13
|
+
'clientName': leadRecord.clientName,
|
|
14
|
+
'clientId': String( tangoId ),
|
|
15
|
+
'tangoId': tangoId,
|
|
16
|
+
'planDetails.totalStores': leadRecord?.planDetails?.totalStores,
|
|
17
|
+
'planDetails.storeSize': leadRecord?.planDetails?.storeSize,
|
|
18
|
+
'planDetails.totalCamera': leadRecord?.planDetails?.totalCamera,
|
|
19
|
+
'planDetails.subscriptionPeriod': leadRecord?.planDetails?.subscriptionPeriod,
|
|
20
|
+
'planDetails.subscriptionType': leadRecord?.planDetails?.subscriptionType,
|
|
21
|
+
'planDetails.paymentStatus': leadRecord?.planDetails?.paymentStatus,
|
|
22
|
+
'planDetails.product': product,
|
|
23
|
+
'reportConfigs.reportName': generatedName,
|
|
24
|
+
'auditConfigs.queueName': generatedName,
|
|
25
|
+
|
|
26
|
+
};
|
|
27
|
+
const insertClient = await insert( record );
|
|
28
|
+
if ( insertClient ) {
|
|
29
|
+
await createAuditQueue( generatedName );
|
|
30
|
+
return res.sendSuccess( { result: 'Client has been created sucessfully' } );
|
|
31
|
+
}
|
|
32
|
+
} catch ( error ) {
|
|
33
|
+
logger.info( { error: error, message: req.body, function: 'create' } );
|
|
34
|
+
return res.sendError( error, 500 );
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function changeStatus( req, res, next ) {
|
|
39
|
+
try {
|
|
40
|
+
const inputData = req.body;
|
|
41
|
+
const query = {
|
|
42
|
+
clientName: inputData.clientName,
|
|
43
|
+
};
|
|
44
|
+
const record= {
|
|
45
|
+
status: inputData.status,
|
|
46
|
+
};
|
|
47
|
+
const result = await update( query, record );
|
|
48
|
+
if ( result.matchedCount == 0 ) {
|
|
49
|
+
res.sendError( 'Not Found', 204 );
|
|
50
|
+
}
|
|
51
|
+
if ( inputData.status == 'approved' ) {
|
|
52
|
+
return next();
|
|
53
|
+
} else {
|
|
54
|
+
return res.sendSuccess( { result: 'Status has been changed sucessfully' } );
|
|
55
|
+
}
|
|
56
|
+
} catch ( error ) {
|
|
57
|
+
logger.info( { error: error, message: req.body, function: 'changeStatus' } );
|
|
58
|
+
return res.sendError( error, 500 );
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function getClients( req, res ) {
|
|
63
|
+
try {
|
|
64
|
+
const field = { clientName: 1, clientId: 1 };
|
|
65
|
+
const result = await find( {}, field );
|
|
66
|
+
if ( result == 0 ) {
|
|
67
|
+
return res.sendError( 'No Data Found', 204 );
|
|
68
|
+
}
|
|
69
|
+
return res.sendSuccess( { result: result } );
|
|
70
|
+
} catch ( error ) {
|
|
71
|
+
logger.error( { error: error, function: 'getClients' } );
|
|
72
|
+
return res.sendError( error, 500 );
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import { validate } from 'tango-app-api-middleware';
|
|
4
|
+
import { clientCreationValid } from '../dtos/client.dtos.js';
|
|
5
|
+
import { isclientNameExists } from '../validations/client.validations.js';
|
|
6
|
+
import { changeStatus, create, getClients } from '../controllers/client.controllers.js';
|
|
7
|
+
|
|
8
|
+
export const clientRouter = express.Router();
|
|
9
|
+
|
|
10
|
+
clientRouter.post( '/create', validate( clientCreationValid ), isclientNameExists, changeStatus, create );
|
|
11
|
+
clientRouter.get( '/get-clients', getClients );
|
|
12
|
+
|
|
13
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import model from 'tango-api-schema';
|
|
2
|
+
// import { createQueue, getQueueUrl } from 'tango-app-api-middleware';
|
|
3
|
+
|
|
4
|
+
export function update( query, record ) {
|
|
5
|
+
return model.leadModel.updateMany( query, { $set: record } );
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function findOne( query, field ) {
|
|
9
|
+
return model.leadModel.findOne( query, field );
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getClientCount( query ) {
|
|
13
|
+
return model.clientModel.countDocuments( query );
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function insert( record ) {
|
|
17
|
+
return model.clientModel.insertMany( record );
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function find( query, field ) {
|
|
21
|
+
return model.clientModel.find( query, field );
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function createAuditQueue( queueName ) {
|
|
25
|
+
try {
|
|
26
|
+
// const isExist = await getQueueUrl( `${queueName}${config.aws.sqs.queueType}` );
|
|
27
|
+
// if ( isExist.statusCode ) {
|
|
28
|
+
// const addQueue = await createQueue( `${queueName}${config.aws.sqs.queueType}` );
|
|
29
|
+
// if ( addQueue.QueueUrl ) {
|
|
30
|
+
// logger.info(
|
|
31
|
+
// 'Queueue Created'
|
|
32
|
+
// , { queueName: addQueue.QueueUrl, addQueue },
|
|
33
|
+
// );
|
|
34
|
+
// } else {
|
|
35
|
+
// logger.error( { error: 'Queue creation failed', function: 'createAuditQueue' } );
|
|
36
|
+
// }
|
|
37
|
+
// } else {
|
|
38
|
+
// logger.error( { error: 'Queue already exisit', message: queueName, function: 'createAuditQueue' } );
|
|
39
|
+
// }
|
|
40
|
+
return true;
|
|
41
|
+
} catch ( error ) {
|
|
42
|
+
return false;
|
|
43
|
+
logger.error( { error: error, message: queueName, function: 'createAuditQueue' } );
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import model from 'tango-api-schema';
|
|
2
|
+
|
|
3
|
+
export async function isclientNameExists( req, res, next ) {
|
|
4
|
+
try {
|
|
5
|
+
const inputData = req.body;
|
|
6
|
+
const lead = await model.clientModel.findOne( { clientName: inputData?.clientName } );
|
|
7
|
+
if ( lead ) {
|
|
8
|
+
return res.sendError( 'clientName is exists', 403 );
|
|
9
|
+
}
|
|
10
|
+
return next();
|
|
11
|
+
} catch ( error ) {
|
|
12
|
+
logger.error( { error: error, message: req.body, function: 'isclientNameExists' } );
|
|
13
|
+
return res.sendError( error, 500 );
|
|
14
|
+
}
|
|
15
|
+
}
|