tango-app-api-audit 3.3.0-alpha.2 → 3.3.0-alpha.21

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,167 +0,0 @@
1
- import { checkFileExist, getJsonFileData, listFileWithoutLimit, signedUrl } from 'tango-app-api-middleware';
2
- import { findOneStoreAudit } from '../service/storeAudit.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 findOneStoreAudit( 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
- }
46
-
47
- export async function getZoneAuditFilterData( data ) {
48
- try {
49
- const bucket = JSON.parse( process.env.BUCKET );
50
- const storeId = data.storeId;
51
- const fileDate = data.fileDate;
52
- const params = {
53
- Bucket: `${bucket.auditUploadBucket}`,
54
- Key: `${storeId}/${data.zoneName}/${fileDate}/${bucket.masterJsonFile}`,
55
- };
56
- const mappingFile = await getJsonFileData( params );
57
- if ( mappingFile.statusCode ) {
58
- return mappingFile;
59
- } else {
60
- const mappingData = await JSON.parse( mappingFile.toString( 'utf-8' ) );
61
- const filterData = await mappingData.person_data.filter(
62
- ( item ) =>
63
- item.temp_ids < 20000 &&
64
- item.temp_ids > 0 &&
65
- item.person_status === '',
66
- );
67
- const finalResult = await filterData.map( ( i ) => {
68
- return { ...i, img: i.index.concat( '_', i.temp_ids ) };
69
- } );
70
- return finalResult;
71
- }
72
- } catch ( error ) {
73
- logger.error( {
74
- error: error,
75
- type: 'MAPPING JSON getFilterData',
76
- function: 'getZoneAuditFilterData',
77
- } );
78
- return error;
79
- }
80
- }
81
-
82
- export async function isZoneAuditInputFolderExist( req, res, next ) {
83
- try {
84
- const bucket = JSON.parse( process.env.BUCKET );
85
- const inputData = req.method === 'POST' ? req.body : req.query;
86
- const params={
87
- Bucket: bucket.auditInput,
88
- Key: `${inputData.fileDate}/${inputData.storeId}/${inputData.zoneName}`,
89
- };
90
- const isExist = await checkFileExist( params );
91
- if ( isExist ) {
92
- next();
93
- } else {
94
- return res.sendError( `Audit Input folder not available : ${inputData.fileDate}/${inputData.storeId}`, 400 );
95
- }
96
- } catch ( error ) {
97
- const err = error.message || 'Internal Server Error';
98
- logger.error( { error: error, message: req.query, function: 'isAuidtInputFolderExist' } );
99
- return res.sendError( err, 500 );
100
- }
101
- }
102
-
103
- export async function getZoneAuditImageData( data ) {
104
- try {
105
- const bucket = JSON.parse( process.env.BUCKET );
106
- const storeId = data.storeId;
107
- const fileDate = data.fileDate;
108
- const files = [];
109
- const fetchData = {
110
- Bucket: `${bucket.auditInput}`,
111
- filePath: `${fileDate}/${storeId}/${data.zoneName}/`,
112
- };
113
-
114
- const folderPath = await listFileWithoutLimit( fetchData );
115
- if ( folderPath.statusCode == 404 ) {
116
- return folderPath;
117
- }
118
- const auditImages = folderPath;
119
-
120
- if ( data.export==false ) {
121
- if ( auditImages && auditImages?.length > 0 ) {
122
- for ( let i = 0; i < auditImages.length; i++ ) {
123
- const img = auditImages[i].Key.split( '/' );
124
- const image = img[3].split( '.' );
125
- const indexes = image[0].split( '_' );
126
- const params = {
127
- file_path: auditImages[i].Key,
128
- Bucket: fetchData.Bucket,
129
- };
130
- const data = await signedUrl( params );
131
- files.push( {
132
- imgPath: data,
133
- imgName: indexes[1],
134
- imgId: image[0],
135
- img_name: indexes[1],
136
- // imgFile: auditImages[i],
137
- } );
138
- }
139
- return files;
140
- }
141
- } else {
142
- if ( auditImages && auditImages?.length > 0 ) {
143
- for ( let i = 0; i < auditImages.length; i++ ) {
144
- const img = auditImages[i].Key.split( '/' );
145
- const image = img[3].split( '.' );
146
- const indexes = image[0].split( '_' );
147
- const params = {
148
- file_path: auditImages[i].Key,
149
- Bucket: fetchData.Bucket,
150
- };
151
- const data = await signedUrl( params );
152
- files.push( {
153
- imgPath: data,
154
- imgName: indexes[1],
155
- imgId: image[0],
156
- imgFile: auditImages[i],
157
- img_name: indexes[1],
158
- } );
159
- }
160
- return files;
161
- }
162
- }
163
- } catch ( error ) {
164
- logger.error( { error: error, type: 'getZoneAuditImageData' } );
165
- return error;
166
- }
167
- }