tango-app-api-audit 1.0.41 → 1.0.43

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.
@@ -0,0 +1,45 @@
1
+ import { checkFileExist } from 'tango-app-api-middleware';
2
+ import { findOneStoreZoneAudit } from '../service/storeZoneAudit.service.js';
3
+
4
+ export async function isAuditDocumentExist( req, res, next ) {
5
+ try {
6
+ const inputData = req.body;
7
+ const query={
8
+ storeId: inputData.storeId,
9
+ fileDate: inputData.fileDate,
10
+ zoneName: inputData.zoneName,
11
+ };
12
+ const auditInfo = await findOneStoreZoneAudit( query );
13
+ if ( auditInfo ) {
14
+ req.audit = auditInfo;
15
+ return next();
16
+ } else {
17
+ return res.sendError( 'No audited Record', 400 );
18
+ }
19
+ } catch ( error ) {
20
+ const err = error.message || 'Internal Server Error';
21
+ logger.error( { error: error, message: req.body, function: 'isAuditFileExist' } );
22
+ return res.sendError( err, 500 );
23
+ }
24
+ }
25
+
26
+ export async function isAuditInputFolderExist( req, res, next ) {
27
+ try {
28
+ const bucket = JSON.parse( process.env.BUCKET );
29
+ const inputData = req.method === 'POST' ? req.body : req.query;
30
+ const params={
31
+ Bucket: bucket.auditInput,
32
+ Key: `${inputData.fileDate}/${inputData.storeId}/${inputData.zoneName}`,
33
+ };
34
+ const isExist = await checkFileExist( params );
35
+ if ( isExist ) {
36
+ next();
37
+ } else {
38
+ return res.sendError( `Audit Input folder not available : ${inputData.fileDate}/${inputData.storeId}/${inputData.zoneName}`, 400 );
39
+ }
40
+ } catch ( error ) {
41
+ const err = error.message || 'Internal Server Error';
42
+ logger.error( { error: error, message: req.query, function: 'isAuidtInputFolderExist' } );
43
+ return res.sendError( err, 500 );
44
+ }
45
+ }