tango-app-api-trax 3.7.13-qid-halfshutter-8 → 3.7.13-qid-halfshutter-10

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.
@@ -1,6 +1,7 @@
1
1
  import express from 'express';
2
2
  import * as mobileController from '../controllers/mobileTrax.controller.js';
3
3
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
4
+ import { sopMobilechecklistSectionValidator } from '../validators/mobileChecklistSection.validator.js';
4
5
  import { dashboardValidation, mobileChecklistValidation, startValidation } from '../dtos/validation.dtos.js';
5
6
 
6
7
  export const mobileRouter = express.Router();
@@ -12,6 +13,8 @@ mobileRouter
12
13
  .post( '/startTask', isAllowedSessionHandler, validate( startValidation ), mobileController.startTask )
13
14
  .post( '/submitCheckList', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidator, mobileController.sopMobilechecklistMultiSectionFormatter, mobileController.submitChecklist )
14
15
  .post( '/submitCheckListv5', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidatorv1, mobileController.sopMobilechecklistMultiSectionFormatterv1, mobileController.submitChecklist )
16
+ // For v6 we run formatter first to normalize partial section payloads, then a V6 validator that validates merged checklist on final submit
17
+ .post( '/submitCheckListv6', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistMultiSectionFormatterv1, sopMobilechecklistSectionValidator, mobileController.sopMobilechecklistQuestionValidatorV6, mobileController.submitChecklistV6 )
15
18
  .post( '/submitTask', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobileTaskQuestionValidator, mobileController.sopMobileTaskMultiSectionFormatter, mobileController.submitTask )
16
19
  .post( '/submiteyeTestTask', isAllowedSessionHandler, mobileController.submiteyeTestTask )
17
20
  .get( '/dashboard', isAllowedSessionHandler, validate( dashboardValidation ), mobileController.dashboard )
@@ -29,6 +32,5 @@ mobileRouter
29
32
  .post( '/checkUpdateVersion', mobileController.checkVersion )
30
33
  .post( '/checkUpdateVersionv1', mobileController.checkVersionV1 )
31
34
  .post( '/checkClientConfig', isAllowedSessionHandler, mobileController.clientConfig )
32
- .post( '/updatePlanoStatus', isAllowedSessionHandler, mobileController.updatePlanoStatus )
33
- .post( '/chunkUpload', isAllowedSessionHandler, mobileController.chunkUpload );
35
+ .post( '/updatePlanoStatus', isAllowedSessionHandler, mobileController.updatePlanoStatus );
34
36
 
@@ -0,0 +1,43 @@
1
+ import { logger } from 'tango-app-api-middleware';
2
+
3
+ export async function sopMobilechecklistSectionValidator( req, res, next ) {
4
+ try {
5
+ let requestData = req.body;
6
+ requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
7
+ const reqAnswers = requestData.questionAnswers;
8
+
9
+ if ( !Array.isArray( reqAnswers ) || !reqAnswers.length ) return next();
10
+
11
+ // ensure each section required fields are present.
12
+ for ( const section of reqAnswers ) {
13
+ if ( !section || !Array.isArray( section.questions ) ) continue;
14
+ for ( const question of section.questions ) {
15
+ try {
16
+ // Types that expect array of answers
17
+ if ( [ 'multiplechoicemultiple', 'multipleImage' ].includes( question.answerType ) ) {
18
+ if ( !question.userAnswer || ( Array.isArray( question.userAnswer ) && question.userAnswer.length === 0 ) ) {
19
+ return res.sendError( 'Please Fill All Fields', 400 );
20
+ }
21
+ } else {
22
+ // other types: expect at least one userAnswer entry
23
+ if ( !question.userAnswer || !question.userAnswer.length ) {
24
+ // If question has linkType enabled, ensure answer present as well
25
+ if ( question.linkType && question.linkquestionenabled ) {
26
+ return res.sendError( 'Please Fill All Fields', 400 );
27
+ }
28
+ return res.sendError( 'Please Fill All Fields', 400 );
29
+ }
30
+ }
31
+ } catch ( e ) {
32
+ logger.error( { function: 'sopMobilechecklistSectionValidator', error: e, body: req.body } );
33
+ return res.sendError( e, 500 );
34
+ }
35
+ }
36
+ }
37
+ console.log( 'sopMobilechecklistSectionValidator passed' );
38
+ return next();
39
+ } catch ( error ) {
40
+ logger.error( { function: 'sopMobilechecklistSectionValidator', error, body: req.body } );
41
+ return res.sendError( error, 500 );
42
+ }
43
+ }