tango-app-api-infra 3.0.4 → 3.0.6
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/app.js +36 -0
- package/index.js +3 -1
- package/package.json +4 -4
- package/src/controllers/infra.controllers.js +86 -15
- package/src/controllers/internalInfra.controller.js +35 -14
- package/src/controllers/userinfra.controller.js +97 -0
- package/src/routes/infra.routes.js +7 -3
- package/src/routes/internalInfra.routes.js +3 -1
- package/src/routes/userinfra.routes.js +9 -0
- package/src/services/client.service.js +12 -0
- package/src/services/infraReason.service.js +11 -0
- package/src/services/store.service.js +15 -0
- package/src/services/tangoTicket.service.js +21 -0
- package/src/services/user.service.js +7 -0
- package/src/validations/infra.validation.js +142 -0
- package/src/middleware/infra.middleware.js +0 -43
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
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { infraRouter } from './src/routes/infra.routes.js';
|
|
4
4
|
import { internalInfraRouter } from './src/routes/internalInfra.routes.js';
|
|
5
|
-
|
|
5
|
+
import { userInfraRouter } from './src/routes/userinfra.routes.js';
|
|
6
|
+
|
|
7
|
+
export { infraRouter, internalInfraRouter, userInfraRouter };
|
|
6
8
|
|
|
7
9
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-infra",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "infra",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "app.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"start": "nodemon --exec \"eslint --fix . && node
|
|
8
|
+
"start": "nodemon --exec \"eslint --fix . && node app.js\""
|
|
9
9
|
},
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=18.10.0"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"handlebars": "^4.7.8",
|
|
21
21
|
"mongodb": "^6.4.0",
|
|
22
22
|
"nodemon": "^3.1.0",
|
|
23
|
-
"tango-api-schema": "^2.0.
|
|
23
|
+
"tango-api-schema": "^2.0.23",
|
|
24
24
|
"tango-app-api-middleware": "^1.0.15",
|
|
25
25
|
"winston": "^3.12.0",
|
|
26
26
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { createTangoTicket, updateOneTangoTicket } from '../services/tangoTicket.service.js';
|
|
4
|
+
import { createinfraReason, findinfraReason } from '../services/infraReason.service.js';
|
|
4
5
|
import { logger } from 'tango-app-api-middleware';
|
|
5
6
|
export async function createTicket( req, res ) {
|
|
6
7
|
try {
|
|
7
|
-
req.body.ticketId = 'TE_INF_' + new Date().valueOf();
|
|
8
8
|
req.body.issueDate = new Date( req.body.Date );
|
|
9
|
-
req.body.infraTicketDetails =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
req.body.infraTicketDetails.filesCount = req.body.filesCount;
|
|
10
|
+
if ( req.body.issueType == 'infra' ) {
|
|
11
|
+
req.body.ticketId = 'TE_INF_' + new Date().valueOf();
|
|
12
|
+
req.body.infraActivity = [ {
|
|
13
|
+
actionType: 'defaultInfra',
|
|
14
|
+
actionBy: 'Tango',
|
|
15
|
+
} ];
|
|
16
|
+
}
|
|
17
|
+
let create = await createTangoTicket( req.body );
|
|
13
18
|
if ( create ) {
|
|
14
19
|
res.sendSuccess( 'Ticket Created Successfully' );
|
|
15
20
|
}
|
|
@@ -20,26 +25,92 @@ export async function createTicket( req, res ) {
|
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
|
|
23
|
-
export async function
|
|
28
|
+
export async function updateStatus( req, res ) {
|
|
24
29
|
try {
|
|
25
30
|
let infraTicketDetails = {};
|
|
26
31
|
if ( req.body.status == 'close' ) {
|
|
27
|
-
|
|
32
|
+
req.body.infraActivity.push( {
|
|
33
|
+
actionType: 'dataRecived',
|
|
34
|
+
actionBy: 'Tango',
|
|
35
|
+
} );
|
|
28
36
|
}
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
if ( req.body.status == 'inprogress' ) {
|
|
38
|
+
req.body.infraActivity.push( {
|
|
39
|
+
actionType: 'statusChange',
|
|
40
|
+
actionBy: 'User',
|
|
41
|
+
} );
|
|
42
|
+
}
|
|
43
|
+
let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId },
|
|
31
44
|
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
45
|
+
status: req.body.status,
|
|
46
|
+
infraTicketDetails: infraTicketDetails,
|
|
47
|
+
infraActivity: req.body.infraActivity,
|
|
36
48
|
},
|
|
37
49
|
);
|
|
38
50
|
if ( updateTicket ) {
|
|
39
51
|
res.sendSuccess( 'Ticket Updated Successfully' );
|
|
40
52
|
}
|
|
41
53
|
} catch ( error ) {
|
|
42
|
-
logger.error( { error: error, function: '
|
|
54
|
+
logger.error( { error: error, function: 'updateStatus' } );
|
|
55
|
+
return res.sendError( error, 500 );
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
export async function createReason( req, res ) {
|
|
61
|
+
try {
|
|
62
|
+
let create = await createinfraReason( req.body );
|
|
63
|
+
if ( create ) {
|
|
64
|
+
res.sendSuccess( 'Reason Created Successfully' );
|
|
65
|
+
}
|
|
66
|
+
} catch ( error ) {
|
|
67
|
+
logger.error( { error: error, function: 'createReason' } );
|
|
68
|
+
return res.sendError( error, 500 );
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
export async function PrimaryReasons( req, res ) {
|
|
74
|
+
try {
|
|
75
|
+
let list = await findinfraReason( { parentId: { $exists: false } }, { name: 1, order: 1 } );
|
|
76
|
+
if ( list.length > 0 ) {
|
|
77
|
+
res.send( {
|
|
78
|
+
count: list.length,
|
|
79
|
+
result: list,
|
|
80
|
+
} );
|
|
81
|
+
} else {
|
|
82
|
+
res.sendError( 'No data found', 204 );
|
|
83
|
+
}
|
|
84
|
+
} catch ( error ) {
|
|
85
|
+
logger.error( { error: error, function: 'PrimaryReasons' } );
|
|
86
|
+
return res.sendError( error, 500 );
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function secondaryReason( req, res ) {
|
|
91
|
+
try {
|
|
92
|
+
let list = await findinfraReason( { parentName: req.body.primaryIssue }, { name: 1, order: 1 } );
|
|
93
|
+
if ( list.length > 0 ) {
|
|
94
|
+
res.send( {
|
|
95
|
+
count: list.length,
|
|
96
|
+
result: list,
|
|
97
|
+
} );
|
|
98
|
+
}
|
|
99
|
+
} catch ( error ) {
|
|
100
|
+
logger.error( { error: error, function: 'secondaryReason' } );
|
|
101
|
+
return res.sendError( error, 500 );
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
export async function updateTicketIssue( req, res ) {
|
|
107
|
+
try {
|
|
108
|
+
let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'infraActivity': req.body.infraActivity, 'infraTicketDetails.issueStatus': 'identified' } );
|
|
109
|
+
if ( updateTicket ) {
|
|
110
|
+
res.sendSuccess( 'Ticket Updated Successfully' );
|
|
111
|
+
}
|
|
112
|
+
} catch ( error ) {
|
|
113
|
+
logger.error( { error: error, function: 'updateTicketIssue' } );
|
|
43
114
|
return res.sendError( error, 500 );
|
|
44
115
|
}
|
|
45
116
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
import { logger } from 'tango-app-api-middleware';
|
|
3
|
-
import dataModel from 'tango-api-schema';
|
|
4
3
|
import dayjs from 'dayjs';
|
|
4
|
+
import { createClient, findClient } from '../services/client.service.js';
|
|
5
|
+
import { createStore, findStore, updateOneStore } from '../services/store.service.js';
|
|
6
|
+
import { findTangoTicket, updateOneTangoTicket } from '../services/tangoTicket.service.js';
|
|
7
|
+
|
|
5
8
|
|
|
6
9
|
export async function migrateClient() {
|
|
7
10
|
try {
|
|
@@ -24,7 +27,7 @@ export async function migrateClient() {
|
|
|
24
27
|
reTrain: 1,
|
|
25
28
|
},
|
|
26
29
|
};
|
|
27
|
-
await
|
|
30
|
+
await createClient( framedClient );
|
|
28
31
|
};
|
|
29
32
|
} catch ( error ) {
|
|
30
33
|
logger.error( { error: error, function: 'migrateClient' } );
|
|
@@ -51,7 +54,8 @@ export async function migrateStores() {
|
|
|
51
54
|
|
|
52
55
|
|
|
53
56
|
};
|
|
54
|
-
|
|
57
|
+
|
|
58
|
+
await createStore( framedStores );
|
|
55
59
|
};
|
|
56
60
|
} catch ( error ) {
|
|
57
61
|
logger.error( { error: error, function: 'migrateStores' } );
|
|
@@ -60,7 +64,7 @@ export async function migrateStores() {
|
|
|
60
64
|
}
|
|
61
65
|
export async function clientList( req, res ) {
|
|
62
66
|
try {
|
|
63
|
-
let storeList = await
|
|
67
|
+
let storeList = await findClient( { status: 'active' },
|
|
64
68
|
{ 'clientName': 1, 'clientId': 1, 'ticketConfigs': 1 } );
|
|
65
69
|
res.sendSuccess( storeList );
|
|
66
70
|
} catch ( error ) {
|
|
@@ -71,7 +75,7 @@ export async function clientList( req, res ) {
|
|
|
71
75
|
|
|
72
76
|
export async function basicList( req, res ) {
|
|
73
77
|
try {
|
|
74
|
-
let storeList = await
|
|
78
|
+
let storeList = await findStore( { status: 'active' },
|
|
75
79
|
{ 'storeName': 1, 'storeId': 1, 'clientId': 1, 'storeProfile.open': 1, 'storeProfile.close': 1, 'storeProfile.timeZone': 1 } );
|
|
76
80
|
res.sendSuccess( storeList );
|
|
77
81
|
} catch ( error ) {
|
|
@@ -85,7 +89,7 @@ export async function setTicketTime( req, res ) {
|
|
|
85
89
|
try {
|
|
86
90
|
let input = req.body;
|
|
87
91
|
for ( let i = 0; i < input.stores.length; i++ ) {
|
|
88
|
-
await
|
|
92
|
+
await updateOneStore( { storeId: input.stores[i].storeId }, { 'ticketConfigs.nextTicektGenerationTime': new Date( input.stores[i].nextTicektGenerationTime ) } );
|
|
89
93
|
};
|
|
90
94
|
res.sendSuccess( 'Updated Suceessfully' );
|
|
91
95
|
} catch ( error ) {
|
|
@@ -97,8 +101,12 @@ export async function setTicketTime( req, res ) {
|
|
|
97
101
|
export async function downStoresList( req, res ) {
|
|
98
102
|
try {
|
|
99
103
|
let getCurrentHour = dayjs().startOf( 'hour' ).format( 'YYYY-MM-DDTHH:mm' );
|
|
100
|
-
let storesList = await
|
|
101
|
-
|
|
104
|
+
let storesList = await findStore( { 'ticketConfigs.nextTicektGenerationTime': new Date( getCurrentHour ) }, { storeId: 1, storeName: 1, storeProfile: 1, ticketConfigs: 1 } );
|
|
105
|
+
if ( storesList.length > 0 ) {
|
|
106
|
+
res.sendSuccess( storesList );
|
|
107
|
+
} else {
|
|
108
|
+
res.sendError( 'No data found', 204 );
|
|
109
|
+
}
|
|
102
110
|
} catch ( error ) {
|
|
103
111
|
logger.error( { error: error, function: 'downStoresList' } );
|
|
104
112
|
res.sendError( error, 500 );
|
|
@@ -106,11 +114,15 @@ export async function downStoresList( req, res ) {
|
|
|
106
114
|
}
|
|
107
115
|
export async function openTicketList( req, res ) {
|
|
108
116
|
try {
|
|
109
|
-
let openTicketList = await
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
117
|
+
let openTicketList = await findTangoTicket( { status: { $ne: 'closed' } }, { ticketId: 1, basicDetails: 1, createdAt: 1, updateAt: 1, infraTicketDetails: 1 } );
|
|
118
|
+
if ( openTicketList.length ) {
|
|
119
|
+
res.send( {
|
|
120
|
+
count: openTicketList.length,
|
|
121
|
+
data: openTicketList,
|
|
122
|
+
} );
|
|
123
|
+
} else {
|
|
124
|
+
res.sendError( 'No data found', 204 );
|
|
125
|
+
}
|
|
114
126
|
} catch ( error ) {
|
|
115
127
|
logger.error( { error: error, function: 'openTicketList' } );
|
|
116
128
|
res.sendError( error, 500 );
|
|
@@ -119,10 +131,19 @@ export async function openTicketList( req, res ) {
|
|
|
119
131
|
|
|
120
132
|
export async function assigntoUser( req, res ) {
|
|
121
133
|
try {
|
|
122
|
-
await
|
|
134
|
+
await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'infraTicketDetails.assigntoUser': true } );
|
|
123
135
|
res.sendSuccess( 'assigntoUser Successfully' );
|
|
124
136
|
} catch ( error ) {
|
|
125
137
|
logger.error( { error: error, function: 'assigntoUser' } );
|
|
126
138
|
res.sendError( error, 500 );
|
|
127
139
|
}
|
|
128
140
|
}
|
|
141
|
+
export async function updateRefreshTicket( req, res ) {
|
|
142
|
+
try {
|
|
143
|
+
await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'infraTicketDetails.ticketType': 'refreshticket' } );
|
|
144
|
+
res.sendSuccess( 'updated Successfully' );
|
|
145
|
+
} catch ( error ) {
|
|
146
|
+
logger.error( { error: error, function: 'updateRefreshTicket' } );
|
|
147
|
+
res.sendError( error, 500 );
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
|
|
2
|
+
import { findOneTangoTicket, updateOneTangoTicket, aggregateTangoTicket, countDocumentsTangoTicket } from '../services/tangoTicket.service.js';
|
|
3
|
+
import { logger } from 'tango-app-api-middleware';
|
|
4
|
+
import { findOneUser } from '../services/user.service.js';
|
|
5
|
+
import mongoose from 'mongoose';
|
|
6
|
+
export async function userTakeTicket( req, res ) {
|
|
7
|
+
try {
|
|
8
|
+
let userTicket = await findOneTangoTicket( { 'status': { $ne: 'closed' }, 'infraTicketDetails.assigntoUser': true } );
|
|
9
|
+
if ( userTicket ) {
|
|
10
|
+
let assignTicket = await updateOneTangoTicket( { ticketId: userTicket.ticketId }, { 'infraTicketDetails.addressingUser': req.body.userId } );
|
|
11
|
+
if ( assignTicket ) {
|
|
12
|
+
res.sendSuccess( 'Ticket Assigned Successfully' );
|
|
13
|
+
}
|
|
14
|
+
} else {
|
|
15
|
+
res.sendError( 'Ticket Not Found', 204 );
|
|
16
|
+
}
|
|
17
|
+
} catch ( error ) {
|
|
18
|
+
logger.error( { error: error, function: 'userTakeTicket' } );
|
|
19
|
+
return res.sendError( error, 500 );
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export async function userTicketList( req, res ) {
|
|
23
|
+
try {
|
|
24
|
+
let query = [ {
|
|
25
|
+
$match: {
|
|
26
|
+
'status': req.body.status,
|
|
27
|
+
'infraTicketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ),
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
$project: {
|
|
32
|
+
storeId: '$basicDetails.storeId',
|
|
33
|
+
Date: { $dateToString: { format: '%d-%m-%Y', date: '$issueDate' } },
|
|
34
|
+
ticketId: 1,
|
|
35
|
+
issueStatus: '$infraTicketDetails.issueStatus',
|
|
36
|
+
ticketType: '$infraTicketDetails.ticketType',
|
|
37
|
+
primaryIssue: {
|
|
38
|
+
$filter: {
|
|
39
|
+
input: '$infraActivity',
|
|
40
|
+
as: 'item',
|
|
41
|
+
cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
$unwind: {
|
|
48
|
+
path: '$primaryIssue', preserveNullAndEmptyArrays: true },
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
$unwind: {
|
|
52
|
+
path: '$primaryIssue.reasons', preserveNullAndEmptyArrays: true },
|
|
53
|
+
}, {
|
|
54
|
+
$project: {
|
|
55
|
+
storeId: 1,
|
|
56
|
+
Date: 1,
|
|
57
|
+
ticketId: 1,
|
|
58
|
+
issueStatus: 1,
|
|
59
|
+
ticketType: 1,
|
|
60
|
+
infraIssue: '$primaryIssue.reasons.primaryIssue',
|
|
61
|
+
},
|
|
62
|
+
} ];
|
|
63
|
+
let ticketList = await aggregateTangoTicket( query );
|
|
64
|
+
res.sendSuccess( {
|
|
65
|
+
count: ticketList.length,
|
|
66
|
+
data: ticketList,
|
|
67
|
+
} );
|
|
68
|
+
} catch ( error ) {
|
|
69
|
+
logger.error( { error: error, function: 'userTicketList' } );
|
|
70
|
+
return res.sendError( error, 500 );
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export async function basicDetails( req, res ) {
|
|
74
|
+
try {
|
|
75
|
+
let user = await findOneUser( { _id: new mongoose.Types.ObjectId( req.body.userId ) }, { userName: 1, userType: 1 } );
|
|
76
|
+
|
|
77
|
+
if ( !user ) {
|
|
78
|
+
return res.sendError( 'User Not Found', 500 );
|
|
79
|
+
}
|
|
80
|
+
let infraCount = await countDocumentsTangoTicket( { 'infraTicketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ), 'issueType': 'infra' } );
|
|
81
|
+
let installationCount = await countDocumentsTangoTicket( { 'infraTicketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ), 'issueType': 'installation' } );
|
|
82
|
+
res.sendSuccess( {
|
|
83
|
+
userName: user.userName,
|
|
84
|
+
userType: user.userType,
|
|
85
|
+
total: infraCount+installationCount,
|
|
86
|
+
infraCount: infraCount,
|
|
87
|
+
installationCount: installationCount,
|
|
88
|
+
dataMismatchCount: 0,
|
|
89
|
+
auditCount: 0,
|
|
90
|
+
employeeTrainingCount: 0,
|
|
91
|
+
} );
|
|
92
|
+
} catch ( error ) {
|
|
93
|
+
logger.error( { error: error, function: 'userTakeTicket' } );
|
|
94
|
+
return res.sendError( error, 500 );
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { validateDetails, validateTicket } from '../
|
|
4
|
-
import { createTicket,
|
|
3
|
+
import { validateDetails, validateTicket, ticketExists, infraReasonExists, InfrastepstoResolve } from '../validations/infra.validation.js';
|
|
4
|
+
import { createTicket, updateStatus, createReason, PrimaryReasons, secondaryReason, updateTicketIssue } from '../controllers/infra.controllers.js';
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
export const infraRouter = express.Router();
|
|
8
8
|
|
|
9
9
|
infraRouter.post( '/createTicket', validateDetails, validateTicket, createTicket );
|
|
10
|
-
infraRouter.post( '/
|
|
10
|
+
infraRouter.post( '/updateStatus', ticketExists, updateStatus );
|
|
11
|
+
infraRouter.post( '/createReason', createReason );
|
|
12
|
+
infraRouter.get( '/PrimaryReasons', PrimaryReasons );
|
|
13
|
+
infraRouter.post( '/secondaryReason', secondaryReason );
|
|
14
|
+
infraRouter.post( '/updateTicketIssue', ticketExists, infraReasonExists, InfrastepstoResolve, updateTicketIssue );
|
|
11
15
|
|
|
12
16
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import {
|
|
4
4
|
migrateClient, migrateStores, basicList, clientList, setTicketTime, downStoresList,
|
|
5
|
-
openTicketList, assigntoUser,
|
|
5
|
+
openTicketList, assigntoUser, updateRefreshTicket,
|
|
6
6
|
} from '../controllers/internalInfra.controller.js';
|
|
7
7
|
|
|
8
8
|
export const internalInfraRouter = express.Router();
|
|
@@ -15,3 +15,5 @@ internalInfraRouter.post( '/setTicketTime', setTicketTime );
|
|
|
15
15
|
internalInfraRouter.post( '/downStoresList', downStoresList );
|
|
16
16
|
internalInfraRouter.get( '/openTicketList', openTicketList );
|
|
17
17
|
internalInfraRouter.post( '/assigntoUser', assigntoUser );
|
|
18
|
+
internalInfraRouter.post( '/updateRefreshTicket', updateRefreshTicket );
|
|
19
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { userTakeTicket, userTicketList, basicDetails } from '../controllers/userinfra.controller.js';
|
|
3
|
+
|
|
4
|
+
export const userInfraRouter = express.Router();
|
|
5
|
+
|
|
6
|
+
userInfraRouter.post( '/userTakeTicket', userTakeTicket );
|
|
7
|
+
userInfraRouter.post( '/userTicketList', userTicketList );
|
|
8
|
+
userInfraRouter.post( '/basicDetails', basicDetails );
|
|
9
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
import dataModel from 'tango-api-schema';
|
|
3
|
+
|
|
4
|
+
export async function createClient( inputData ) {
|
|
5
|
+
return await dataModel.clientModel.create( inputData );
|
|
6
|
+
}
|
|
7
|
+
export async function findClient( query, project ) {
|
|
8
|
+
return await dataModel.clientModel.find( query, project );
|
|
9
|
+
}
|
|
10
|
+
export async function findOneClient( query, project ) {
|
|
11
|
+
return await dataModel.clientModel.findOne( query, project );
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import dataModel from 'tango-api-schema';
|
|
2
|
+
|
|
3
|
+
export async function createinfraReason( inputData ) {
|
|
4
|
+
return await dataModel.infraReasonsModel.create( inputData );
|
|
5
|
+
}
|
|
6
|
+
export async function findinfraReason( query, project ) {
|
|
7
|
+
return await dataModel.infraReasonsModel.find( query, project );
|
|
8
|
+
}
|
|
9
|
+
export async function findOneinfraReason( query, project ) {
|
|
10
|
+
return await dataModel.infraReasonsModel.findOne( query, project );
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
import dataModel from 'tango-api-schema';
|
|
3
|
+
|
|
4
|
+
export async function createStore( inputData ) {
|
|
5
|
+
return await dataModel.storeModel.create( inputData );
|
|
6
|
+
}
|
|
7
|
+
export async function findStore( query, project ) {
|
|
8
|
+
return await dataModel.storeModel.find( query, project );
|
|
9
|
+
}
|
|
10
|
+
export async function findOneStore( query, project ) {
|
|
11
|
+
return await dataModel.storeModel.findOne( query, project );
|
|
12
|
+
}
|
|
13
|
+
export async function updateOneStore( query, data ) {
|
|
14
|
+
return await dataModel.storeModel.updateOne( query, { $set: data } );
|
|
15
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
import dataModel from 'tango-api-schema';
|
|
3
|
+
|
|
4
|
+
export async function createTangoTicket( inputData ) {
|
|
5
|
+
return await dataModel.tangoTicketModel.create( inputData );
|
|
6
|
+
}
|
|
7
|
+
export async function findTangoTicket( query, project ) {
|
|
8
|
+
return await dataModel.tangoTicketModel.find( query, project );
|
|
9
|
+
}
|
|
10
|
+
export async function findOneTangoTicket( query, project ) {
|
|
11
|
+
return await dataModel.tangoTicketModel.findOne( query, project );
|
|
12
|
+
}
|
|
13
|
+
export async function updateOneTangoTicket( query, data ) {
|
|
14
|
+
return await dataModel.tangoTicketModel.updateOne( query, { $set: data } );
|
|
15
|
+
}
|
|
16
|
+
export async function countDocumentsTangoTicket( query, data ) {
|
|
17
|
+
return await dataModel.tangoTicketModel.countDocuments( query );
|
|
18
|
+
}
|
|
19
|
+
export async function aggregateTangoTicket( query ) {
|
|
20
|
+
return await dataModel.tangoTicketModel.aggregate( query );
|
|
21
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import { findOneTangoTicket } from '../services/tangoTicket.service.js';
|
|
3
|
+
import { findOneClient } from '../services/client.service.js';
|
|
4
|
+
import { findOneStore } from '../services/store.service.js';
|
|
5
|
+
import { findOneinfraReason } from '../services/infraReason.service.js';
|
|
6
|
+
import { logger } from 'tango-app-api-middleware';
|
|
7
|
+
|
|
8
|
+
export async function validateDetails( req, res, next ) {
|
|
9
|
+
try {
|
|
10
|
+
let store = await findOneStore( { storeId: req.body.storeId } );
|
|
11
|
+
if ( !store ) {
|
|
12
|
+
return res.sendError( 'StoreID Not Available' );
|
|
13
|
+
}
|
|
14
|
+
let client = await findOneClient( { clientId: store.clientId } );
|
|
15
|
+
if ( !client ) {
|
|
16
|
+
return res.sendError( 'Client Not Available' );
|
|
17
|
+
}
|
|
18
|
+
req.body.basicDetails = {
|
|
19
|
+
storeId: req.body.storeId,
|
|
20
|
+
storeName: store.storeName,
|
|
21
|
+
clientId: store.clientId,
|
|
22
|
+
clientName: client.clientName,
|
|
23
|
+
};
|
|
24
|
+
req.body.infraTicketDetails = {
|
|
25
|
+
ticketRefreshTime: dayjs().add( client.ticketConfigs.refreshAlert, 'days' ),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
next();
|
|
29
|
+
} catch ( error ) {
|
|
30
|
+
logger.error( { error: error, function: 'validateDetails' } );
|
|
31
|
+
return res.sendError( error, 500 );
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export async function validateTicket( req, res, next ) {
|
|
36
|
+
try {
|
|
37
|
+
let Ticket = await findOneTangoTicket(
|
|
38
|
+
{
|
|
39
|
+
'basicDetails.storeId': req.body.basicDetails.storeId,
|
|
40
|
+
'issueDate': new Date( req.body.Date ),
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
if ( Ticket ) {
|
|
44
|
+
return res.sendSuccess( 'Ticket Already Exists for the day' );
|
|
45
|
+
}
|
|
46
|
+
next();
|
|
47
|
+
} catch ( error ) {
|
|
48
|
+
logger.error( { error: error, function: 'validateTicket' } );
|
|
49
|
+
return res.sendError( error, 500 );
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
export async function ticketExists( req, res, next ) {
|
|
53
|
+
try {
|
|
54
|
+
let Ticket = await findOneTangoTicket(
|
|
55
|
+
{
|
|
56
|
+
ticketId: req.body.ticketId,
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
if ( !Ticket ) {
|
|
60
|
+
return res.sendError( 'Ticket Not Found', 204 );
|
|
61
|
+
}
|
|
62
|
+
req.body.infraActivity = Ticket.infraActivity;
|
|
63
|
+
next();
|
|
64
|
+
} catch ( error ) {
|
|
65
|
+
logger.error( { error: error, function: 'ticketExists' } );
|
|
66
|
+
return res.sendError( error, 500 );
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export async function infraReasonExists( req, res, next ) {
|
|
71
|
+
try {
|
|
72
|
+
let primaryReason = await findOneinfraReason( { name: req.body.primary } );
|
|
73
|
+
if ( !primaryReason ) {
|
|
74
|
+
return res.sendError( 'Primary Reason Not exists in database', 500 );
|
|
75
|
+
}
|
|
76
|
+
const secondary = [];
|
|
77
|
+
const steptoReslove = [];
|
|
78
|
+
for ( let i = 0; i < req.body.secondary.length; i++ ) {
|
|
79
|
+
let secondaryReason = await findOneinfraReason( { name: req.body.secondary[i] } );
|
|
80
|
+
if ( !secondaryReason ) {
|
|
81
|
+
return res.sendError( `secondary Reason - ${req.body.secondary[i]} Not exists in database`, 500 );
|
|
82
|
+
}
|
|
83
|
+
secondary.push( {
|
|
84
|
+
name: secondaryReason.name,
|
|
85
|
+
} );
|
|
86
|
+
let resolveSteps = [];
|
|
87
|
+
for ( let i = 0; i < secondaryReason.stepstoResolve.length; i++ ) {
|
|
88
|
+
resolveSteps.push( {
|
|
89
|
+
name: secondaryReason.stepstoResolve[i].name,
|
|
90
|
+
} );
|
|
91
|
+
}
|
|
92
|
+
steptoReslove.push( {
|
|
93
|
+
primaryIssue: secondaryReason.name,
|
|
94
|
+
secondaryIsssue: [ ...resolveSteps ],
|
|
95
|
+
} );
|
|
96
|
+
}
|
|
97
|
+
req.body.infraActivity.push( {
|
|
98
|
+
actionType: 'issueUpdate',
|
|
99
|
+
actionBy: 'User',
|
|
100
|
+
comment: req.body.comment,
|
|
101
|
+
reasons: [ {
|
|
102
|
+
primaryIssue: primaryReason.name,
|
|
103
|
+
secondaryIssue: secondary,
|
|
104
|
+
} ],
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
next();
|
|
108
|
+
} catch ( error ) {
|
|
109
|
+
logger.error( { error: error, function: 'infraReasonExists' } );
|
|
110
|
+
return res.sendError( error, 500 );
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
export async function InfrastepstoResolve( req, res, next ) {
|
|
114
|
+
try {
|
|
115
|
+
const steptoReslove = [];
|
|
116
|
+
for ( let i = 0; i < req.body.secondary.length; i++ ) {
|
|
117
|
+
let secondaryReason = await findOneinfraReason( { name: req.body.secondary[i] } );
|
|
118
|
+
if ( !secondaryReason ) {
|
|
119
|
+
return res.sendError( `secondary Reason - ${req.body.secondary[i]} Not exists in database`, 500 );
|
|
120
|
+
}
|
|
121
|
+
steptoReslove.push( {
|
|
122
|
+
primaryIssue: secondaryReason.name,
|
|
123
|
+
secondaryIsssue: [ ...secondaryReason.stepstoResolve ],
|
|
124
|
+
} );
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
req.body.infraActivity.push( {
|
|
128
|
+
actionType: 'stepsToResolve',
|
|
129
|
+
actionBy: 'Tango',
|
|
130
|
+
reasons: steptoReslove.map( ( item ) => ( {
|
|
131
|
+
primaryIssue: item.primaryIssue,
|
|
132
|
+
secondaryIssue: item.secondaryIsssue.map( ( issue ) => ( {
|
|
133
|
+
name: issue.name, // Assuming each object has a 'name' property
|
|
134
|
+
} ) ),
|
|
135
|
+
} ) ),
|
|
136
|
+
} );
|
|
137
|
+
next();
|
|
138
|
+
} catch ( error ) {
|
|
139
|
+
logger.error( { error: error, function: 'infraReasonExists' } );
|
|
140
|
+
return res.sendError( error, 500 );
|
|
141
|
+
}
|
|
142
|
+
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import dataModel from 'tango-api-schema';
|
|
2
|
-
import { logger } from 'tango-app-api-middleware';
|
|
3
|
-
|
|
4
|
-
export async function validateDetails( req, res, next ) {
|
|
5
|
-
try {
|
|
6
|
-
let store = await dataModel.storeModel.findOne( { storeId: req.body.storeId } );
|
|
7
|
-
if ( !store ) {
|
|
8
|
-
return res.sendError( 'StoreID Not Available' );
|
|
9
|
-
}
|
|
10
|
-
let client = await dataModel.clientModel.findOne( { clientId: store.clientId } );
|
|
11
|
-
if ( !client ) {
|
|
12
|
-
return res.sendError( 'Client Not Available' );
|
|
13
|
-
}
|
|
14
|
-
req.body.basicDetails = {
|
|
15
|
-
storeId: req.body.storeId,
|
|
16
|
-
storeName: store.storeName,
|
|
17
|
-
clientId: store.clientId,
|
|
18
|
-
clientName: client.clientName,
|
|
19
|
-
};
|
|
20
|
-
next();
|
|
21
|
-
} catch ( error ) {
|
|
22
|
-
logger.error( { error: error, function: 'validateDetails' } );
|
|
23
|
-
return res.sendError( error, 500 );
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export async function validateTicket( req, res, next ) {
|
|
28
|
-
try {
|
|
29
|
-
let Ticket = await dataModel.tangoTicket.findOne(
|
|
30
|
-
{
|
|
31
|
-
'basicDetails.storeId': req.body.basicDetails.storeId,
|
|
32
|
-
'issueDate': new Date( req.body.Date ),
|
|
33
|
-
},
|
|
34
|
-
);
|
|
35
|
-
if ( Ticket ) {
|
|
36
|
-
return res.sendSuccess( 'Ticket Already Exists for the day' );
|
|
37
|
-
}
|
|
38
|
-
next();
|
|
39
|
-
} catch ( error ) {
|
|
40
|
-
logger.error( { error: error, function: 'validateTicket' } );
|
|
41
|
-
return res.sendError( error, 500 );
|
|
42
|
-
}
|
|
43
|
-
};
|