tango-app-api-store-builder 1.0.0-beta-34 → 1.0.0-beta-36
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-store-builder",
|
|
3
|
-
"version": "1.0.0-beta-
|
|
3
|
+
"version": "1.0.0-beta-36",
|
|
4
4
|
"description": "storeBuilder",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"joi": "^17.13.3",
|
|
24
24
|
"mongodb": "^6.12.0",
|
|
25
25
|
"nodemon": "^3.1.9",
|
|
26
|
-
"tango-api-schema": "^2.2.
|
|
26
|
+
"tango-api-schema": "^2.2.60",
|
|
27
27
|
"tango-app-api-middleware": "^3.1.48",
|
|
28
28
|
"winston": "^3.17.0",
|
|
29
29
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -12,6 +12,8 @@ import * as planoProductService from '../service/planoProduct.service.js';
|
|
|
12
12
|
import * as planoMappingService from '../service/planoMapping.service.js';
|
|
13
13
|
import * as planoComplianceService from '../service/planoCompliance.service.js';
|
|
14
14
|
import * as planoTaskComplianceService from '../service/planoTask.service.js';
|
|
15
|
+
import * as planoQrConversionRequestService from '../service/planoQrConversionRequest.service.js';
|
|
16
|
+
|
|
15
17
|
import path from 'path';
|
|
16
18
|
|
|
17
19
|
|
|
@@ -539,10 +541,17 @@ export async function storeFixtures( req, res ) {
|
|
|
539
541
|
|
|
540
542
|
export async function storeFixturesv1( req, res ) {
|
|
541
543
|
try {
|
|
542
|
-
const planoIds = req.body.id
|
|
544
|
+
const planoIds = req.body.id
|
|
545
|
+
.filter( ( id ) => mongoose.Types.ObjectId.isValid( id ) )
|
|
546
|
+
.map( ( id ) => new mongoose.Types.ObjectId( id ) );
|
|
543
547
|
|
|
544
548
|
const planograms = await planoService.find(
|
|
545
|
-
{
|
|
549
|
+
{
|
|
550
|
+
$or: [
|
|
551
|
+
{ _id: { $in: planoIds } },
|
|
552
|
+
{ storeId: { $in: req.body.id } },
|
|
553
|
+
],
|
|
554
|
+
},
|
|
546
555
|
{ storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1, scanType: 1 },
|
|
547
556
|
);
|
|
548
557
|
|
|
@@ -1899,10 +1908,17 @@ export const uploadImage = async ( req, res ) => {
|
|
|
1899
1908
|
|
|
1900
1909
|
export async function storeFixturesTask( req, res ) {
|
|
1901
1910
|
try {
|
|
1902
|
-
const planoIds = req.body.id
|
|
1911
|
+
const planoIds = req.body.id
|
|
1912
|
+
.filter( ( id ) => mongoose.Types.ObjectId.isValid( id ) )
|
|
1913
|
+
.map( ( id ) => new mongoose.Types.ObjectId( id ) );
|
|
1903
1914
|
|
|
1904
1915
|
const planograms = await planoService.find(
|
|
1905
|
-
{
|
|
1916
|
+
{
|
|
1917
|
+
$or: [
|
|
1918
|
+
{ _id: { $in: planoIds } },
|
|
1919
|
+
{ storeId: { $in: req.body.id } },
|
|
1920
|
+
],
|
|
1921
|
+
},
|
|
1906
1922
|
{ storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1, scanType: 1 },
|
|
1907
1923
|
);
|
|
1908
1924
|
|
|
@@ -2074,15 +2090,14 @@ export async function storeFixturesTask( req, res ) {
|
|
|
2074
2090
|
}
|
|
2075
2091
|
}
|
|
2076
2092
|
|
|
2077
|
-
|
|
2078
|
-
export const qrVideoUpload = async ( req, res ) => {
|
|
2093
|
+
export const qrFileUpload = async ( req, res ) => {
|
|
2079
2094
|
try {
|
|
2080
2095
|
if ( !req.files?.file ) {
|
|
2081
2096
|
return res.sendError( { message: 'Please upload a file' }, 400 );
|
|
2082
2097
|
}
|
|
2083
2098
|
|
|
2084
2099
|
const { file } = req.files;
|
|
2085
|
-
const { fixtureId } = req.body;
|
|
2100
|
+
const { fixtureId, type } = req.body;
|
|
2086
2101
|
|
|
2087
2102
|
if ( !fixtureId ) {
|
|
2088
2103
|
return res.sendError( { message: 'Missing fixtureId' }, 400 );
|
|
@@ -2102,7 +2117,13 @@ export const qrVideoUpload = async ( req, res ) => {
|
|
|
2102
2117
|
return res.sendError( { message: 'Storage bucket not configured' }, 500 );
|
|
2103
2118
|
}
|
|
2104
2119
|
|
|
2105
|
-
|
|
2120
|
+
let uploadPath;
|
|
2121
|
+
|
|
2122
|
+
if ( type === 'video' ) {
|
|
2123
|
+
uploadPath = `planoQrFixtureVideos/${dayjs().format( 'YYYY-MM-DD' )}/${fixture.toObject().storeId}`;
|
|
2124
|
+
} else if ( type === 'image' ) {
|
|
2125
|
+
uploadPath = `planoQrFixtureImages/${dayjs().format( 'YYYY-MM-DD' )}/${fixture.toObject().storeId}`;
|
|
2126
|
+
}
|
|
2106
2127
|
|
|
2107
2128
|
const params = {
|
|
2108
2129
|
fileName: `/${fixtureId}.${format}`,
|
|
@@ -2114,11 +2135,43 @@ export const qrVideoUpload = async ( req, res ) => {
|
|
|
2114
2135
|
|
|
2115
2136
|
const fileUrl = await fileUpload( params );
|
|
2116
2137
|
|
|
2138
|
+
const signedParams = {
|
|
2139
|
+
Bucket: bucket.storeBuilder,
|
|
2140
|
+
file_path: fileUrl.Key,
|
|
2141
|
+
};
|
|
2142
|
+
const signedKey = await signedUrl( signedParams );
|
|
2143
|
+
|
|
2144
|
+
res.sendSuccess( signedKey );
|
|
2145
|
+
} catch ( error ) {
|
|
2146
|
+
logger.error( 'fixtureQrUpdate =>', error );
|
|
2147
|
+
return res.sendError( { message: 'Internal Server Error' }, 500 );
|
|
2148
|
+
}
|
|
2149
|
+
};
|
|
2150
|
+
|
|
2151
|
+
export const updateQrCvProcessRequest = async ( req, res ) => {
|
|
2152
|
+
try {
|
|
2153
|
+
const { fixtureId, videoPath, imagePath, videoComment, imageComment } = req.body;
|
|
2154
|
+
|
|
2155
|
+
if ( !fixtureId ) {
|
|
2156
|
+
return res.sendError( { message: 'Missing fixtureId' }, 400 );
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
const fixture = await storeFixtureService.findOne( { _id: fixtureId } );
|
|
2160
|
+
|
|
2161
|
+
if ( !fixture ) {
|
|
2162
|
+
return res.sendError( { message: 'Fixture not found' }, 400 );
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
const bucket = JSON.parse( process.env.BUCKET || '{}' );
|
|
2166
|
+
if ( !bucket.storeBuilder ) {
|
|
2167
|
+
return res.sendError( { message: 'Storage bucket not configured' }, 500 );
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2117
2170
|
const message = {
|
|
2118
2171
|
'fixtureId': fixtureId,
|
|
2119
2172
|
'date': dayjs().format( 'YYYY-MM-DD' ),
|
|
2120
2173
|
'bucket': bucket.storeBuilder,
|
|
2121
|
-
'videoPath':
|
|
2174
|
+
'videoPath': videoPath,
|
|
2122
2175
|
};
|
|
2123
2176
|
|
|
2124
2177
|
const sqs = JSON.parse( process.env.SQS || '{}' );
|
|
@@ -2128,7 +2181,89 @@ export const qrVideoUpload = async ( req, res ) => {
|
|
|
2128
2181
|
|
|
2129
2182
|
const sqsPush = await sendMessageToQueue( `${sqs.url}${sqs.qrVideoTopic}`, JSON.stringify( message ) );
|
|
2130
2183
|
|
|
2131
|
-
|
|
2184
|
+
if ( !sqsPush?.MessageId ) {
|
|
2185
|
+
return res.sendError( { message: 'Failed to send SQS message' }, 500 );
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
const fixtureData = fixture.toObject();
|
|
2189
|
+
|
|
2190
|
+
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
2191
|
+
|
|
2192
|
+
const data = {
|
|
2193
|
+
clientId: fixtureData?.clientId,
|
|
2194
|
+
storeName: fixtureData?.storeName,
|
|
2195
|
+
storeId: fixtureData?.storeId,
|
|
2196
|
+
planoId: fixtureData?.planoId,
|
|
2197
|
+
floorId: fixtureData?.floorId,
|
|
2198
|
+
fixtureId: fixtureData?._id,
|
|
2199
|
+
date: currentDate,
|
|
2200
|
+
status: 'initiated',
|
|
2201
|
+
fixtureImage: {
|
|
2202
|
+
filePath: imagePath ? imagePath.match( /planoQrFixtureImages\/[^?]+/ )?.[0] : undefined,
|
|
2203
|
+
comment: imageComment,
|
|
2204
|
+
},
|
|
2205
|
+
fixtureVideo: {
|
|
2206
|
+
filePath: videoPath ? videoPath.match( /planoQrFixtureVideos\/[^?]+/ )?.[0] : undefined,
|
|
2207
|
+
comment: videoComment,
|
|
2208
|
+
},
|
|
2209
|
+
};
|
|
2210
|
+
|
|
2211
|
+
|
|
2212
|
+
await planoQrConversionRequestService.upsertOne( { fixtureId: fixtureData?._id, date: currentDate }, data );
|
|
2213
|
+
|
|
2214
|
+
return res.sendSuccess( { message: 'Updated successfully', data } );
|
|
2215
|
+
} catch ( error ) {
|
|
2216
|
+
logger.error( 'uploadFixtureVideo =>', error );
|
|
2217
|
+
return res.sendError( { message: 'Internal Server Error' }, 500 );
|
|
2218
|
+
}
|
|
2219
|
+
};
|
|
2220
|
+
|
|
2221
|
+
export const getQrCvProcessRequest = async ( req, res ) => {
|
|
2222
|
+
try {
|
|
2223
|
+
const { fixtureId } = req.body;
|
|
2224
|
+
|
|
2225
|
+
if ( !fixtureId ) {
|
|
2226
|
+
return res.sendError( { message: 'Missing fixtureId' }, 400 );
|
|
2227
|
+
}
|
|
2228
|
+
|
|
2229
|
+
const fixture = await storeFixtureService.findOne( { _id: fixtureId } );
|
|
2230
|
+
|
|
2231
|
+
if ( !fixture ) {
|
|
2232
|
+
return res.sendError( { message: 'Fixture not found' }, 400 );
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
2236
|
+
|
|
2237
|
+
const planoCvReq = await planoQrConversionRequestService.findOne( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), date: currentDate } );
|
|
2238
|
+
|
|
2239
|
+
if ( !planoCvReq ) {
|
|
2240
|
+
return res.sendError( 'No data found', 204 );
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2243
|
+
const bucket = JSON.parse( process.env.BUCKET || '{}' );
|
|
2244
|
+
if ( !bucket.storeBuilder ) {
|
|
2245
|
+
return res.sendError( { message: 'Storage bucket not configured' }, 500 );
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
let planoCvReqData = planoCvReq.toObject();
|
|
2249
|
+
|
|
2250
|
+
if ( planoCvReqData?.fixtureImage?.filePath ) {
|
|
2251
|
+
const params = {
|
|
2252
|
+
Bucket: bucket.storeBuilder,
|
|
2253
|
+
file_path: planoCvReqData.fixtureImage.filePath,
|
|
2254
|
+
};
|
|
2255
|
+
planoCvReqData.fixtureImage.filePath = await signedUrl( params );
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
if ( planoCvReqData?.fixtureVideo?.filePath ) {
|
|
2259
|
+
const params = {
|
|
2260
|
+
Bucket: bucket.storeBuilder,
|
|
2261
|
+
file_path: planoCvReqData.fixtureVideo.filePath,
|
|
2262
|
+
};
|
|
2263
|
+
planoCvReqData.fixtureVideo.filePath = await signedUrl( params );
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
return res.sendSuccess( planoCvReqData );
|
|
2132
2267
|
} catch ( error ) {
|
|
2133
2268
|
logger.error( 'uploadFixtureVideo =>', error );
|
|
2134
2269
|
return res.sendError( { message: 'Internal Server Error' }, 500 );
|
|
@@ -2183,6 +2318,8 @@ export const fixtureQrUpdate = async ( req, res ) => {
|
|
|
2183
2318
|
} ),
|
|
2184
2319
|
);
|
|
2185
2320
|
|
|
2321
|
+
await planoQrConversionRequestService.updateOne( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), date: currentDate }, { status: 'data-received' } );
|
|
2322
|
+
|
|
2186
2323
|
return res.sendSuccess( updateStatus );
|
|
2187
2324
|
} catch ( error ) {
|
|
2188
2325
|
logger.error( 'fixtureQrUpdate =>', error );
|
|
@@ -2190,3 +2327,4 @@ export const fixtureQrUpdate = async ( req, res ) => {
|
|
|
2190
2327
|
}
|
|
2191
2328
|
};
|
|
2192
2329
|
|
|
2330
|
+
|
|
@@ -28,6 +28,8 @@ storeBuilderRouter
|
|
|
28
28
|
.post( '/bulkFixtureUpload', storeBuilderController.bulkFixtureUpload )
|
|
29
29
|
.post( '/uploadImage', storeBuilderController.uploadImage )
|
|
30
30
|
.post( '/storeFixturesTask', storeBuilderController.storeFixturesTask )
|
|
31
|
-
.post( '/
|
|
31
|
+
.post( '/qrFileUpload', storeBuilderController.qrFileUpload )
|
|
32
|
+
.post( '/updateQrCvProcessRequest', storeBuilderController.updateQrCvProcessRequest )
|
|
33
|
+
.post( '/getQrCvProcessRequest', storeBuilderController.getQrCvProcessRequest )
|
|
32
34
|
.post( '/fixtureQrUpdate', storeBuilderController.fixtureQrUpdate );
|
|
33
35
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import model from 'tango-api-schema';
|
|
2
|
+
|
|
3
|
+
export async function find( query={}, field={} ) {
|
|
4
|
+
return model.planoQrConversionRequest.find( query, field );
|
|
5
|
+
}
|
|
6
|
+
export async function findOne( query={}, field={} ) {
|
|
7
|
+
return model.planoQrConversionRequest.findOne( query, field );
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function insertMany( data ) {
|
|
11
|
+
return model.planoQrConversionRequest.insertMany( data );
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function aggregate( query ) {
|
|
15
|
+
return model.planoQrConversionRequest.aggregate( query );
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function updateOne( query, record ) {
|
|
19
|
+
return model.planoQrConversionRequest.updateOne( query, { $set: record } );
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function count( query ) {
|
|
23
|
+
return model.planoQrConversionRequest.countDocuments( query );
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function create( data ) {
|
|
27
|
+
return model.planoQrConversionRequest.create( data );
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function upsertOne( query, record ) {
|
|
31
|
+
return model.planoQrConversionRequest.updateOne( query, { $set: record }, { upsert: true } );
|
|
32
|
+
}
|