tango-app-api-trax 1.0.0-task.127 → 1.0.0-task.128
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/package.json
CHANGED
|
@@ -6,6 +6,10 @@ import * as groupService from '../services/group.service.js';
|
|
|
6
6
|
import * as processedchecklistconfigService from '../services/processedchecklistconfig.services.js';
|
|
7
7
|
import * as processedChecklist from '../services/processedchecklist.services.js';
|
|
8
8
|
import * as checklistLogs from '../services/checklistlog.service.js';
|
|
9
|
+
import * as ApproverModel from '../services/approver.service.js';
|
|
10
|
+
|
|
11
|
+
import mongoose from 'mongoose';
|
|
12
|
+
import dayjs from 'dayjs';
|
|
9
13
|
// import axios from 'axios';
|
|
10
14
|
async function LamdaServiceCall( url, data ) {
|
|
11
15
|
try {
|
|
@@ -122,16 +126,12 @@ export async function getcustomerunattendedlist( req, res ) {
|
|
|
122
126
|
|
|
123
127
|
export async function storesList( req, res ) {
|
|
124
128
|
try {
|
|
125
|
-
console.log( req.body );
|
|
126
|
-
|
|
127
129
|
let storeslist = await storeService.find( { clientId: req.body.clientId }, { storeId: 1, storeName: 1 } );
|
|
128
130
|
if ( req.body.groups&&req.body.groups.length>0 ) {
|
|
129
131
|
let stores = [];
|
|
130
132
|
for ( let group of req.body.groups ) {
|
|
131
133
|
let findGroup = await groupService.findOneGroup( { groupName: group.groupName }, { storeList: 1 } );
|
|
132
|
-
console.log( findGroup );
|
|
133
134
|
stores = [ ...stores, ...findGroup.storeList ];
|
|
134
|
-
console.log( stores );
|
|
135
135
|
}
|
|
136
136
|
let storeslist = await storeService.find( { storeId: { $in: stores } }, { storeId: 1, storeName: 1 } );
|
|
137
137
|
return res.sendSuccess( { result: storeslist } );
|
|
@@ -286,8 +286,9 @@ export async function approveChecklist( req, res ) {
|
|
|
286
286
|
},
|
|
287
287
|
body: JSON.stringify( params ),
|
|
288
288
|
};
|
|
289
|
-
let
|
|
290
|
-
|
|
289
|
+
let url = JSON.parse( process.env.LAMBDAURL );
|
|
290
|
+
let searchResponse = await fetch( url.approveChecklist, requestOptions );
|
|
291
|
+
|
|
291
292
|
|
|
292
293
|
if ( searchResponse.ok ) {
|
|
293
294
|
return res.sendSuccess( 'Checklist Approved successfully' );
|
|
@@ -313,17 +314,23 @@ export async function redoChecklist( req, res ) {
|
|
|
313
314
|
return res.sendError( 'Question number is Required', 400 );
|
|
314
315
|
}
|
|
315
316
|
|
|
316
|
-
|
|
317
|
+
|
|
318
|
+
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 } );
|
|
317
319
|
if ( !checklistDetails ) {
|
|
318
320
|
return res.sendError( 'No data found', 204 );
|
|
319
321
|
}
|
|
320
322
|
let question = checklistDetails.questionAnswers;
|
|
323
|
+
|
|
324
|
+
|
|
321
325
|
let sectionIndex = question.findIndex( ( sec ) => sec.section_id == req.body.payload.section_id );
|
|
322
326
|
if ( sectionIndex == -1 ) {
|
|
323
327
|
return res.sendError( 'section is not found', 400 );
|
|
324
328
|
}
|
|
329
|
+
|
|
325
330
|
let data = { ...question[sectionIndex].questions[req.body.payload.qno - 1], redo: true };
|
|
326
331
|
let userAnswer = data.userAnswer;
|
|
332
|
+
|
|
333
|
+
|
|
327
334
|
question[sectionIndex].questions[req.body.payload.qno - 1] = data;
|
|
328
335
|
question[sectionIndex].questions[req.body.payload.qno - 1].userAnswer = [];
|
|
329
336
|
checklistDetails.questionAnswers = question;
|
|
@@ -338,6 +345,7 @@ export async function redoChecklist( req, res ) {
|
|
|
338
345
|
data = {
|
|
339
346
|
checklistId: checklistDetails.sourceCheckList_id,
|
|
340
347
|
checkListName: checklistDetails.checkListName,
|
|
348
|
+
checklistDescription: req.body.payload.checklistDescription,
|
|
341
349
|
sectionId: req.body.payload.section_id,
|
|
342
350
|
sectionName: question[sectionIndex].sectionName,
|
|
343
351
|
questionName: question[sectionIndex].questions[req.body.payload.qno - 1].qname,
|
|
@@ -348,8 +356,16 @@ export async function redoChecklist( req, res ) {
|
|
|
348
356
|
processedChecklistId: checklistDetails._id,
|
|
349
357
|
type: checklistDetails.checkListType,
|
|
350
358
|
userAnswer: userAnswer,
|
|
359
|
+
initiatedBy: req.user.userName,
|
|
360
|
+
initiatedTime: dayjs().format(),
|
|
361
|
+
answerType: question[sectionIndex].questions[req.body.payload.qno - 1].answerType,
|
|
362
|
+
submitedBy: checklistDetails.userName,
|
|
363
|
+
submitTime: checklistDetails.submitTime,
|
|
351
364
|
};
|
|
365
|
+
|
|
366
|
+
// return;
|
|
352
367
|
await checklistLogs.create( data );
|
|
368
|
+
|
|
353
369
|
const requestOptions = {
|
|
354
370
|
method: 'POST',
|
|
355
371
|
headers: {
|
|
@@ -357,8 +373,9 @@ export async function redoChecklist( req, res ) {
|
|
|
357
373
|
},
|
|
358
374
|
body: JSON.stringify( req.body ),
|
|
359
375
|
};
|
|
360
|
-
let
|
|
361
|
-
|
|
376
|
+
let url = JSON.parse( process.env.LAMBDAURL );
|
|
377
|
+
let searchResponse = await fetch( url.redoChecklist, requestOptions );
|
|
378
|
+
|
|
362
379
|
|
|
363
380
|
if ( searchResponse.ok ) {
|
|
364
381
|
return res.sendSuccess( 'Question redo successfully' );
|
|
@@ -375,3 +392,66 @@ export async function redoChecklist( req, res ) {
|
|
|
375
392
|
}
|
|
376
393
|
|
|
377
394
|
|
|
395
|
+
export async function getLogs( req, res ) {
|
|
396
|
+
try {
|
|
397
|
+
let result = await checklistLogs.find( {
|
|
398
|
+
checklistId: new mongoose.Types.ObjectId( req.body.checklistId ),
|
|
399
|
+
processedChecklistId: new mongoose.Types.ObjectId( req.body.processedChecklistId ),
|
|
400
|
+
sectionId: new mongoose.Types.ObjectId( req.body.section_id ),
|
|
401
|
+
questionName: req.body.qname,
|
|
402
|
+
action: 'redo',
|
|
403
|
+
} );
|
|
404
|
+
|
|
405
|
+
let response =[];
|
|
406
|
+
for ( let data of result ) {
|
|
407
|
+
let userAnswer = {
|
|
408
|
+
actionType: 'answer',
|
|
409
|
+
userName: data.submitedBy,
|
|
410
|
+
Timestamp: data.submitTime,
|
|
411
|
+
userAnswer: data.userAnswer,
|
|
412
|
+
answerType: data.answerType,
|
|
413
|
+
};
|
|
414
|
+
let initiatedstatus = {
|
|
415
|
+
actionType: 'initation',
|
|
416
|
+
userName: data.initiatedBy,
|
|
417
|
+
Timestamp: data.initiatedTime,
|
|
418
|
+
description: data.checklistDescription,
|
|
419
|
+
|
|
420
|
+
};
|
|
421
|
+
response.push( initiatedstatus );
|
|
422
|
+
response.push( userAnswer );
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
res.sendSuccess( response );
|
|
427
|
+
} catch ( e ) {
|
|
428
|
+
logger.error( { function: 'getLogs', error: e } );
|
|
429
|
+
return res.sendError( e, 500 );
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
export async function approvalstatus( req, res ) {
|
|
435
|
+
try {
|
|
436
|
+
let Approver = await ApproverModel.findOne( { checkListId: req.body.checklistId } );
|
|
437
|
+
if ( !Approver||Approver&&Approver.email!=req.user.email ) {
|
|
438
|
+
return res.sendError( 'No Content', 204 );
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
let url = JSON.parse( process.env.LAMBDAURL );
|
|
443
|
+
let resultData = await LamdaServiceCall( url.approvalstatus, req.body );
|
|
444
|
+
if ( resultData ) {
|
|
445
|
+
if ( resultData.status_code == '200' ) {
|
|
446
|
+
return res.sendSuccess( resultData );
|
|
447
|
+
} else {
|
|
448
|
+
return res.sendError( 'No Content', 204 );
|
|
449
|
+
}
|
|
450
|
+
} else {
|
|
451
|
+
return res.sendError( 'No Content', 204 );
|
|
452
|
+
}
|
|
453
|
+
} catch ( error ) {
|
|
454
|
+
logger.error( error, 'approvalstatus' );
|
|
455
|
+
return res.sendError( error, 500 );
|
|
456
|
+
}
|
|
457
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { getchecklist, viewchecklist, getMobileUseagelist, storeOpencloselist, getcustomerunattendedlist, storesList, checklistDropdown, redoChecklist, approveChecklist } from '../controllers/gallery.controller.js';
|
|
3
|
+
import { getchecklist, viewchecklist, getMobileUseagelist, storeOpencloselist, getcustomerunattendedlist, storesList, checklistDropdown, redoChecklist, approveChecklist, approvalstatus, getLogs } from '../controllers/gallery.controller.js';
|
|
4
4
|
import express from 'express';
|
|
5
5
|
export const galleryRouter = express.Router();
|
|
6
6
|
import { isAllowedSessionHandler } from 'tango-app-api-middleware';
|
|
@@ -23,4 +23,6 @@ galleryRouter
|
|
|
23
23
|
|
|
24
24
|
galleryRouter
|
|
25
25
|
.post( '/updateApprove', isAllowedSessionHandler, approveChecklist )
|
|
26
|
-
.post( '/redo', isAllowedSessionHandler, redoChecklist )
|
|
26
|
+
.post( '/redo', isAllowedSessionHandler, redoChecklist )
|
|
27
|
+
.post( '/approvalstatus', isAllowedSessionHandler, approvalstatus )
|
|
28
|
+
.post( '/getLogs', isAllowedSessionHandler, getLogs );
|
|
@@ -15,3 +15,6 @@ export const insertMany = async ( data = [] ) => {
|
|
|
15
15
|
export const find = async ( query ={}, field={} ) => {
|
|
16
16
|
return model.traxApproverModel.find( query, field );
|
|
17
17
|
};
|
|
18
|
+
export const findOne = async ( query ={}, field={} ) => {
|
|
19
|
+
return model.traxApproverModel.findOne( query, field );
|
|
20
|
+
};
|