tango-app-api-trax 3.9.67 → 3.9.69
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
|
@@ -69,12 +69,45 @@ export async function viewchecklist( req, res ) {
|
|
|
69
69
|
try {
|
|
70
70
|
let url = JSON.parse( process.env.LAMBDAURL );
|
|
71
71
|
let resultData = await LamdaServiceCall( url.checklistAnswer, req.body );
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
// Guard before touching resultData — LamdaServiceCall returns false on failure.
|
|
73
|
+
if ( !resultData ) {
|
|
74
|
+
return res.sendError( 'No Content', 204 );
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const answers = resultData.checklistAnswers || [];
|
|
78
|
+
// Enrich each answer with its store's SPOC email. Batch every store lookup
|
|
79
|
+
// into a single $in query (one round-trip instead of one per answer), indexed
|
|
80
|
+
// by storeId for an in-memory lookup below.
|
|
81
|
+
const storeIds = [ ...new Set(
|
|
82
|
+
answers
|
|
83
|
+
.filter( ( ele ) => ele?.storeProfile?.storeName && ele?.storeProfile?.store_id )
|
|
84
|
+
.map( ( ele ) => ele?.storeProfile?.store_id ),
|
|
85
|
+
) ];
|
|
86
|
+
const spocEmailByStoreId = {};
|
|
87
|
+
if ( storeIds.length ) {
|
|
88
|
+
const storeDetails = await storeService.find(
|
|
89
|
+
{ storeId: { $in: storeIds } },
|
|
90
|
+
{ storeId: 1, spocDetails: 1 },
|
|
91
|
+
);
|
|
92
|
+
storeDetails?.forEach( ( store ) => {
|
|
93
|
+
if ( store.spocDetails?.[0]?.email ) {
|
|
94
|
+
spocEmailByStoreId[store.storeId] = { email: store.spocDetails?.[0]?.email, name: store.spocDetails?.[0]?.name };
|
|
95
|
+
}
|
|
96
|
+
} );
|
|
97
|
+
}
|
|
98
|
+
// Keep every answer; only attach the SPOC email when we found one.
|
|
99
|
+
resultData.checklistAnswers = answers.map( ( ele ) => {
|
|
100
|
+
ele.storeProfile.userList = [ { name: ele.storeProfile.userName, email: ele.storeProfile.userEmail } ];
|
|
101
|
+
if ( ele?.storeProfile?.storeName && spocEmailByStoreId[ele?.storeProfile?.store_id] ) {
|
|
102
|
+
if ( !ele.storeProfile.userList.find( ( list ) => list.email == spocEmailByStoreId[ele?.storeProfile?.store_id]?.email ) ) {
|
|
103
|
+
ele.storeProfile.userList.push( { name: spocEmailByStoreId[ele?.storeProfile?.store_id]?.name, email: spocEmailByStoreId[ele?.storeProfile?.store_id]?.email } );
|
|
104
|
+
}
|
|
77
105
|
}
|
|
106
|
+
return ele;
|
|
107
|
+
} );
|
|
108
|
+
|
|
109
|
+
if ( resultData.status_code == '200' ) {
|
|
110
|
+
return res.sendSuccess( resultData );
|
|
78
111
|
} else {
|
|
79
112
|
return res.sendError( 'No Content', 204 );
|
|
80
113
|
}
|