tango-app-api-audit 3.5.22 → 3.5.23

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.5.22",
3
+ "version": "3.5.23",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,4 +1,4 @@
1
- import { getOpenSearchData, getOpenSearchById, logger, insertOpenSearchData, updateOpenSearchData, download, chunkArray, getOpenSearchCount } from 'tango-app-api-middleware';
1
+ import { getOpenSearchData, getOpenSearchById, logger, insertOpenSearchData, updateOpenSearchData, download, chunkArray, getOpenSearchCount, insertWithId } from 'tango-app-api-middleware';
2
2
  import { findOneUser } from '../service/user.service.js';
3
3
  import mongoose from 'mongoose';
4
4
  import dayjs from 'dayjs';
@@ -758,6 +758,86 @@ export async function save( req, res ) {
758
758
  };
759
759
  await updateOpenSearchData( openSearch.EyeTestOutput, output?._id, { doc: record } );
760
760
  await updateOpenSearchData( openSearch.EyeTestInput, inputData.id, { doc: inputrecord } );
761
+
762
+ const getOne = await getOpenSearchData( openSearch.EyeTestInput, inputData.id );
763
+ const inputUpdatedData = getOne?.body?.hits?.hits;
764
+ const getEyetestConfig = await findOneEyeTestConfig( { clientId: req?.user.userType == 'tango'? inputData?.clientId : req.user.clientId, configureType: 'email' }, { condition: '$complianceThreshold.condition', value: '$complianceThreshold.value' } );
765
+ if ( getEyetestConfig && inputData.auditStatus == 'Audited' && inputUpdatedData?.lenght > 0 ) {
766
+ const trustScore = Math.round( 100-( ( inputData?.overRides / inputData?.steps?.length ) * 100 ) );
767
+ const value = Number( getEyetestConfig?.value?.split( '%' )[0] );
768
+ const condition = getEyetestConfig.condition;
769
+ const id= `${inputData?.RMEmail}_${inputData?.cluster}_${inputUpdatedData?.[0]?._source?.optumId}_${inputData?.fileId}`;
770
+ switch ( condition ) {
771
+ case '>': if ( trustScore > value ) {
772
+ const record1 = {
773
+ RMEmail: inputData.RMEmail,
774
+ cluster: inputData.cluster,
775
+ optumId: inputUpdatedData?.[0]?._source?.optumId,
776
+ storeName: inputUpdatedData?.[0]?._source?.storeName,
777
+ complianceScore: inputUpdatedData?.[0]?._source?.complianceScore,
778
+ trustScore: inputUpdatedData?.[0]?._source?.trustScore,
779
+ };
780
+ await insertWithId( openSearch.eyeTestEmailAlert, id, record1 );
781
+ }
782
+ case '<': if ( trustScore < value ) {
783
+ const record2 = {
784
+ RMEmail: inputData.RMEmail,
785
+ cluster: inputData.cluster,
786
+ optumId: inputUpdatedData?.[0]?._source?.optumId,
787
+ storeName: inputUpdatedData?.[0]?._source?.storeName,
788
+ complianceScore: inputUpdatedData?.[0]?._source?.complianceScore,
789
+ trustScore: inputUpdatedData?.[0]?._source?.trustScore,
790
+ };
791
+ await insertWithId( openSearch.eyeTestEmailAlert, id, record2 );
792
+ };
793
+ case '>=': if ( trustScore >= value ) {
794
+ const record3 = {
795
+ RMEmail: inputData.RMEmail,
796
+ cluster: inputData.cluster,
797
+ optumId: inputUpdatedData?.[0]?._source?.optumId,
798
+ storeName: inputUpdatedData?.[0]?._source?.storeName,
799
+ complianceScore: inputUpdatedData?.[0]?._source?.complianceScore,
800
+ trustScore: inputUpdatedData?.[0]?._source?.trustScore,
801
+ };
802
+ await insertWithId( openSearch.eyeTestEmailAlert, id, record3 );
803
+ }
804
+ case '<=': if ( trustScore <= value ) {
805
+ const record4 = {
806
+ RMEmail: inputData.RMEmail,
807
+ cluster: inputData.cluster,
808
+ optumId: inputUpdatedData?.[0]?._source?.optumId,
809
+ storeName: inputUpdatedData?.[0]?._source?.storeName,
810
+ complianceScore: inputUpdatedData?.[0]?._source?.complianceScore,
811
+ trustScore: inputUpdatedData?.[0]?._source?.trustScore,
812
+ };
813
+ await insertWithId( openSearch.eyeTestEmailAlert, id, record4 );
814
+ }
815
+ case '=':
816
+ case '==': if ( trustScore == value ) {
817
+ const record5 = {
818
+ RMEmail: inputData.RMEmail,
819
+ cluster: inputData.cluster,
820
+ optumId: inputUpdatedData?.[0]?._source?.optumId,
821
+ storeName: inputUpdatedData?.[0]?._source?.storeName,
822
+ complianceScore: inputUpdatedData?.[0]?._source?.complianceScore,
823
+ trustScore: inputUpdatedData?.[0]?._source?.trustScore,
824
+ };
825
+ await insertWithId( openSearch.eyeTestEmailAlert, id, record5 );
826
+ }
827
+ case '===': if ( trustScore === value ) {
828
+ const record6 = {
829
+ RMEmail: inputData.RMEmail,
830
+ cluster: inputData.cluster,
831
+ optumId: inputUpdatedData?.[0]?._source?.optumId,
832
+ storeName: inputUpdatedData?.[0]?._source?.storeName,
833
+ complianceScore: inputUpdatedData?.[0]?._source?.complianceScore,
834
+ trustScore: inputUpdatedData?.[0]?._source?.trustScore,
835
+ };
836
+ await insertWithId( openSearch.eyeTestEmailAlert, id, record6 );
837
+ }
838
+ default: throw new Error( `Unknown condition: ${condition}` );
839
+ }
840
+ }
761
841
  return res.sendSuccess( 'The file has been submited successfully' );
762
842
  } catch ( error ) {
763
843
  const err = error.message || 'Internal Server Error';
@@ -1573,16 +1653,25 @@ export async function emailAlertLog( req, res ) {
1573
1653
  if ( getData && getData?.body?.hits?.hits?.length > 0 ) {
1574
1654
  return res.sendError( 'No records found', 204 );
1575
1655
  }
1656
+ let response =[];
1657
+ for ( let item of getData?.body?.hits?.hits ) {
1658
+ response.push( {
1659
+ RMEmail: item?._source?.RMEmail,
1660
+ cluster: item?._source?.cluster,
1661
+ optumId: item?._source?.optumId,
1662
+ storeName: item?._source?.storeName,
1663
+ complianceScore: item?.source?.complianceScore,
1664
+ trustScore: item?._source?.trustScore,
1576
1665
 
1577
- // declare open search output
1578
- const result = getData?.body?.hits?.hits?.length;
1666
+ } );
1667
+ }
1579
1668
 
1580
1669
 
1581
1670
  // throw error if null or undefined or empty array
1582
1671
 
1583
1672
 
1584
- logger.info( { inputData: inputData, getData: getData } );
1585
- return res.sendSuccess( { result: result } );
1673
+ logger.info( { inputData: inputData, getData: response } );
1674
+ return res.sendSuccess( { result: response } );
1586
1675
  } catch ( error ) {
1587
1676
  const err = error.message || 'Internal Server Error';
1588
1677
  logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-emailAlertLog' } );
@@ -60,7 +60,10 @@ export const saveSchema = joi.object( {
60
60
  auditedSteps: joi.number().required(),
61
61
  auditStatus: joi.string().required(),
62
62
  overRides: joi.number().required(),
63
+ clientId: joi.string().required(),
63
64
  spokenLanguage: joi.string().optional(),
65
+ cluster: joi.string().required().allow( '' ),
66
+ RMEmail: joi.string().required().allow( '' ),
64
67
  } );
65
68
 
66
69
  export const saveValid = {