tango-app-api-trax 3.4.1-beta-2 → 3.5.0-alpha-1
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/index.js +2 -1
- package/package.json +1 -1
- package/src/controllers/activityLog.controller.js +294 -0
- package/src/controllers/download.controller.js +2 -0
- package/src/controllers/gallery.controller.js +210 -6
- package/src/controllers/mobileTrax.controller.js +288 -5
- package/src/controllers/trax.controller.js +536 -111
- package/src/controllers/traxDashboard.controllers.js +18 -5
- package/src/dtos/downloadValidation.dtos.js +1 -0
- package/src/routes/activityLog.router.js +18 -0
- package/src/routes/gallery.routes.js +2 -1
- package/src/routes/mobileTrax.routes.js +1 -0
- package/src/services/camera.service.js +14 -0
package/index.js
CHANGED
|
@@ -8,5 +8,6 @@ import { downloadRouter } from './src/routes/download.router.js';
|
|
|
8
8
|
import { mobileRouter } from './src/routes/mobileTrax.routes.js';
|
|
9
9
|
import { internalTraxRouter } from './src/routes/internalTraxApi.router.js';
|
|
10
10
|
import { locusOrderRouter } from './src/routes/locus.router.js';
|
|
11
|
+
import { traxActivityLogRouter } from './src/routes/activityLog.router.js';
|
|
11
12
|
|
|
12
|
-
export { traxDashboardRouter, traxFlagRouter, traxRouter, galleryRouter, downloadRouter, mobileRouter, internalTraxRouter, locusOrderRouter };
|
|
13
|
+
export { traxDashboardRouter, traxFlagRouter, traxRouter, galleryRouter, downloadRouter, mobileRouter, internalTraxRouter, locusOrderRouter, traxActivityLogRouter };
|
package/package.json
CHANGED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// import mongoose from 'mongoose';
|
|
2
|
+
import { insertOpenSearchData, updateOpenSearchData, getOpenSearchData } from 'tango-app-api-middleware';
|
|
3
|
+
import * as checklistService from '../services/checklist.service.js';
|
|
4
|
+
import * as taskconfigService from '../services/taskConfig.service.js';
|
|
5
|
+
|
|
6
|
+
export const insertLog = async ( req, res ) => {
|
|
7
|
+
try {
|
|
8
|
+
// let currentDate = new Date();
|
|
9
|
+
// let inserttraxlogs = {
|
|
10
|
+
// 'client_id': '11',
|
|
11
|
+
// 'createAt': new Date(),
|
|
12
|
+
// 'sourceCheckList_id': '668e3e1807d5312fa49b0046',
|
|
13
|
+
// 'checkListName': 'Daily Store Checklistnafi33',
|
|
14
|
+
// 'fromCheckListName': '',
|
|
15
|
+
// 'type': 'checklist',
|
|
16
|
+
// 'action': 'updated',
|
|
17
|
+
// 'storeName': 'LKST007',
|
|
18
|
+
// 'store_id': '',
|
|
19
|
+
// 'createdByEmail': 'lkst007bc1@lenskart.co.in',
|
|
20
|
+
// 'createdBy': 'lkst007bc1',
|
|
21
|
+
// 'coverage': 'store',
|
|
22
|
+
// 'logDetails': {
|
|
23
|
+
// 'schedule': {
|
|
24
|
+
// 'previous': {
|
|
25
|
+
// 'schedule': 'repeats',
|
|
26
|
+
// // "repeats":"daily",
|
|
27
|
+
// 'time': '10:00 AM to 11:00 PM',
|
|
28
|
+
// // "occurs":[],
|
|
29
|
+
// 'scheduleRepeatedDay': [ '01' ],
|
|
30
|
+
// 'scheduleRepeatedType': 'daily',
|
|
31
|
+
// 'scheduleStartTime_iso': '2025-02-10T23:30:00.000+00:00',
|
|
32
|
+
// 'scheduleEndTime_iso': '2025-02-10T23:30:00.000+00:00',
|
|
33
|
+
// 'configStartDate': '2025-03-11T00:00:00.000+00:00',
|
|
34
|
+
// 'configEndDate': '2025-03-12T00:00:00.000+00:00',
|
|
35
|
+
// 'scheduleWeekDays': [ 'Monday', 'Tuesday' ],
|
|
36
|
+
// 'scheduleRepeatedMonthWeek': '2 Tuesday',
|
|
37
|
+
// 'specificDate': [ '10', '11' ],
|
|
38
|
+
|
|
39
|
+
// },
|
|
40
|
+
// 'new': {
|
|
41
|
+
// 'schedule': 'onetime',
|
|
42
|
+
// // "repeats":"weekly",
|
|
43
|
+
// 'time': '10:00 AM to 11:00 PM',
|
|
44
|
+
// // "occurs":["Mondy","Tuesday"],
|
|
45
|
+
// 'scheduleRepeatedDay': [ '01' ],
|
|
46
|
+
// 'scheduleRepeatedType': 'daily',
|
|
47
|
+
// 'configStartDate': '2025-03-11T00:00:00.000+00:00',
|
|
48
|
+
// 'configEndDate': '2025-03-12T00:00:00.000+00:00',
|
|
49
|
+
// 'scheduleStartTime_iso': '2025-02-10T23:30:00.000+00:00',
|
|
50
|
+
// 'scheduleEndTime_iso': '2025-02-10T23:30:00.000+00:00',
|
|
51
|
+
// 'scheduleWeekDays': [ 'Monday', 'Tuesday' ],
|
|
52
|
+
// 'scheduleRepeatedMonthWeek': '2 Tuesday',
|
|
53
|
+
// 'specificDate': [ '10', '11' ],
|
|
54
|
+
// },
|
|
55
|
+
// },
|
|
56
|
+
// 'response': {
|
|
57
|
+
// 'previous': [ 'Geo Facing', 'Allow Multiple response' ],
|
|
58
|
+
// 'new': [ 'Geo Facing 2', 'Allow Multiple response 2' ],
|
|
59
|
+
// },
|
|
60
|
+
// 'owner': {
|
|
61
|
+
// 'previous': [ 'Ajinkya Malshe' ],
|
|
62
|
+
// 'new': [ 'Ajinkya Malshe' ],
|
|
63
|
+
// },
|
|
64
|
+
// 'approver': {
|
|
65
|
+
// 'previous': [ 'raju', 'rajuapprover' ],
|
|
66
|
+
// 'new': [ 'raju 1', 'rajuapprover 2' ],
|
|
67
|
+
// },
|
|
68
|
+
// 'storeAdded': [ 'LKST011', 'LKST022', 'LKST3444', 'LKST455', 'LKST566', 'LKST666', 'LKST766', 'LKST866', 'LkST966' ],
|
|
69
|
+
// 'storeRemoved': [ 'LKST1166', 'LKST1177', 'LKST1188', 'LKST1199', 'LKST1155', 'LKST1144', 'LKST1133', 'LKST1122', 'LkST1111' ],
|
|
70
|
+
// 'userAdded': [ 'LKST011@yopmail.com', 'LKST022@yopmail.com', 'LKST3444@yopmail.com', 'LKST455@yopmail.com', 'LKST566@yopmail.com', 'LKST666@yopmail.com', 'LKST766@yopmail.com', 'LKST866@yopmail.com', 'LkST966@yopmail.com' ],
|
|
71
|
+
// 'userRemoved': [ 'LKST1166@yopmail.com', 'LKST1177@yopmail.com', 'LKST1188@yopmail.com', 'LKST1199@yopmail.com', 'LKST1155@yopmail.com', 'LKST1144@yopmail.com', 'LKST1133@yopmail.com', 'LKST1122@yopmail.com', 'LkST1111@yopmail.com' ],
|
|
72
|
+
// },
|
|
73
|
+
// };
|
|
74
|
+
|
|
75
|
+
let inserttraxlogs = {
|
|
76
|
+
client_id: '201',
|
|
77
|
+
createAt: new Date( '2025-04-21T14:43:22.603Z' ),
|
|
78
|
+
sourceCheckList_id: '68065496feb4eaeb4515cf1d',
|
|
79
|
+
checkListName: 'Ghk',
|
|
80
|
+
fromCheckListName: '',
|
|
81
|
+
type: 'checklist',
|
|
82
|
+
action: 'draft',
|
|
83
|
+
storeName: '',
|
|
84
|
+
store_id: '',
|
|
85
|
+
createdByEmail: 'praveenraju@tangotech.co.in',
|
|
86
|
+
createdBy: 'Praveen Raju',
|
|
87
|
+
coverage: 'store',
|
|
88
|
+
logDetails: {
|
|
89
|
+
schedule: {
|
|
90
|
+
previous: {
|
|
91
|
+
scheduleDateString: '28 Apr, 2025',
|
|
92
|
+
schedule: 'onetime',
|
|
93
|
+
time: '10:00 AM to 10:00 PM',
|
|
94
|
+
scheduleRepeatedDay: '',
|
|
95
|
+
scheduleRepeatedType: 'onetime',
|
|
96
|
+
scheduleWeekDays: [],
|
|
97
|
+
scheduleRepeatedMonthWeek: '',
|
|
98
|
+
specificDate: [],
|
|
99
|
+
},
|
|
100
|
+
new: {
|
|
101
|
+
scheduleDateString: '29 Apr, 2025',
|
|
102
|
+
schedule: 'onetime',
|
|
103
|
+
time: '10:00 AM to 10:00 PM',
|
|
104
|
+
scheduleRepeatedDay: '',
|
|
105
|
+
scheduleRepeatedType: 'onetime',
|
|
106
|
+
scheduleWeekDays: [],
|
|
107
|
+
scheduleRepeatedMonthWeek: '',
|
|
108
|
+
specificDate: [],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
response: { previous: [], new: [] },
|
|
112
|
+
approver: {},
|
|
113
|
+
owner: {},
|
|
114
|
+
storeAdded: [ 'test_Eye52', 'test_Eye53' ],
|
|
115
|
+
storeRemoved: [],
|
|
116
|
+
userAdded: [],
|
|
117
|
+
userRemoved: [],
|
|
118
|
+
},
|
|
119
|
+
userType: 'tango',
|
|
120
|
+
};
|
|
121
|
+
// console.log( 'inserttraxlogs =>', inserttraxlogs );
|
|
122
|
+
let insertOS = await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, inserttraxlogs );
|
|
123
|
+
console.log( 'insertOS', insertOS );
|
|
124
|
+
return res.sendSuccess( 'insert successfully' );
|
|
125
|
+
// if ( insertOS && insertOS.body.result == 'created' ) {
|
|
126
|
+
// emailersIds.push( insertOS.body._id );
|
|
127
|
+
// }
|
|
128
|
+
} catch ( e ) {
|
|
129
|
+
// logger.error( 'insertLog =>', e );
|
|
130
|
+
// console.log( 'insertLog =>', e );
|
|
131
|
+
return res.sendError( e, 500 );
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
export const updateLog = async ( req, res ) => {
|
|
135
|
+
try {
|
|
136
|
+
// console.log( 'update' );
|
|
137
|
+
const document = {
|
|
138
|
+
doc: {
|
|
139
|
+
storeName: 'LKST008',
|
|
140
|
+
// fromDate: '2025-01-13',
|
|
141
|
+
// toDate: '2025-01-19',
|
|
142
|
+
// status: 'completed',
|
|
143
|
+
// storeIds: [ '347-1' ],
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
let updateResult = await updateOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, '5DwBYZUBcRcpuflp5oek', document );
|
|
147
|
+
// console.log( 'updateResult', updateResult );
|
|
148
|
+
if ( updateResult?.statusCode == 200 && updateResult?.body?.result == 'updated' ) {
|
|
149
|
+
return res.sendSuccess( 'Email Send Successfully' );
|
|
150
|
+
} else {
|
|
151
|
+
return res.sendSuccess( 'Email Send Successfully' );
|
|
152
|
+
// return res.sendError( { error: error }, 500 );
|
|
153
|
+
}
|
|
154
|
+
} catch ( e ) {
|
|
155
|
+
logger.error( 'updateLog =>', e );
|
|
156
|
+
return res.sendError( e, 500 );
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
export const listLog = async ( req, res ) => {
|
|
160
|
+
try {
|
|
161
|
+
let requestBody = req.body;
|
|
162
|
+
let from = ( requestBody.offset ) * requestBody.limit;
|
|
163
|
+
|
|
164
|
+
let start = new Date( requestBody.fromDate );
|
|
165
|
+
let userTimezoneOffset = start.getTimezoneOffset() * 60000;
|
|
166
|
+
start = new Date( start.getTime() - userTimezoneOffset );
|
|
167
|
+
start.setUTCHours( 0, 0, 0, 0 );
|
|
168
|
+
let end = new Date( requestBody.toDate );
|
|
169
|
+
end = new Date( end.getTime() - userTimezoneOffset );
|
|
170
|
+
end.setUTCHours( 23, 59, 59, 59 );
|
|
171
|
+
|
|
172
|
+
// console.log( 'list' );
|
|
173
|
+
const mustConditions = [];
|
|
174
|
+
|
|
175
|
+
if ( requestBody.clientId ) {
|
|
176
|
+
mustConditions.push( { term: { client_id: requestBody.clientId } } );
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if ( requestBody.type ) {
|
|
180
|
+
mustConditions.push( { term: { type: requestBody.type } } );
|
|
181
|
+
}
|
|
182
|
+
if ( requestBody.action && requestBody.action.length > 0 ) {
|
|
183
|
+
mustConditions.push( { terms: { action: requestBody.action } } );
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if ( req.user.userType == 'client' && req.user.role == 'user' ) {
|
|
187
|
+
return res.sendError( 'no data found', 204 );
|
|
188
|
+
}
|
|
189
|
+
let sourceCheckListIds;
|
|
190
|
+
if ( req.user.userType === 'client' && req.user.role == 'admin' ) {
|
|
191
|
+
if ( requestBody.type === 'checklist' ) {
|
|
192
|
+
const sourceCheckListResult = await checklistService.aggregate( [
|
|
193
|
+
// { $match: { 'owner.value': req.user.email } },
|
|
194
|
+
{ $match: { $or: [ { 'owner.value': req.user.email }, { 'approver.value': req.user.email } ] } },
|
|
195
|
+
{ $group: { _id: null, checklistIds: { $push: { $toString: '$_id' } } } },
|
|
196
|
+
{ $project: { _id: 0, checklistIds: 1 } },
|
|
197
|
+
] );
|
|
198
|
+
sourceCheckListIds = sourceCheckListResult.length > 0 ? sourceCheckListResult[0].checklistIds : [];
|
|
199
|
+
// console.log( 'sourceCheckListIds', sourceCheckListIds );
|
|
200
|
+
}
|
|
201
|
+
if ( requestBody.type === 'task' ) {
|
|
202
|
+
const sourceCheckListResult = await taskconfigService.aggregate( [
|
|
203
|
+
{ $match: { createdBy: req.user._id } },
|
|
204
|
+
// { $match: { $or: [ { 'owner.value': req.user.email }, { 'approver.value': req.user.email } ] } },
|
|
205
|
+
{ $group: { _id: null, checklistIds: { $push: { $toString: '$_id' } } } },
|
|
206
|
+
{ $project: { _id: 0, checklistIds: 1 } },
|
|
207
|
+
] );
|
|
208
|
+
sourceCheckListIds = sourceCheckListResult.length > 0 ? sourceCheckListResult[0].checklistIds : [];
|
|
209
|
+
// console.log( 'sourceCheckListIds', sourceCheckListIds );
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// mustConditions.push( { terms: { $or: [ { store_id: { $in: requestBody.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestBody.userEmailes } }, { sourceCheckList_id: { $in: sourceCheckListIds } } ] } } );
|
|
213
|
+
mustConditions.push( {
|
|
214
|
+
'bool': {
|
|
215
|
+
'should': [
|
|
216
|
+
{ 'terms': { 'store_id': requestBody.storeId } },
|
|
217
|
+
{
|
|
218
|
+
'bool': {
|
|
219
|
+
'must': [
|
|
220
|
+
{ 'term': { 'store_id': '' } },
|
|
221
|
+
{ 'terms': { 'userEmail': requestBody.userEmailes } },
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
{ 'terms': { 'sourceCheckList_id': sourceCheckListIds.map( String ) } },
|
|
226
|
+
],
|
|
227
|
+
'minimum_should_match': 1,
|
|
228
|
+
},
|
|
229
|
+
} );
|
|
230
|
+
}
|
|
231
|
+
if ( req.user.userType === 'client' ) {
|
|
232
|
+
mustConditions.push( {
|
|
233
|
+
term: { userType: 'client' },
|
|
234
|
+
} );
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
if ( requestBody.searchValue ) {
|
|
239
|
+
mustConditions.push( { multi_match: {
|
|
240
|
+
'query': requestBody.searchValue,
|
|
241
|
+
'fields': [ 'checkListName', 'storeName', 'createdByEmail' ],
|
|
242
|
+
'type': 'phrase_prefix',
|
|
243
|
+
},
|
|
244
|
+
} );
|
|
245
|
+
}
|
|
246
|
+
// console.log( 'Generated Query:', JSON.stringify( mustConditions, null, 2 ) );
|
|
247
|
+
|
|
248
|
+
// console.log( 'mustConditions =>', mustConditions );
|
|
249
|
+
if ( requestBody.fromDate && requestBody.toDate ) {
|
|
250
|
+
mustConditions.push( {
|
|
251
|
+
range: {
|
|
252
|
+
createAt: {
|
|
253
|
+
gte: start, // Start date
|
|
254
|
+
lte: end, // End date
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
} );
|
|
258
|
+
}
|
|
259
|
+
let sortCreatedAt = 'desc';
|
|
260
|
+
if ( requestBody.sortColumnName && requestBody.sortColumnName != '' ) {
|
|
261
|
+
if ( requestBody.sortBy == '1' ) {
|
|
262
|
+
sortCreatedAt = 'asc';
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
let query = {
|
|
266
|
+
from: parseInt( from ),
|
|
267
|
+
size: parseInt( requestBody.limit ),
|
|
268
|
+
track_total_hits: true,
|
|
269
|
+
query: {
|
|
270
|
+
bool: {
|
|
271
|
+
must: mustConditions,
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
sort: [
|
|
275
|
+
{
|
|
276
|
+
createAt: {
|
|
277
|
+
order: sortCreatedAt,
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
'_doc',
|
|
281
|
+
],
|
|
282
|
+
};
|
|
283
|
+
// console.log( 'Executing OpenSearch Query:', JSON.stringify( query, null, 2 ) );
|
|
284
|
+
let result = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, query );
|
|
285
|
+
// console.log( 'OpenSearch Raw Response', JSON.stringify( result, null, 2 ) );
|
|
286
|
+
if ( !result || !result.body.hits.hits.length ) {
|
|
287
|
+
return res.sendError( 'no data found', 204 );
|
|
288
|
+
}
|
|
289
|
+
return res.sendSuccess( { count: result.body.hits.total.value, result: result.body.hits.hits } );
|
|
290
|
+
} catch ( e ) {
|
|
291
|
+
// console.log( 'listLog', e );
|
|
292
|
+
return res.sendError( e, 500 );
|
|
293
|
+
}
|
|
294
|
+
};
|
|
@@ -559,6 +559,8 @@ export const getChecklistFromZipId = async ( req, res ) => {
|
|
|
559
559
|
resultData.questions = getzipdata.questions;
|
|
560
560
|
resultData.insertType = getzipdata.insertType;
|
|
561
561
|
resultData.status = getzipdata.status;
|
|
562
|
+
resultData.fromDate = getzipdata.fromDate;
|
|
563
|
+
resultData.toDate = getzipdata.toDate;
|
|
562
564
|
return res.sendSuccess( resultData );
|
|
563
565
|
}
|
|
564
566
|
} else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { logger } from 'tango-app-api-middleware';
|
|
3
|
+
import { logger, insertOpenSearchData } from 'tango-app-api-middleware';
|
|
4
4
|
import * as storeService from '../services/store.service.js';
|
|
5
5
|
import * as groupService from '../services/group.service.js';
|
|
6
6
|
import * as clusterService from '../services/cluster.service.js';
|
|
@@ -14,6 +14,12 @@ import dayjs from 'dayjs';
|
|
|
14
14
|
import { aggregateTeams, findteams } from '../services/teams.service.js';
|
|
15
15
|
import { aggregate } from '../services/user.service.js';
|
|
16
16
|
// import axios from 'axios';
|
|
17
|
+
import timeZone from 'dayjs/plugin/timezone.js';
|
|
18
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
19
|
+
|
|
20
|
+
dayjs.extend( customParseFormat );
|
|
21
|
+
dayjs.extend( timeZone );
|
|
22
|
+
|
|
17
23
|
async function LamdaServiceCall( url, data ) {
|
|
18
24
|
try {
|
|
19
25
|
const requestOptions = {
|
|
@@ -282,15 +288,24 @@ export async function approveChecklist( req, res ) {
|
|
|
282
288
|
if ( req.body?.storeId?.length ) {
|
|
283
289
|
query['store_id'] = { $in: req.body.storeId };
|
|
284
290
|
}
|
|
285
|
-
let checklistDetails = await processedChecklist.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1 } );
|
|
291
|
+
let checklistDetails = await processedChecklist.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1, client_id: 1, coverage: 1, checkListName: 1 } );
|
|
286
292
|
if ( !checklistDetails.length ) {
|
|
287
293
|
return res.sendError( 'No data found', 204 );
|
|
288
294
|
}
|
|
289
295
|
let idList = checklistDetails.filter( ( ele ) => ele.checklistStatus == 'submit' ).map( ( item ) => item._id );
|
|
290
296
|
if ( idList.length ) {
|
|
291
|
-
let
|
|
297
|
+
let approvalUpdateData = {
|
|
298
|
+
approvalStatus: true,
|
|
299
|
+
approvalTime: new Date(),
|
|
300
|
+
// approvalTime_string: dayjs().format( 'hh:mm A, DD MMM YYYY' ),
|
|
301
|
+
approvalTime_string: dayjs().tz( 'Asia/Kolkata' ).format( 'hh:mm A, DD MMM YYYY' ),
|
|
302
|
+
approvalByName: req.user.userName,
|
|
303
|
+
approvalByEmail: req.user.email,
|
|
304
|
+
};
|
|
305
|
+
let updateResponse = await processedChecklist.updateMany( { _id: { $in: idList } }, approvalUpdateData );
|
|
292
306
|
if ( updateResponse.modifiedCount || updateResponse.matchedCount ) {
|
|
293
307
|
let inputstores = checklistDetails.filter( ( data ) => data.checklistStatus == 'submit' );
|
|
308
|
+
let storeNames = inputstores.map( ( data ) => data.storeName );
|
|
294
309
|
|
|
295
310
|
|
|
296
311
|
let params = {
|
|
@@ -303,6 +318,10 @@ export async function approveChecklist( req, res ) {
|
|
|
303
318
|
},
|
|
304
319
|
'upsert': {
|
|
305
320
|
approvalStatus: true,
|
|
321
|
+
approvalTime: new Date(),
|
|
322
|
+
approvalTime_string: dayjs().tz( 'Asia/Kolkata' ).format( 'hh:mm A, DD MMM YYYY' ),
|
|
323
|
+
approvalByName: req.user.userName,
|
|
324
|
+
approvalByEmail: req.user.email,
|
|
306
325
|
},
|
|
307
326
|
};
|
|
308
327
|
|
|
@@ -315,7 +334,27 @@ export async function approveChecklist( req, res ) {
|
|
|
315
334
|
};
|
|
316
335
|
let url = JSON.parse( process.env.LAMBDAURL );
|
|
317
336
|
let searchResponse = await fetch( url.approveChecklist, requestOptions );
|
|
318
|
-
|
|
337
|
+
let logData= {
|
|
338
|
+
'client_id': checklistDetails[0].client_id,
|
|
339
|
+
'createAt': new Date(),
|
|
340
|
+
'sourceCheckList_id': req.body.sourceCheckList_id,
|
|
341
|
+
'checkListName': checklistDetails[0].checkListName,
|
|
342
|
+
'fromCheckListName': '',
|
|
343
|
+
'type': 'checklist',
|
|
344
|
+
'action': 'approved',
|
|
345
|
+
'storeName': '',
|
|
346
|
+
'store_id': '',
|
|
347
|
+
'createdByEmail': req.user.email,
|
|
348
|
+
'createdBy': req.user._id,
|
|
349
|
+
'coverage': checklistDetails[0].coverage,
|
|
350
|
+
'logDetails': {
|
|
351
|
+
'approved': storeNames,
|
|
352
|
+
},
|
|
353
|
+
'userType': req.user.userType,
|
|
354
|
+
};
|
|
355
|
+
console.log( 'logData', logData );
|
|
356
|
+
let urlopensearch = JSON.parse( process.env.OPENSEARCH );
|
|
357
|
+
insertOpenSearchData( urlopensearch.traxActivityLog, logData );
|
|
319
358
|
console.log( searchResponse.ok );
|
|
320
359
|
if ( searchResponse.ok ) {
|
|
321
360
|
let pendingstores = checklistDetails.filter( ( data ) => data.checklistStatus != 'submit' );
|
|
@@ -332,6 +371,7 @@ export async function approveChecklist( req, res ) {
|
|
|
332
371
|
return res.sendError( `${redoList.length} stores has not been approved since those stores are not submitted`, 400 );
|
|
333
372
|
}
|
|
334
373
|
} catch ( e ) {
|
|
374
|
+
// console.log( 'e', e );
|
|
335
375
|
logger.error( { function: 'approveChecklist', error: e } );
|
|
336
376
|
return res.sendError( e, 500 );
|
|
337
377
|
}
|
|
@@ -350,7 +390,7 @@ export async function redoChecklist( req, res ) {
|
|
|
350
390
|
}
|
|
351
391
|
|
|
352
392
|
|
|
353
|
-
let checklistDetails = await processedChecklist.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1 } );
|
|
393
|
+
let checklistDetails = await processedChecklist.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1, coverage: 1, userEmail: 1 } );
|
|
354
394
|
if ( !checklistDetails ) {
|
|
355
395
|
return res.sendError( 'No data found', 204 );
|
|
356
396
|
}
|
|
@@ -440,7 +480,27 @@ export async function redoChecklist( req, res ) {
|
|
|
440
480
|
let url = JSON.parse( process.env.LAMBDAURL );
|
|
441
481
|
let searchResponse = await fetch( url.redoChecklist, requestOptions );
|
|
442
482
|
console.log( searchResponse.ok );
|
|
443
|
-
|
|
483
|
+
let logData= {
|
|
484
|
+
'client_id': checklistDetails.client_id,
|
|
485
|
+
'createAt': new Date(),
|
|
486
|
+
'sourceCheckList_id': checklistDetails.sourceCheckList_id,
|
|
487
|
+
'checkListName': checklistDetails.checkListName,
|
|
488
|
+
'fromCheckListName': checklistDetails.checkListName,
|
|
489
|
+
'type': 'checklist',
|
|
490
|
+
'action': checklistDetails.redoStatus?'multiredo': 'redo',
|
|
491
|
+
'storeName': checklistDetails?.storeName?checklistDetails?.storeName:'',
|
|
492
|
+
'store_id': checklistDetails?.store_id?checklistDetails?.store_id:'',
|
|
493
|
+
'userName': checklistDetails.userName,
|
|
494
|
+
'userEmail': checklistDetails.userEmail,
|
|
495
|
+
'createdByEmail': req.user.email,
|
|
496
|
+
'createdBy': req.user.userName,
|
|
497
|
+
'coverage': checklistDetails.coverage,
|
|
498
|
+
'logDetails': {},
|
|
499
|
+
'userType': req.user.userType,
|
|
500
|
+
};
|
|
501
|
+
let urlopensearch = JSON.parse( process.env.OPENSEARCH );
|
|
502
|
+
console.log( 'logData', logData );
|
|
503
|
+
insertOpenSearchData( urlopensearch.traxActivityLog, logData );
|
|
444
504
|
if ( searchResponse.ok ) {
|
|
445
505
|
return res.sendSuccess( 'Question redo successfully' );
|
|
446
506
|
} else {
|
|
@@ -455,6 +515,150 @@ export async function redoChecklist( req, res ) {
|
|
|
455
515
|
}
|
|
456
516
|
}
|
|
457
517
|
|
|
518
|
+
export async function redomultiChecklist( req, res ) {
|
|
519
|
+
try {
|
|
520
|
+
let inputData = req.body.payload.coverage==='user'?req.body.payload.userEmail:req.body.payload.storeName;
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
for ( let originalData of inputData ) {
|
|
524
|
+
if ( !originalData.checklistId ) {
|
|
525
|
+
return res.sendError( 'Id is Required', 400 );
|
|
526
|
+
}
|
|
527
|
+
if ( !originalData.section_id ) {
|
|
528
|
+
return res.sendError( 'Section id is Required', 400 );
|
|
529
|
+
}
|
|
530
|
+
if ( !req.body.payload.qno ) {
|
|
531
|
+
return res.sendError( 'Question number is Required', 400 );
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
let checklistDetails = await processedChecklist.findOne( { _id: originalData.checklistId }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1 } );
|
|
536
|
+
if ( !checklistDetails ) {
|
|
537
|
+
return res.sendError( 'No data found', 204 );
|
|
538
|
+
}
|
|
539
|
+
let question = checklistDetails.questionAnswers;
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
let sectionIndex = question.findIndex( ( sec ) => sec.sectionName == req.body.payload.sectionName );
|
|
543
|
+
if ( sectionIndex == -1 ) {
|
|
544
|
+
return res.sendError( 'section is not found', 400 );
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.payload.qno );
|
|
548
|
+
|
|
549
|
+
let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
|
|
550
|
+
// if ( checklistDetails.client_id == '458' ) {
|
|
551
|
+
data.answers.forEach( ( item ) => {
|
|
552
|
+
if ( item.showLinked ) {
|
|
553
|
+
item.nestedQuestion.forEach( ( ele ) => {
|
|
554
|
+
let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
|
|
555
|
+
let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
|
|
556
|
+
question[sectionIndex].questions[eleIndex] = element;
|
|
557
|
+
question[sectionIndex].questions[eleIndex].userAnswer = [];
|
|
558
|
+
question[sectionIndex].questions[eleIndex].remarks = '';
|
|
559
|
+
} );
|
|
560
|
+
}
|
|
561
|
+
} );
|
|
562
|
+
// data.answers.forEach( ( item ) => {
|
|
563
|
+
// if ( item.showLinked ) {
|
|
564
|
+
// item.nestedQuestion = [];
|
|
565
|
+
// item.showLinked = false;
|
|
566
|
+
// item.linkedQuestion = 0;
|
|
567
|
+
// }
|
|
568
|
+
// } );
|
|
569
|
+
// }
|
|
570
|
+
let userAnswer = data.userAnswer;
|
|
571
|
+
|
|
572
|
+
question[sectionIndex].questions[findQuestion] = data;
|
|
573
|
+
question[sectionIndex].questions[findQuestion].userAnswer = [];
|
|
574
|
+
question[sectionIndex].questions[findQuestion].remarks = '';
|
|
575
|
+
checklistDetails.questionAnswers = question;
|
|
576
|
+
let updateData = {
|
|
577
|
+
checklistStatus: 'open',
|
|
578
|
+
redoStatus: true,
|
|
579
|
+
reinitiateStatus: true,
|
|
580
|
+
questionAnswers: question,
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
let response = await processedChecklist.updateOne( { _id: originalData.checklistId }, updateData );
|
|
584
|
+
console.log( response );
|
|
585
|
+
if ( response.modifiedCount || response.matchedCount ) {
|
|
586
|
+
let storeTimeZone = await storeService.findOne( { storeName: checklistDetails.storeName }, { 'storeProfile.timeZone': 1 } );
|
|
587
|
+
let currentDateTime;
|
|
588
|
+
if ( storeTimeZone?.storeProfile?.timeZone ) {
|
|
589
|
+
currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
|
|
590
|
+
} else {
|
|
591
|
+
currentDateTime = dayjs();
|
|
592
|
+
}
|
|
593
|
+
data = {
|
|
594
|
+
checklistId: checklistDetails.sourceCheckList_id,
|
|
595
|
+
checkListName: checklistDetails.checkListName,
|
|
596
|
+
checklistDescription: req.body.payload.checklistDescription,
|
|
597
|
+
sectionId: originalData.section_id,
|
|
598
|
+
sectionName: question[sectionIndex].sectionName,
|
|
599
|
+
questionName: question[sectionIndex].questions[findQuestion].qname,
|
|
600
|
+
action: 'redo',
|
|
601
|
+
store_id: checklistDetails?.store_id?checklistDetails?.store_id:'',
|
|
602
|
+
storeName: checklistDetails?.storeName?checklistDetails?.storeName:'',
|
|
603
|
+
client_id: checklistDetails.client_id,
|
|
604
|
+
processedChecklistId: checklistDetails._id,
|
|
605
|
+
type: checklistDetails.checkListType,
|
|
606
|
+
userAnswer: userAnswer,
|
|
607
|
+
initiatedBy: req.user.userName,
|
|
608
|
+
initiatedTime: dayjs.utc( currentDateTime.format( 'hh:mm:ss A, DD MMM YYYY' ), 'hh:mm:ss A, DD MMM YYYY' ).format(),
|
|
609
|
+
answerType: question[sectionIndex].questions[findQuestion].answerType,
|
|
610
|
+
submitedBy: checklistDetails.userName,
|
|
611
|
+
submitTime: checklistDetails.submitTime,
|
|
612
|
+
};
|
|
613
|
+
await checklistLogs.create( data );
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
req.body.payload._id=originalData.checklistId;
|
|
617
|
+
req.body.payload.section_id=originalData.section_id;
|
|
618
|
+
req.body.payload.uniqueNo=originalData.uniqueNo;
|
|
619
|
+
console.log( req.body );
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
const requestOptions = {
|
|
623
|
+
method: 'POST',
|
|
624
|
+
headers: {
|
|
625
|
+
'Content-Type': 'application/json',
|
|
626
|
+
},
|
|
627
|
+
body: JSON.stringify( req.body ),
|
|
628
|
+
};
|
|
629
|
+
let url = JSON.parse( process.env.LAMBDAURL );
|
|
630
|
+
let searchResponse = await fetch( url.redoChecklist, requestOptions );
|
|
631
|
+
console.log( searchResponse.ok );
|
|
632
|
+
let logData= {
|
|
633
|
+
'client_id': checklistDetails.client_id,
|
|
634
|
+
'createAt': new Date(),
|
|
635
|
+
'sourceCheckList_id': checklistDetails.sourceCheckList_id,
|
|
636
|
+
'checkListName': checklistDetails.checkListName,
|
|
637
|
+
'fromCheckListName': checklistDetails.checkListName,
|
|
638
|
+
'type': 'checklist',
|
|
639
|
+
'action': checklistDetails.redoStatus?'multiredo': 'redo',
|
|
640
|
+
'storeName': checklistDetails?.storeName?checklistDetails?.storeName:'',
|
|
641
|
+
'store_id': checklistDetails?.store_id?checklistDetails?.store_id:'',
|
|
642
|
+
'userName': checklistDetails.userName,
|
|
643
|
+
'userEmail': checklistDetails.userEmail,
|
|
644
|
+
'createdByEmail': req.user.email,
|
|
645
|
+
'createdBy': req.user.userName,
|
|
646
|
+
'coverage': checklistDetails.coverage,
|
|
647
|
+
'logDetails': {},
|
|
648
|
+
'userType': req.user.userType,
|
|
649
|
+
};
|
|
650
|
+
let urlopensearch = JSON.parse( process.env.OPENSEARCH );
|
|
651
|
+
console.log( 'logData', logData );
|
|
652
|
+
insertOpenSearchData( urlopensearch.traxActivityLog, logData );
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return res.sendSuccess( 'Question redo successfully' );
|
|
656
|
+
} catch ( e ) {
|
|
657
|
+
logger.error( { function: 'redomultiChecklist', error: e } );
|
|
658
|
+
return res.sendError( e, 500 );
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
458
662
|
|
|
459
663
|
export async function getLogs( req, res ) {
|
|
460
664
|
try {
|