tango-app-api-infra 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 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,36 @@
1
+
2
+ import express from 'express';
3
+ import { infraRouter } from './index.js';
4
+ import dotenv from 'dotenv';
5
+ import { logger } from './config/logger/logger.js';
6
+ import responseMiddleware from './config/response/response.js';
7
+ import errorMiddleware from './config/response/error.js';
8
+ import { connectdb } from './config/database/database.js';
9
+ import pkg from 'body-parser';
10
+ const { json, urlencoded } = pkg;
11
+
12
+ const env=dotenv.config();
13
+
14
+ const app = express();
15
+ const PORT = process.env.PORT || 3000;
16
+
17
+
18
+ if ( env.error ) {
19
+ logger.error( '.env not found' );
20
+ process.exit( 1 );
21
+ }
22
+ app.use( json( { limit: '500mb' } ) );
23
+ app.use(
24
+ urlencoded( {
25
+ extended: true,
26
+ } ),
27
+ );
28
+ app.use( responseMiddleware );
29
+ app.use( errorMiddleware );
30
+ app.use( '/api', infraRouter );
31
+
32
+ app.listen( PORT, () => {
33
+ console.log( `server is running on port= ${PORT} ` );
34
+ connectdb();
35
+ } );
36
+
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+
2
+
3
+ import { infraRouter } from './src/routes/infra.routes.js';
4
+ import { internalInfraRouter } from './src/routes/internalInfra.routes.js';
5
+ export { infraRouter, internalInfraRouter };
6
+
7
+
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "tango-app-api-infra",
3
+ "version": "1.0.0",
4
+ "description": "infra",
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.1571.0",
17
+ "dayjs": "^1.11.10",
18
+ "dotenv": "^16.4.5",
19
+ "express": "^4.18.3",
20
+ "handlebars": "^4.7.8",
21
+ "mongodb": "^6.4.0",
22
+ "nodemon": "^3.1.0",
23
+ "tango-api-schema": "^2.0.5",
24
+ "tango-app-api-middleware": "^1.0.15",
25
+ "winston": "^3.12.0",
26
+ "winston-daily-rotate-file": "^5.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "eslint": "^8.57.0",
30
+ "eslint-config-google": "^0.14.0",
31
+ "eslint-config-semistandard": "^17.0.0",
32
+ "eslint-config-standard": "^17.1.0",
33
+ "eslint-plugin-import": "^2.29.1",
34
+ "eslint-plugin-promise": "^6.1.1"
35
+ }
36
+ }
File without changes
@@ -0,0 +1,97 @@
1
+
2
+ import { logger } from 'tango-app-api-middleware';
3
+ import dataModel from 'tango-api-schema';
4
+ import dayjs from 'dayjs';
5
+
6
+ export async function migrateClient() {
7
+ try {
8
+ let oldclient = [];
9
+ for ( let i = 0; i < oldclient.length; i++ ) {
10
+ let framedClient = {
11
+ clientName: oldclient[i].brandName,
12
+ clientId: oldclient[i].clientId,
13
+ tangoId: oldclient[i].brandIndex,
14
+ status: 'active',
15
+ ticketConfigs: {
16
+ installationReAssign: 1,
17
+ downTimeType: 1,
18
+ infraDownTime: 1,
19
+ minFilesCount: 0,
20
+ rcaTicketAssign: 2,
21
+ refreshAlert: 2,
22
+ statusCheckAlert: 2,
23
+ accuracyPercentage: 0,
24
+ reTrain: 1,
25
+ },
26
+ };
27
+ await dataModel.clientModel.create( framedClient );
28
+ };
29
+ } catch ( error ) {
30
+ logger.error( { error: error, function: 'migrateClient' } );
31
+ res.sendError( error, 500 );
32
+ }
33
+ }
34
+
35
+
36
+ export async function migrateStores() {
37
+ try {
38
+ let oldstores = [];
39
+ for ( let i = 0; i < oldstores.length; i++ ) {
40
+ let framedStores = {
41
+ storeId: oldstores[i].id,
42
+ storeName: oldstores[i].name,
43
+ appId: oldstores[i].appId,
44
+ clientId: oldstores[i].client_id,
45
+ status: 'active',
46
+ storeProfile: {
47
+ open: oldstores[i].configuration.storeOpenTime,
48
+ close: oldstores[i].configuration.storeCloseTime,
49
+ timeZone: oldstores[i].timezone,
50
+ },
51
+
52
+
53
+ };
54
+ await dataModel.storeModel.create( framedStores );
55
+ };
56
+ } catch ( error ) {
57
+ logger.error( { error: error, function: 'migrateStores' } );
58
+ res.sendError( error, 500 );
59
+ }
60
+ }
61
+
62
+
63
+ export async function basicList( req, res ) {
64
+ try {
65
+ let storeList = await dataModel.storeModel.find( { status: 'active' },
66
+ { 'storeName': 1, 'storeId': 1, 'clientId': 1, 'storeProfile.open': 1, 'storeProfile.close': 1, 'storeProfile.timeZone': 1 } );
67
+ res.sendSuccess( storeList );
68
+ } catch ( error ) {
69
+ logger.error( { error: error, function: 'basicList' } );
70
+ res.sendError( error, 500 );
71
+ }
72
+ }
73
+
74
+
75
+ export async function setTicketTime( req, res ) {
76
+ try {
77
+ let input = req.body;
78
+ for ( let i = 0; i < input.stores.length; i++ ) {
79
+ await dataModel.storeModel.updateOne( { storeId: input.stores[i].storeId }, { 'ticketConfigs.nextTicektGenerationTime': new Date( input.stores[i].nextTicektGenerationTime ) } );
80
+ };
81
+ res.sendSuccess( 'Updated Suceessfully' );
82
+ } catch ( error ) {
83
+ logger.error( { error: error, function: 'setTicketTime' } );
84
+ res.sendError( error, 500 );
85
+ }
86
+ }
87
+
88
+ export async function downStoresList( req, res ) {
89
+ try {
90
+ let getCurrentHour = dayjs().startOf( 'hour' ).format( 'YYYY-MM-DDTHH:mm' );
91
+ let storesList = await dataModel.storeModel.find( { 'ticketConfigs.nextTicektGenerationTime': new Date( getCurrentHour ) }, { storeId: 1, storeName: 1, storeProfile: 1, ticketConfigs: 1 } );
92
+ res.sendSuccess( storesList );
93
+ } catch ( error ) {
94
+ logger.error( { error: error, function: 'downStoresList' } );
95
+ res.sendError( error, 500 );
96
+ }
97
+ }
@@ -0,0 +1,12 @@
1
+
2
+ import express from 'express';
3
+
4
+
5
+ export const infraRouter = express.Router();
6
+
7
+ infraRouter.get( '/', ( req, res ) => {
8
+
9
+
10
+ } );
11
+
12
+
@@ -0,0 +1,13 @@
1
+
2
+ import express from 'express';
3
+ import { migrateClient, migrateStores, basicList, setTicketTime, downStoresList } from '../controllers/internalInfra.controller.js';
4
+
5
+ export const internalInfraRouter = express.Router();
6
+
7
+ internalInfraRouter.get( '/migrateClient', migrateClient );
8
+ internalInfraRouter.get( '/migrateStores', migrateStores );
9
+ internalInfraRouter.get( '/basicList', basicList );
10
+ internalInfraRouter.post( '/setTicketTime', setTicketTime );
11
+ internalInfraRouter.post( '/downStoresList', downStoresList );
12
+
13
+