tango-app-api-store-builder 1.0.0-beta-102 → 1.0.0-beta-104
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/index.js +4 -1
- package/inputjson/layoutverification.json +210 -0
- package/package.json +3 -2
- package/response.json +647 -0
- package/src/controllers/fixtureTemplate.controller.js +451 -0
- package/src/controllers/managePlano.controller.js +260 -0
- package/src/controllers/planoLibrary.controller.js +1313 -0
- package/src/controllers/script.controller.js +1791 -403
- package/src/controllers/storeBuilder.controller.js +526 -318
- package/src/controllers/task.controller.js +132 -52
- package/src/dtos/validation.dtos.js +218 -0
- package/src/routes/fixtureTemplate.routes.js +17 -0
- package/src/routes/managePlano.routes.js +14 -0
- package/src/routes/planoLibrary.routes.js +40 -0
- package/src/routes/script.routes.js +3 -1
- package/src/routes/storeBuilder.routes.js +5 -1
- package/src/routes/task.routes.js +1 -0
- package/src/service/fixtureConfig.service.js +32 -3
- package/src/service/planoLibrary.service.js +37 -0
- package/src/service/planoStaticData.service.js +3 -0
- package/src/service/planoTask.service.js +3 -0
- package/src/service/planoVm.service.js +49 -0
- package/src/service/planoproductCategory.service.js +39 -0
- package/src/service/vmType.service.js +33 -0
|
@@ -7,6 +7,7 @@ import * as planoService from '../service/planogram.service.js';
|
|
|
7
7
|
import * as storeFixtureService from '../service/storeFixture.service.js';
|
|
8
8
|
import * as fixtureShelfService from '../service/fixtureShelf.service.js';
|
|
9
9
|
import * as planoProductService from '../service/planoProduct.service.js';
|
|
10
|
+
import * as planoVmService from '../service/planoVm.service.js';
|
|
10
11
|
import * as planoMappingService from '../service/planoMapping.service.js';
|
|
11
12
|
import * as planoTaskService from '../service/planoTask.service.js';
|
|
12
13
|
import * as processedTaskService from '../service/processedTaskservice.js';
|
|
@@ -14,11 +15,11 @@ import * as processedTaskService from '../service/processedTaskservice.js';
|
|
|
14
15
|
// import * as planoTaskComplianceService from '../service/planoTask.service.js';
|
|
15
16
|
// import * as planoQrConversionRequestService from '../service/planoQrConversionRequest.service.js';
|
|
16
17
|
import * as fixtureConfigService from '../service/fixtureConfig.service.js';
|
|
18
|
+
import * as fixtureLibraryService from '../service/planoLibrary.service.js';
|
|
17
19
|
import mongoose from 'mongoose';
|
|
18
20
|
import JSZip from 'jszip';
|
|
19
21
|
import { signedUrl } from 'tango-app-api-middleware';
|
|
20
22
|
import fs from 'fs';
|
|
21
|
-
import https from 'https';
|
|
22
23
|
import os from 'os';
|
|
23
24
|
import { fileURLToPath } from 'url';
|
|
24
25
|
import path from 'path';
|
|
@@ -1135,7 +1136,7 @@ export async function updateFixturesShelves( req, res ) {
|
|
|
1135
1136
|
|
|
1136
1137
|
const createdFixture = await storeFixtureService.findOneAndUpdate2( { storeName: layoutDoc.storeName, fixtureNumber: fixture?.['fixtureNumber'] }, { fixtureCode: fixture?.['Fixture ID'] } );
|
|
1137
1138
|
|
|
1138
|
-
|
|
1139
|
+
console.log( 'Fixture Data', fixtureData );
|
|
1139
1140
|
|
|
1140
1141
|
|
|
1141
1142
|
const vms = typeof fixture?.['VM Template ID'] === 'string' ? fixture?.['VM Template ID']?.split( ', ' ).map( ( item ) => item.trim() ) : [];
|
|
@@ -1251,7 +1252,7 @@ export async function updateFixturesShelves( req, res ) {
|
|
|
1251
1252
|
|
|
1252
1253
|
const createdFixture = await storeFixtureService.findOneAndUpdate2( { storeName: layoutDoc.storeName, fixtureNumber: fixture?.['fixtureNumber'] }, { fixtureCode: fixture?.['Fixture ID'] } );
|
|
1253
1254
|
|
|
1254
|
-
|
|
1255
|
+
console.log( 'Fixture Data', fixtureData );
|
|
1255
1256
|
|
|
1256
1257
|
const vms = typeof fixture?.['VM Template ID'] === 'string' ? fixture?.['VM Template ID']?.split( ', ' ).map( ( item ) => item.trim() ) : [];
|
|
1257
1258
|
|
|
@@ -1300,7 +1301,7 @@ export async function updateFixturesShelves( req, res ) {
|
|
|
1300
1301
|
|
|
1301
1302
|
const createdShelf = await fixtureShelfService.create( shelfData );
|
|
1302
1303
|
|
|
1303
|
-
|
|
1304
|
+
console.log( 'Shelf Data:', createdShelf );
|
|
1304
1305
|
|
|
1305
1306
|
shelfIndex++;
|
|
1306
1307
|
}
|
|
@@ -1362,7 +1363,7 @@ export async function updateFixturesShelves( req, res ) {
|
|
|
1362
1363
|
|
|
1363
1364
|
const createdFixture = await storeFixtureService.findOneAndUpdate2( { storeName: layoutDoc.storeName, fixtureNumber: fixture?.['fixtureNumber'] }, { fixtureCode: fixture?.['Fixture ID'] } );
|
|
1364
1365
|
|
|
1365
|
-
|
|
1366
|
+
console.log( 'Fixture Data', fixtureData );
|
|
1366
1367
|
|
|
1367
1368
|
const vms = typeof fixture?.['VM Template ID'] === 'string' ? fixture?.['VM Template ID']?.split( ', ' ).map( ( item ) => item.trim() ) : [];
|
|
1368
1369
|
|
|
@@ -1487,7 +1488,7 @@ export async function updateFixturesShelves( req, res ) {
|
|
|
1487
1488
|
};
|
|
1488
1489
|
|
|
1489
1490
|
const createdFixture = await storeFixtureService.findOneAndUpdate2( { storeName: layoutDoc.storeName, fixtureNumber: fixture?.['fixtureNumber'] }, { fixtureCode: fixture?.['Fixture ID'] } );
|
|
1490
|
-
|
|
1491
|
+
console.log( 'Fixture Data', fixtureData );
|
|
1491
1492
|
|
|
1492
1493
|
const vms = typeof fixture?.['VM Template ID'] === 'string' ? fixture?.['VM Template ID']?.split( ', ' ).map( ( item ) => item.trim() ) : [];
|
|
1493
1494
|
|
|
@@ -1700,6 +1701,7 @@ export async function updateInventory( req, res ) {
|
|
|
1700
1701
|
console.log( updateData );
|
|
1701
1702
|
|
|
1702
1703
|
const product = await planoProductService.create( updateData );
|
|
1704
|
+
console.log( product );
|
|
1703
1705
|
}
|
|
1704
1706
|
|
|
1705
1707
|
|
|
@@ -1824,6 +1826,7 @@ export async function updatelayoutFeedback( req, res ) {
|
|
|
1824
1826
|
const layoutDoc = layoutFeedbacks[i].toObject();
|
|
1825
1827
|
|
|
1826
1828
|
const [ q1, q2, q3 ] = layoutDoc.answers;
|
|
1829
|
+
console.log( q3 );
|
|
1827
1830
|
|
|
1828
1831
|
if ( q1.value === false ) {
|
|
1829
1832
|
const floor = await storeBuilderService.findOne( { _id: layoutDoc.floorId } );
|
|
@@ -2136,6 +2139,7 @@ export async function updateFixtureFeedback( req, res ) {
|
|
|
2136
2139
|
const vmTask = vmTaskList[j].toObject();
|
|
2137
2140
|
|
|
2138
2141
|
const [ q1, q2 ] = vmTask.answers;
|
|
2142
|
+
console.log( q2 );
|
|
2139
2143
|
|
|
2140
2144
|
if ( q1.value ) continue;
|
|
2141
2145
|
|
|
@@ -2316,76 +2320,76 @@ export async function updateVmData( req, res ) {
|
|
|
2316
2320
|
}
|
|
2317
2321
|
}
|
|
2318
2322
|
|
|
2319
|
-
|
|
2320
|
-
async function scrapeCrest() {
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
}
|
|
2387
|
-
|
|
2388
|
-
// scrapeCrest()
|
|
2323
|
+
// import https from 'https';
|
|
2324
|
+
// async function scrapeCrest() {
|
|
2325
|
+
// const storeIds = [ 'LKST2567' ];
|
|
2326
|
+
// const apiUrl = 'https://api.getcrest.ai/api/ms_shelfsensei/layout/';
|
|
2327
|
+
// const bearerToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQ5MTEyNDYxLCJpYXQiOjE3NDkxMDg4NjEsImp0aSI6ImYzMDhmN2M3YzBlYjQ4NWU5YjVmNTJjZjRjNTkxNTM2IiwidXNlcl9pZCI6MTA4NSwiaWQiOjEwODUsImlzX21lZXNlZWtfYWNjb3VudCI6ZmFsc2UsImN1c3RvbWVyX2dyb3VwIjozOTgsImxpY2VuY2Vfc2NvcGVzIjpbeyJyZXNvdXJjZV9zZXQiOiJwcF9zZXQiLCJzY29wZV9yb2xlIjoiY29udHJpYnV0b3IifSx7InJlc291cmNlX3NldCI6ImRwX3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9LHsicmVzb3VyY2Vfc2V0IjoiZGZfc2V0Iiwic2NvcGVfcm9sZSI6ImNvbnRyaWJ1dG9yIn0seyJyZXNvdXJjZV9zZXQiOiJkZWZhdWx0X3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9XX0.zXRf9dgtrIhjnUJSKyLqbB8FRnTT0a-hOBos0gvKsJY';
|
|
2328
|
+
// const filePath = 'response.json';
|
|
2329
|
+
// let allResults = [];
|
|
2330
|
+
|
|
2331
|
+
// if ( fs.existsSync( filePath ) ) {
|
|
2332
|
+
// try {
|
|
2333
|
+
// const existingData = fs.readFileSync( filePath, 'utf8' );
|
|
2334
|
+
// allResults = JSON.parse( existingData );
|
|
2335
|
+
// if ( !Array.isArray( allResults ) ) {
|
|
2336
|
+
// allResults = [];
|
|
2337
|
+
// }
|
|
2338
|
+
// } catch ( error ) {
|
|
2339
|
+
// console.error( 'Error reading existing JSON file:', error.message );
|
|
2340
|
+
// allResults = [];
|
|
2341
|
+
// }
|
|
2342
|
+
// }
|
|
2343
|
+
|
|
2344
|
+
// for ( const storeId of storeIds ) {
|
|
2345
|
+
// try {
|
|
2346
|
+
// const result = await new Promise( ( resolve ) => {
|
|
2347
|
+
// const payload = JSON.stringify( { store_id: storeId } );
|
|
2348
|
+
// const options = {
|
|
2349
|
+
// method: 'POST',
|
|
2350
|
+
// headers: {
|
|
2351
|
+
// 'Authorization': `Bearer ${bearerToken}`,
|
|
2352
|
+
// 'Content-Type': 'application/json',
|
|
2353
|
+
// 'Content-Length': Buffer.byteLength( payload ),
|
|
2354
|
+
// },
|
|
2355
|
+
// };
|
|
2356
|
+
|
|
2357
|
+
// const req = https.request( apiUrl, options, ( res ) => {
|
|
2358
|
+
// let data = '';
|
|
2359
|
+
// res.on( 'data', ( chunk ) => {
|
|
2360
|
+
// data += chunk;
|
|
2361
|
+
// } );
|
|
2362
|
+
// res.on( 'end', () => {
|
|
2363
|
+
// try {
|
|
2364
|
+
// const jsonData = JSON.parse( data );
|
|
2365
|
+
// const result = { storeName: storeId, data: jsonData };
|
|
2366
|
+
// allResults.push( result );
|
|
2367
|
+
// fs.writeFileSync( filePath, JSON.stringify( allResults, null, 2 ) );
|
|
2368
|
+
// console.log( 'Received Data:', result );
|
|
2369
|
+
// resolve( result );
|
|
2370
|
+
// } catch ( error ) {
|
|
2371
|
+
// console.error( `Error parsing JSON for ${storeId}:`, error.message );
|
|
2372
|
+
// resolve( { storeName: storeId, data: null } );
|
|
2373
|
+
// }
|
|
2374
|
+
// } );
|
|
2375
|
+
// } );
|
|
2376
|
+
|
|
2377
|
+
// req.on( 'error', ( error ) => {
|
|
2378
|
+
// console.error( `Error fetching data for ${storeId}:`, error.message );
|
|
2379
|
+
// resolve( { storeName: storeId, data: null } );
|
|
2380
|
+
// } );
|
|
2381
|
+
|
|
2382
|
+
// req.write( payload );
|
|
2383
|
+
// req.end();
|
|
2384
|
+
// } );
|
|
2385
|
+
// } catch ( error ) {
|
|
2386
|
+
// console.error( `Unexpected error for ${storeId}:`, error.message );
|
|
2387
|
+
// }
|
|
2388
|
+
// await new Promise( ( resolve ) => setTimeout( resolve, 1000 ) );
|
|
2389
|
+
// }
|
|
2390
|
+
// }
|
|
2391
|
+
|
|
2392
|
+
// scrapeCrest();
|
|
2389
2393
|
|
|
2390
2394
|
export async function createCrestPlanogram( req, res ) {
|
|
2391
2395
|
try {
|
|
@@ -3319,246 +3323,249 @@ export async function updateCrestVms( req, res ) {
|
|
|
3319
3323
|
}
|
|
3320
3324
|
|
|
3321
3325
|
|
|
3322
|
-
async function filterStores() {
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
const rawData = fs.readFileSync( 'crest_scrap_v1.json', 'utf8' );
|
|
3341
|
-
const allStores = JSON.parse( rawData );
|
|
3342
|
-
|
|
3343
|
-
const filteredStores = allStores.filter( ( store ) => stores.includes( store.storeName ) );
|
|
3344
|
-
|
|
3345
|
-
fs.writeFileSync( 'crest_filtered.json', JSON.stringify( filteredStores, null, 2 ) );
|
|
3346
|
-
}
|
|
3347
|
-
|
|
3348
|
-
import fsp from 'fs/promises';
|
|
3349
|
-
|
|
3350
|
-
import sharp from 'sharp';
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
const stitchImagesFromZips = async () => {
|
|
3354
|
-
const zip1Path = 'crest_plano.zip';
|
|
3355
|
-
const zip2Path = 'tango_plano.zip';
|
|
3356
|
-
const outputDir = 'stitched';
|
|
3357
|
-
|
|
3358
|
-
const loadZip = async ( zipPath ) => {
|
|
3359
|
-
const buffer = await fsp.readFile( zipPath );
|
|
3360
|
-
return await JSZip.loadAsync( buffer );
|
|
3361
|
-
};
|
|
3362
|
-
|
|
3363
|
-
const extractImages = async ( zip ) => {
|
|
3364
|
-
const imageFiles = {};
|
|
3365
|
-
const imageRegex = /\.(png|jpe?g)$/i;
|
|
3366
|
-
|
|
3367
|
-
for ( const [ name, file ] of Object.entries( zip.files ) ) {
|
|
3368
|
-
const base = path.basename( name );
|
|
3369
|
-
if ( !file.dir && imageRegex.test( base ) ) {
|
|
3370
|
-
imageFiles[base] = await file.async( 'nodebuffer' );
|
|
3371
|
-
}
|
|
3372
|
-
}
|
|
3373
|
-
|
|
3374
|
-
return imageFiles;
|
|
3375
|
-
};
|
|
3376
|
-
|
|
3377
|
-
const stitchOrCenter = async ( buffer1, buffer2, outputPath ) => {
|
|
3378
|
-
const totalWidth = 7000;
|
|
3379
|
-
const width1 = Math.round( totalWidth * 0.3 );
|
|
3380
|
-
const width2 = Math.round( totalWidth * 0.7 );
|
|
3381
|
-
|
|
3382
|
-
let img1 = buffer1 ? await sharp( buffer1 ).resize( { width: width1 } ).toBuffer() : null;
|
|
3383
|
-
let img2 = buffer2 ? await sharp( buffer2 ).resize( { width: width2 } ).toBuffer() : null;
|
|
3384
|
-
|
|
3385
|
-
const [ meta1, meta2 ] = await Promise.all( [
|
|
3386
|
-
img1 ? sharp( img1 ).metadata() : Promise.resolve( { height: 0 } ),
|
|
3387
|
-
img2 ? sharp( img2 ).metadata() : Promise.resolve( { height: 0 } ),
|
|
3388
|
-
] );
|
|
3389
|
-
|
|
3390
|
-
const maxHeight = Math.max( meta1.height, meta2.height );
|
|
3326
|
+
// async function filterStores() {
|
|
3327
|
+
// const stores = [
|
|
3328
|
+
// 'ST338', 'LKST1304', 'ST303', 'LKST1228', 'LKST499', 'LKST479', 'ST320',
|
|
3329
|
+
// 'LKST515', 'LKST406', 'ST392', 'ST328', 'ST332', 'LKST487', 'ST312',
|
|
3330
|
+
// 'LKST615', 'LKST352', 'LKST457', 'LKST439', 'LKST347', 'LKST1084',
|
|
3331
|
+
// 'LKST380', 'ST298', 'LKST356', 'LKST223', 'LKST480', 'ST30', 'ST285',
|
|
3332
|
+
// 'LKST500', 'LKST466', 'LKST321', 'LKST678', 'LKST383', 'LKST365',
|
|
3333
|
+
// 'LKST374', 'ST302', 'LKST420', 'LKST394', 'LKST444', 'LKST314',
|
|
3334
|
+
// 'LKST01', 'LKST357', 'LKST465', 'LKST331', 'LKST440', 'LKST345',
|
|
3335
|
+
// 'LKST389', 'ST330', 'LKST299', 'ST244', 'LKST294', 'ST314', 'LKST361',
|
|
3336
|
+
// 'LKST377', 'LKST390', 'ST335', 'LKST416', 'ST293', 'LKST341', 'LKST501',
|
|
3337
|
+
// 'LKST408', 'LKST227', 'LKST353', 'LKST364', 'ST318', 'LKST326',
|
|
3338
|
+
// 'LKST344', 'ST321', 'LKST384', 'LKST496', 'LKST427', 'LKST325',
|
|
3339
|
+
// 'LKST282', 'ST197', 'LKST388', 'LKST338', 'LKST371', 'ST326', 'LKST428',
|
|
3340
|
+
// 'LKST112', 'LKST334', 'ST319', 'LKST464', 'LKST490', 'LKST11',
|
|
3341
|
+
// 'LKST502', 'LKST1438',
|
|
3342
|
+
// ];
|
|
3391
3343
|
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
if ( img2 ) composites.push( { input: img2, top: 0, left: width1 } );
|
|
3344
|
+
// const rawData = fs.readFileSync( 'crest_scrap_v1.json', 'utf8' );
|
|
3345
|
+
// const allStores = JSON.parse( rawData );
|
|
3395
3346
|
|
|
3396
|
-
|
|
3397
|
-
create: {
|
|
3398
|
-
width: totalWidth,
|
|
3399
|
-
height: maxHeight,
|
|
3400
|
-
channels: 4,
|
|
3401
|
-
background: { r: 255, g: 255, b: 255, alpha: 0 },
|
|
3402
|
-
},
|
|
3403
|
-
} )
|
|
3404
|
-
.composite( composites )
|
|
3405
|
-
.png()
|
|
3406
|
-
.toFile( outputPath );
|
|
3407
|
-
};
|
|
3347
|
+
// const filteredStores = allStores.filter( ( store ) => stores.includes( store.storeName ) );
|
|
3408
3348
|
|
|
3409
|
-
|
|
3410
|
-
|
|
3349
|
+
// fs.writeFileSync( 'crest_filtered.json', JSON.stringify( filteredStores, null, 2 ) );
|
|
3350
|
+
// }
|
|
3411
3351
|
|
|
3412
|
-
|
|
3413
|
-
const [ images1, images2 ] = await Promise.all( [ extractImages( zip1 ), extractImages( zip2 ) ] );
|
|
3352
|
+
// import fsp from 'fs/promises';
|
|
3414
3353
|
|
|
3415
|
-
|
|
3354
|
+
import sharp from 'sharp';
|
|
3416
3355
|
|
|
3417
|
-
for ( const name of allFilenames ) {
|
|
3418
|
-
const buffer1 = images1[name] || null;
|
|
3419
|
-
const buffer2 = images2[name] || null;
|
|
3420
|
-
const outputPath = path.join( outputDir, `${name.replace( /\.[^/.]+$/, '' )}.png` );
|
|
3421
3356
|
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3357
|
+
// const stitchImagesFromZips = async () => {
|
|
3358
|
+
// const zip1Path = 'crest_plano.zip';
|
|
3359
|
+
// const zip2Path = 'tango_plano.zip';
|
|
3360
|
+
// const outputDir = 'stitched';
|
|
3361
|
+
|
|
3362
|
+
// const loadZip = async ( zipPath ) => {
|
|
3363
|
+
// const buffer = await fsp.readFile( zipPath );
|
|
3364
|
+
// return await JSZip.loadAsync( buffer );
|
|
3365
|
+
// };
|
|
3366
|
+
|
|
3367
|
+
// const extractImages = async ( zip ) => {
|
|
3368
|
+
// const imageFiles = {};
|
|
3369
|
+
// const imageRegex = /\.(png|jpe?g)$/i;
|
|
3370
|
+
|
|
3371
|
+
// for ( const [ name, file ] of Object.entries( zip.files ) ) {
|
|
3372
|
+
// const base = path.basename( name );
|
|
3373
|
+
// if ( !file.dir && imageRegex.test( base ) ) {
|
|
3374
|
+
// imageFiles[base] = await file.async( 'nodebuffer' );
|
|
3375
|
+
// }
|
|
3376
|
+
// }
|
|
3377
|
+
|
|
3378
|
+
// return imageFiles;
|
|
3379
|
+
// };
|
|
3380
|
+
|
|
3381
|
+
// const stitchOrCenter = async ( buffer1, buffer2, outputPath ) => {
|
|
3382
|
+
// const totalWidth = 7000;
|
|
3383
|
+
// const width1 = Math.round( totalWidth * 0.3 );
|
|
3384
|
+
// const width2 = Math.round( totalWidth * 0.7 );
|
|
3385
|
+
|
|
3386
|
+
// let img1 = buffer1 ? await sharp( buffer1 ).resize( { width: width1 } ).toBuffer() : null;
|
|
3387
|
+
// let img2 = buffer2 ? await sharp( buffer2 ).resize( { width: width2 } ).toBuffer() : null;
|
|
3388
|
+
|
|
3389
|
+
// const [ meta1, meta2 ] = await Promise.all( [
|
|
3390
|
+
// img1 ? sharp( img1 ).metadata() : Promise.resolve( { height: 0 } ),
|
|
3391
|
+
// img2 ? sharp( img2 ).metadata() : Promise.resolve( { height: 0 } ),
|
|
3392
|
+
// ] );
|
|
3393
|
+
|
|
3394
|
+
// const maxHeight = Math.max( meta1.height, meta2.height );
|
|
3395
|
+
|
|
3396
|
+
// const composites = [];
|
|
3397
|
+
// if ( img1 ) composites.push( { input: img1, top: 0, left: 0 } );
|
|
3398
|
+
// if ( img2 ) composites.push( { input: img2, top: 0, left: width1 } );
|
|
3399
|
+
|
|
3400
|
+
// await sharp( {
|
|
3401
|
+
// create: {
|
|
3402
|
+
// width: totalWidth,
|
|
3403
|
+
// height: maxHeight,
|
|
3404
|
+
// channels: 4,
|
|
3405
|
+
// background: { r: 255, g: 255, b: 255, alpha: 0 },
|
|
3406
|
+
// },
|
|
3407
|
+
// } )
|
|
3408
|
+
// .composite( composites )
|
|
3409
|
+
// .png()
|
|
3410
|
+
// .toFile( outputPath );
|
|
3411
|
+
// };
|
|
3412
|
+
|
|
3413
|
+
// try {
|
|
3414
|
+
// await fsp.mkdir( outputDir, { recursive: true } );
|
|
3415
|
+
|
|
3416
|
+
// const [ zip1, zip2 ] = await Promise.all( [ loadZip( zip1Path ), loadZip( zip2Path ) ] );
|
|
3417
|
+
// const [ images1, images2 ] = await Promise.all( [ extractImages( zip1 ), extractImages( zip2 ) ] );
|
|
3418
|
+
|
|
3419
|
+
// const allFilenames = new Set( [ ...Object.keys( images1 ), ...Object.keys( images2 ) ] );
|
|
3420
|
+
|
|
3421
|
+
// for ( const name of allFilenames ) {
|
|
3422
|
+
// const buffer1 = images1[name] || null;
|
|
3423
|
+
// const buffer2 = images2[name] || null;
|
|
3424
|
+
// const outputPath = path.join( outputDir, `${name.replace( /\.[^/.]+$/, '' )}.png` );
|
|
3425
|
+
|
|
3426
|
+
// try {
|
|
3427
|
+
// await stitchOrCenter( buffer1, buffer2, outputPath );
|
|
3428
|
+
// console.log( ` Processed: ${name}` );
|
|
3429
|
+
// } catch ( err ) {
|
|
3430
|
+
// console.error( ` Error processing ${name}:`, err.message );
|
|
3431
|
+
// }
|
|
3432
|
+
// }
|
|
3433
|
+
// } catch ( err ) {
|
|
3434
|
+
// console.error( ' Unexpected error:', err.message );
|
|
3435
|
+
// }
|
|
3436
|
+
// };
|
|
3433
3437
|
|
|
3434
3438
|
// stitchImagesFromZips();
|
|
3435
3439
|
|
|
3436
3440
|
|
|
3437
|
-
import { Builder
|
|
3438
|
-
import chrome from 'selenium-webdriver/chrome.js';
|
|
3441
|
+
import { Builder } from 'selenium-webdriver';
|
|
3442
|
+
// import chrome from 'selenium-webdriver/chrome.js';
|
|
3439
3443
|
import fetch from 'node-fetch';
|
|
3440
3444
|
|
|
3441
3445
|
import fetchCookie from 'fetch-cookie';
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
}
|
|
3446
|
+
// import { elementIsNotVisible } from 'selenium-webdriver/lib/until.js';
|
|
3447
|
+
|
|
3448
|
+
|
|
3449
|
+
// async function downloadCrestImages() {
|
|
3450
|
+
// const storeList = await planoService.find( {} );
|
|
3451
|
+
// // const storeIds = storeList.map( ( store ) => store.toObject().storeName );
|
|
3452
|
+
// const storeIds = [ 'LKST1304' ];
|
|
3453
|
+
|
|
3454
|
+
|
|
3455
|
+
// const invalidateUrl = 'https://app.getcrest.ai/api/ms_iam/user/session/override/';
|
|
3456
|
+
// const tokenUrl = 'https://app.getcrest.ai/api/ms_iam/token/';
|
|
3457
|
+
|
|
3458
|
+
// let authToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQ3NTEwNDAxLCJpYXQiOjE3NDc1MDY4MDEsImp0aSI6IjQ0YzNjOWNkZjUzYjQ5ZWE5OGQ3NWQxOTI1NGMxMGRkIiwidXNlcl9pZCI6MTA4NSwiaWQiOjEwODUsImlzX21lZXNlZWtfYWNjb3VudCI6ZmFsc2UsImN1c3RvbWVyX2dyb3VwIjozOTgsImxpY2VuY2Vfc2NvcGVzIjpbeyJyZXNvdXJjZV9zZXQiOiJwcF9zZXQiLCJzY29wZV9yb2xlIjoiY29udHJpYnV0b3IifSx7InJlc291cmNlX3NldCI6ImRwX3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9LHsicmVzb3VyY2Vfc2V0IjoiZGZfc2V0Iiwic2NvcGVfcm9sZSI6ImNvbnRyaWJ1dG9yIn0seyJyZXNvdXJjZV9zZXQiOiJkZWZhdWx0X3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9XX0.5OYkUq4kIWDUXothNCCfk6GIQHlhiMdOuHzuczWt6QM';
|
|
3459
|
+
|
|
3460
|
+
// const fetchWithCookies = fetchCookie( fetch );
|
|
3461
|
+
|
|
3462
|
+
// async function fetchNewToken() {
|
|
3463
|
+
// const invalidate = await fetchWithCookies( invalidateUrl, {
|
|
3464
|
+
// 'method': 'POST',
|
|
3465
|
+
// 'headers': { 'Content-Type': 'application/json' },
|
|
3466
|
+
// 'body': JSON.stringify( { 'email': 'tango.lenskart@getcrest.ai', 'password': 'Tangolenskart@123' } ),
|
|
3467
|
+
// } );
|
|
3468
|
+
|
|
3469
|
+
// const invalidateData = await invalidate.json();
|
|
3470
|
+
|
|
3471
|
+
// console.log( invalidateData );
|
|
3472
|
+
|
|
3473
|
+
// console.log( 'Fetching new token...' );
|
|
3474
|
+
// const res = await fetchWithCookies( tokenUrl, {
|
|
3475
|
+
// 'method': 'POST',
|
|
3476
|
+
// 'Accept': 'application/json, text/javascript, */*; q=0.01',
|
|
3477
|
+
// 'headers': { 'Content-Type': 'application/json' },
|
|
3478
|
+
// 'body': JSON.stringify( { 'email': 'tango.lenskart@getcrest.ai', 'password': 'Tangolenskart@123' } ),
|
|
3479
|
+
// } );
|
|
3480
|
+
|
|
3481
|
+
// if ( !res.ok ) {
|
|
3482
|
+
// throw new Error( `Failed to fetch token: ${res.status}` );
|
|
3483
|
+
// }
|
|
3484
|
+
|
|
3485
|
+
// const data = await res.json();
|
|
3486
|
+
// console.log( data );
|
|
3487
|
+
// authToken = data.access;
|
|
3488
|
+
// return authToken;
|
|
3489
|
+
// }
|
|
3490
|
+
|
|
3491
|
+
// async function runAutomation( token, storeId, retries = 3 ) {
|
|
3492
|
+
// let attempts = 0;
|
|
3493
|
+
|
|
3494
|
+
// while ( attempts < retries ) {
|
|
3495
|
+
// const options = new chrome.Options();
|
|
3496
|
+
// // options.addArguments( 'headless' );
|
|
3497
|
+
// options.addArguments( 'disable-gpu' );
|
|
3498
|
+
|
|
3499
|
+
// const driver = await new Builder()
|
|
3500
|
+
// .forBrowser( 'chrome' )
|
|
3501
|
+
// .setChromeOptions( options )
|
|
3502
|
+
// .build();
|
|
3503
|
+
|
|
3504
|
+
// try {
|
|
3505
|
+
// const url = `https://app.getcrest.ai/pvt/?auth=${token}&module=planno&store_id=${storeId}`;
|
|
3506
|
+
// await driver.get( url );
|
|
3507
|
+
// const currentUrl = await driver.getCurrentUrl();
|
|
3508
|
+
// if ( currentUrl.includes( '/login' ) ) {
|
|
3509
|
+
// console.warn( `Redirected to login for store ${storeId}. Retrying with new token...` );
|
|
3510
|
+
// await driver.quit();
|
|
3511
|
+
// const newToken = await fetchNewToken();
|
|
3512
|
+
// return await runAutomation( newToken, storeId, retries );
|
|
3513
|
+
// }
|
|
3514
|
+
|
|
3515
|
+
// const button = await driver.wait( until.elementLocated(
|
|
3516
|
+
// By.xpath( '//*[contains(@class, "MuiButtonBase-root") and contains(@class, "MuiButton-root") and contains(@class, "MuiButton-text") and contains(@class, "MuiButton-disableElevation") and contains(@class, "jss35") and contains(@class, "jss47") and contains(@class, "jss37") and contains(@class, "jss144")]' ),
|
|
3517
|
+
// ), 10000 );
|
|
3518
|
+
// await button.click();
|
|
3519
|
+
|
|
3520
|
+
// const checkbox = await driver.wait(
|
|
3521
|
+
// until.elementLocated(
|
|
3522
|
+
// By.xpath( '//*[contains(@class, "MuiCheckbox-root") and contains(@class, "MuiIconButton-root")]//input[@type="checkbox"]' ),
|
|
3523
|
+
// ),
|
|
3524
|
+
// 10000,
|
|
3525
|
+
// );
|
|
3526
|
+
// await checkbox.click();
|
|
3527
|
+
|
|
3528
|
+
// const downloadIcon = await driver.wait(
|
|
3529
|
+
// until.elementLocated(
|
|
3530
|
+
// By.xpath( '//button[contains(@class, "cool-tooltip")]' ),
|
|
3531
|
+
// ),
|
|
3532
|
+
// 10000,
|
|
3533
|
+
// );
|
|
3534
|
+
// await downloadIcon.click();
|
|
3535
|
+
|
|
3536
|
+
|
|
3537
|
+
// console.log( `Download triggered for store: ${storeId}` );
|
|
3538
|
+
// await driver.sleep( 5000 );
|
|
3539
|
+
// return;
|
|
3540
|
+
// } catch ( err ) {
|
|
3541
|
+
// attempts++;
|
|
3542
|
+
// console.error( `Error for store ${storeId}, attempt ${attempts}: ${err.message}` );
|
|
3543
|
+
// if ( attempts >= retries ) {
|
|
3544
|
+
// console.error( `Failed for store ${storeId} after ${retries} attempts` );
|
|
3545
|
+
// } else {
|
|
3546
|
+
// console.log( `Retrying for store ${storeId}, attempt ${attempts + 1}` );
|
|
3547
|
+
// }
|
|
3548
|
+
// } finally {
|
|
3549
|
+
// try {
|
|
3550
|
+
// if ( driver && ( await driver.getSession() ) ) {
|
|
3551
|
+
// await driver.quit();
|
|
3552
|
+
// }
|
|
3553
|
+
// } catch ( e ) {
|
|
3554
|
+
|
|
3555
|
+
// }
|
|
3556
|
+
// }
|
|
3557
|
+
// }
|
|
3558
|
+
// }
|
|
3559
|
+
|
|
3560
|
+
// for ( const storeId of storeIds ) {
|
|
3561
|
+
// try {
|
|
3562
|
+
// console.log( `Starting automation for store: ${storeId}` );
|
|
3563
|
+
// await runAutomation( authToken, storeId );
|
|
3564
|
+
// } catch ( error ) {
|
|
3565
|
+
// console.error( `Automation failed for store ${storeId}: ${error.message}` );
|
|
3566
|
+
// }
|
|
3567
|
+
// }
|
|
3568
|
+
// }
|
|
3562
3569
|
|
|
3563
3570
|
// downloadCrestImages();
|
|
3564
3571
|
export async function updatePlanoFixtureLayout( planoId, floorId ) {
|
|
@@ -4133,36 +4140,12 @@ export async function downloadPlanoImage( req, res ) {
|
|
|
4133
4140
|
date_string: { $gte: req.body.fromDate, $lte: req.body.toDate },
|
|
4134
4141
|
type: 'layout',
|
|
4135
4142
|
status: 'incomplete',
|
|
4143
|
+
storeName: { $in: req.body.store },
|
|
4136
4144
|
},
|
|
4137
4145
|
},
|
|
4138
|
-
{
|
|
4139
|
-
$lookup: {
|
|
4140
|
-
from: 'planograms',
|
|
4141
|
-
let: { plano_id: '$planoId' },
|
|
4142
|
-
pipeline: [
|
|
4143
|
-
{
|
|
4144
|
-
$match: {
|
|
4145
|
-
$expr: {
|
|
4146
|
-
$and: [
|
|
4147
|
-
{ $eq: [ '$_id', '$$plano_id' ] },
|
|
4148
|
-
],
|
|
4149
|
-
},
|
|
4150
|
-
},
|
|
4151
|
-
},
|
|
4152
|
-
{
|
|
4153
|
-
$project: {
|
|
4154
|
-
storeName: 1,
|
|
4155
|
-
_id: 0,
|
|
4156
|
-
},
|
|
4157
|
-
},
|
|
4158
|
-
],
|
|
4159
|
-
as: 'planogram',
|
|
4160
|
-
},
|
|
4161
|
-
},
|
|
4162
|
-
{ $unwind: { path: '$planogram', preserveNullAndEmptyArrays: true } },
|
|
4163
4146
|
{
|
|
4164
4147
|
$project: {
|
|
4165
|
-
storeName:
|
|
4148
|
+
storeName: 1,
|
|
4166
4149
|
answers: 1,
|
|
4167
4150
|
type: 1,
|
|
4168
4151
|
status: 1,
|
|
@@ -4176,17 +4159,18 @@ export async function downloadPlanoImage( req, res ) {
|
|
|
4176
4159
|
if ( !taskDetails.length ) {
|
|
4177
4160
|
return res.sendError( 'No data found', 204 );
|
|
4178
4161
|
}
|
|
4179
|
-
let planoList = taskDetails.map( ( ele ) => ele.planoId );
|
|
4180
|
-
|
|
4162
|
+
let planoList = [ ...new Set( taskDetails.map( ( ele ) => ele.planoId ) ) ];
|
|
4163
|
+
console.log( planoList );
|
|
4164
|
+
let storeList = [ ...new Set( taskDetails.map( ( ele ) => ele.storeName ) ) ];
|
|
4165
|
+
console.log( storeList );
|
|
4181
4166
|
async function sleep( ms ) {
|
|
4182
4167
|
return new Promise( ( resolve ) => setTimeout( resolve, ms ) );
|
|
4183
4168
|
}
|
|
4184
4169
|
|
|
4185
4170
|
async function openPlanoUrls( planoList ) {
|
|
4186
4171
|
for ( let id of planoList ) {
|
|
4187
|
-
const url = `
|
|
4172
|
+
const url = `https://plano-builder.tangoeye.ai/#/plano?planoId=${id}&token&download=1&url=http://localhost:3008`;
|
|
4188
4173
|
const driver = await new Builder().forBrowser( 'chrome' ).build();
|
|
4189
|
-
|
|
4190
4174
|
try {
|
|
4191
4175
|
await driver.get( url );
|
|
4192
4176
|
await sleep( 20000 );
|
|
@@ -4206,6 +4190,7 @@ export async function downloadPlanoImage( req, res ) {
|
|
|
4206
4190
|
if ( !req.body?.merge ) {
|
|
4207
4191
|
const downloadsPath = path.join( os.homedir(), 'Downloads' );
|
|
4208
4192
|
const targetFolder = path.join( __dirname, '..', '..', `${req.body.file}Images` );
|
|
4193
|
+
console.log( 'test' );
|
|
4209
4194
|
await openPlanoUrls( planoList );
|
|
4210
4195
|
if ( !fs.existsSync( targetFolder ) ) {
|
|
4211
4196
|
fs.mkdirSync( targetFolder, { recursive: true } );
|
|
@@ -5722,7 +5707,7 @@ export async function getVideoLinks( req, res ) {
|
|
|
5722
5707
|
continue;
|
|
5723
5708
|
}
|
|
5724
5709
|
const [ q1, q2, q3 ] = data.answers;
|
|
5725
|
-
|
|
5710
|
+
console.log( q1, q2 );
|
|
5726
5711
|
const params = {
|
|
5727
5712
|
Bucket: 'tango-planogram',
|
|
5728
5713
|
file_path: q3?.video || null,
|
|
@@ -7015,28 +7000,28 @@ export async function updateExcelPlanogram( req, res ) {
|
|
|
7015
7000
|
}
|
|
7016
7001
|
}
|
|
7017
7002
|
|
|
7018
|
-
async function downloadImage() {
|
|
7019
|
-
|
|
7003
|
+
// async function downloadImage() {
|
|
7004
|
+
// const url = 'https://api.getcrest.ai/api/ms_data_preparation/master_data/attachment/?preview=0&attachment_id=2934';
|
|
7020
7005
|
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
|
|
7027
|
-
|
|
7006
|
+
// try {
|
|
7007
|
+
// const response = await fetch( url, {
|
|
7008
|
+
// headers: {
|
|
7009
|
+
// Authorization: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQ3MjE0MjcxLCJpYXQiOjE3NDcyMTA2NzEsImp0aSI6ImM4ZjQ4ZDY2YWJkYzRmNDU4MWI4OGE4MTMwODVjOTUwIiwidXNlcl9pZCI6MTA4NSwiaWQiOjEwODUsImlzX21lZXNlZWtfYWNjb3VudCI6ZmFsc2UsImN1c3RvbWVyX2dyb3VwIjozOTgsImxpY2VuY2Vfc2NvcGVzIjpbeyJyZXNvdXJjZV9zZXQiOiJwcF9zZXQiLCJzY29wZV9yb2xlIjoiY29udHJpYnV0b3IifSx7InJlc291cmNlX3NldCI6ImRwX3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9LHsicmVzb3VyY2Vfc2V0IjoiZGZfc2V0Iiwic2NvcGVfcm9sZSI6ImNvbnRyaWJ1dG9yIn0seyJyZXNvdXJjZV9zZXQiOiJkZWZhdWx0X3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9XX0.IOw_0yNA6CMBCIn7cxjPR0FqHI949WplCKzlkr8aK7g',
|
|
7010
|
+
// Cookie: 'prod_session_key=w144dqljxlh096487nc33rm09vwtossh; prod_session_key=7mljy9k7niwpw4btbbyvuhkz7otbdh6v',
|
|
7011
|
+
// },
|
|
7012
|
+
// } );
|
|
7028
7013
|
|
|
7029
|
-
|
|
7014
|
+
// if ( !response.ok ) throw new Error( `HTTP error! Status: ${response.status}` );
|
|
7030
7015
|
|
|
7031
|
-
|
|
7032
|
-
|
|
7016
|
+
// const dest = fs.createWriteStream( '2934.png' );
|
|
7017
|
+
// response.body.pipe( dest );
|
|
7033
7018
|
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
|
|
7037
|
-
|
|
7038
|
-
|
|
7039
|
-
}
|
|
7019
|
+
// dest.on( 'finish', () => console.log( 'Image saved as image.jpg' ) );
|
|
7020
|
+
// dest.on( 'error', ( err ) => console.error( 'File write error:', err ) );
|
|
7021
|
+
// } catch ( err ) {
|
|
7022
|
+
// console.error( 'Fetch error:', err );
|
|
7023
|
+
// }
|
|
7024
|
+
// }
|
|
7040
7025
|
|
|
7041
7026
|
// downloadImage();
|
|
7042
7027
|
|
|
@@ -7083,73 +7068,1476 @@ export async function recorrectTaskData( req, res ) {
|
|
|
7083
7068
|
}
|
|
7084
7069
|
|
|
7085
7070
|
|
|
7086
|
-
function
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
7071
|
+
export async function migrateCrestv1( req, res ) {
|
|
7072
|
+
try {
|
|
7073
|
+
if ( req?.headers?.authorization?.split( ' ' )[1] !== 'hwjXfCD6TgMvc82cuSGZ9bNv9MuXsaiQ6uvx' ) {
|
|
7074
|
+
return res.sendError( 'Unauthorized', 401 );
|
|
7075
|
+
}
|
|
7076
|
+
|
|
7077
|
+
const startTime = Date.now();
|
|
7078
|
+
|
|
7079
|
+
const layoutApiUrl = 'https://api.getcrest.ai/api/ms_shelfsensei/layout/';
|
|
7080
|
+
let staticToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQ1NTE3MjQxLCJpYXQiOjE3NDU1MTM2NDEsImp0aSI6Ijg3MWVlNTA3ODY2OTQ5OTVhMTQ0YTk4NzQyNzY0MzEzIiwidXNlcl9pZCI6MTA4NSwiaWQiOjEwODUsImlzX21lZXNlZWtfYWNjb3VudCI6ZmFsc2UsImN1c3RvbWVyX2dyb3VwIjozOTgsImxpY2VuY2Vfc2NvcGVzIjpbeyJyZXNvdXJjZV9zZXQiOiJwcF9zZXQiLCJzY29wZV9yb2xlIjoiY29udHJpYnV0b3IifSx7InJlc291cmNlX3NldCI6ImRwX3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9LHsicmVzb3VyY2Vfc2V0IjoiZGZfc2V0Iiwic2NvcGVfcm9sZSI6ImNvbnRyaWJ1dG9yIn0seyJyZXNvdXJjZV9zZXQiOiJkZWZhdWx0X3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9XX0.eGzTMGwwstr13M0Hu1Ls5-gkE_oSPMJJBL2wgygT6Ac';
|
|
7081
|
+
const fetchWithCookies = fetchCookie( fetch );
|
|
7082
|
+
|
|
7083
|
+
|
|
7084
|
+
async function fetchStoreData( store, bearerToken, res ) {
|
|
7085
|
+
const payload = JSON.stringify( { store_id: store.toObject().storeName?.toUpperCase() } );
|
|
7086
|
+
|
|
7087
|
+
try {
|
|
7088
|
+
const response = await fetch( layoutApiUrl, {
|
|
7089
|
+
method: 'POST',
|
|
7090
|
+
headers: {
|
|
7091
|
+
'Authorization': `Bearer ${bearerToken}`,
|
|
7092
|
+
'Content-Type': 'application/json',
|
|
7093
|
+
'Content-Length': Buffer.byteLength( payload ),
|
|
7094
|
+
},
|
|
7095
|
+
body: payload,
|
|
7096
|
+
} );
|
|
7097
|
+
|
|
7098
|
+
const data = await response.text();
|
|
7099
|
+
let jsonData = null;
|
|
7090
7100
|
|
|
7091
|
-
|
|
7101
|
+
try {
|
|
7102
|
+
jsonData = JSON.parse( data );
|
|
7103
|
+
} catch ( parseError ) {
|
|
7104
|
+
logger.error( { functionName: `Warning: Received invalid JSON for store ${store.toObject().storeName}`, error: parseError } );
|
|
7105
|
+
console.warn( `Warning: Received invalid JSON for store ${store.toObject().storeName}` );
|
|
7106
|
+
return { storeName: store.toObject().storeName, data: null };
|
|
7107
|
+
}
|
|
7092
7108
|
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7109
|
+
if ( jsonData.result === 'Token is invalid or expired' ) {
|
|
7110
|
+
console.log( 'Token expired, retrying...' );
|
|
7111
|
+
try {
|
|
7112
|
+
const newToken = await fetchNewToken();
|
|
7113
|
+
staticToken = newToken;
|
|
7114
|
+
return await fetchStoreData( store, newToken, res );
|
|
7115
|
+
} catch ( retryError ) {
|
|
7116
|
+
logger.error( { functionName: 'Failed to refresh token', error: retryError } );
|
|
7117
|
+
console.log( retryError );
|
|
7118
|
+
return res.sendError( 'Failed to refresh token', 401 );
|
|
7119
|
+
}
|
|
7120
|
+
}
|
|
7097
7121
|
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7122
|
+
return { storeName: store.toObject().storeName, data: jsonData };
|
|
7123
|
+
} catch ( error ) {
|
|
7124
|
+
logger.error( { functionName: `Error fetching data for ${store.toObject().storeName}:`, error } );
|
|
7125
|
+
console.error( `Error fetching data for ${store.toObject().storeName}:`, error.message );
|
|
7126
|
+
return { storeName: store.toObject().storeName, data: null };
|
|
7127
|
+
}
|
|
7102
7128
|
}
|
|
7103
|
-
return row;
|
|
7104
|
-
} );
|
|
7105
7129
|
|
|
7106
|
-
const newSheet = xlsx.utils.json_to_sheet( updatedData );
|
|
7107
7130
|
|
|
7108
|
-
|
|
7131
|
+
const fetchNewToken = async () => {
|
|
7132
|
+
const email = 'tango.lenskart@getcrest.ai';
|
|
7133
|
+
const password = 'Tangolenskart@123';
|
|
7109
7134
|
|
|
7110
|
-
|
|
7111
|
-
}
|
|
7135
|
+
const credentials = JSON.stringify( { email, password } );
|
|
7112
7136
|
|
|
7113
|
-
|
|
7137
|
+
const invalidateUrl = 'https://app.getcrest.ai/api/ms_iam/user/session/override/';
|
|
7138
|
+
const tokenUrl = 'https://app.getcrest.ai/api/ms_iam/token/';
|
|
7114
7139
|
|
|
7140
|
+
try {
|
|
7141
|
+
const invalidateRes = await fetchWithCookies( invalidateUrl, {
|
|
7142
|
+
method: 'POST',
|
|
7143
|
+
headers: {
|
|
7144
|
+
'Content-Type': 'application/json',
|
|
7145
|
+
},
|
|
7146
|
+
body: credentials,
|
|
7147
|
+
} );
|
|
7115
7148
|
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
const shelfConfigArr = [];
|
|
7119
|
-
const vmConfigArr = [];
|
|
7149
|
+
const invalidateData = await invalidateRes.json();
|
|
7150
|
+
console.log( 'Invalidate response:', invalidateData );
|
|
7120
7151
|
|
|
7121
|
-
|
|
7122
|
-
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7152
|
+
console.log( 'Fetching new token...' );
|
|
7153
|
+
const tokenRes = await fetchWithCookies( tokenUrl, {
|
|
7154
|
+
method: 'POST',
|
|
7155
|
+
headers: {
|
|
7156
|
+
'Content-Type': 'application/json',
|
|
7157
|
+
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
|
7158
|
+
},
|
|
7159
|
+
body: credentials,
|
|
7160
|
+
} );
|
|
7130
7161
|
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
fixtureCode: fixture.fixtureCode,
|
|
7134
|
-
...shelf,
|
|
7135
|
-
} );
|
|
7136
|
-
} );
|
|
7162
|
+
const tokenData = await tokenRes.json();
|
|
7163
|
+
console.log( 'Token response:', tokenData );
|
|
7137
7164
|
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
}
|
|
7143
|
-
}
|
|
7144
|
-
|
|
7165
|
+
return tokenData.access;
|
|
7166
|
+
} catch ( error ) {
|
|
7167
|
+
console.error( 'Error fetching new token:', error );
|
|
7168
|
+
throw error;
|
|
7169
|
+
}
|
|
7170
|
+
};
|
|
7171
|
+
|
|
7172
|
+
const fetchVmImage = async ( attachmentId ) => {
|
|
7173
|
+
try {
|
|
7174
|
+
const response = await fetchWithCookies( `https://api.getcrest.ai/api/ms_data_preparation/master_data/attachment/?preview=0&attachment_id=${attachmentId}`, {
|
|
7175
|
+
method: 'GET',
|
|
7176
|
+
headers: {
|
|
7177
|
+
'Authorization': `Bearer ${staticToken}`,
|
|
7178
|
+
'Cookie': 'prod_session_key=w144dqljxlh096487nc33rm09vwtossh',
|
|
7179
|
+
},
|
|
7180
|
+
} );
|
|
7145
7181
|
|
|
7146
|
-
const workbook = xlsx.utils.book_new();
|
|
7147
|
-
xlsx.utils.book_append_sheet( workbook, xlsx.utils.json_to_sheet( fixtureInfoArr ), 'Fixture Info' );
|
|
7148
|
-
xlsx.utils.book_append_sheet( workbook, xlsx.utils.json_to_sheet( shelfConfigArr ), 'Shelf Config' );
|
|
7149
|
-
xlsx.utils.book_append_sheet( workbook, xlsx.utils.json_to_sheet( vmConfigArr ), 'VM Config' );
|
|
7150
7182
|
|
|
7151
|
-
|
|
7152
|
-
|
|
7183
|
+
if ( !response.ok ) {
|
|
7184
|
+
return;
|
|
7185
|
+
// throw new Error( `Failed to fetch image: ${response.status}` );
|
|
7186
|
+
}
|
|
7187
|
+
|
|
7188
|
+
// const dest = fs.createWriteStream( `${attachmentId}.png` );
|
|
7189
|
+
// response.body.pipe( dest );
|
|
7190
|
+
|
|
7191
|
+
return await response.buffer();
|
|
7192
|
+
} catch ( error ) {
|
|
7193
|
+
console.error( 'Error fetching image buffer:', error.message );
|
|
7194
|
+
throw error;
|
|
7195
|
+
}
|
|
7196
|
+
};
|
|
7197
|
+
|
|
7198
|
+
const getImageMetadata = async ( imageBuffer ) => {
|
|
7199
|
+
try {
|
|
7200
|
+
const metadata = await sharp( imageBuffer ).metadata();
|
|
7201
|
+
const { width, height, format } = metadata;
|
|
7202
|
+
|
|
7203
|
+
if ( !width || !height || !format ) throw new Error( 'Invalid image metadata' );
|
|
7204
|
+
|
|
7205
|
+
const ratio = width / height;
|
|
7206
|
+
const normalizedRatio = ratio > 1 ? ratio : 1 / ratio;
|
|
7207
|
+
const squareThreshold = 1.2;
|
|
7208
|
+
const imageShape = normalizedRatio <= squareThreshold ? 'square' : 'rectangle';
|
|
7209
|
+
|
|
7210
|
+
const fileExtension = format === 'jpeg' ? 'jpg' : format;
|
|
7211
|
+
const contentType = `image/${format}`;
|
|
7212
|
+
|
|
7213
|
+
return {
|
|
7214
|
+
imageShape,
|
|
7215
|
+
width,
|
|
7216
|
+
height,
|
|
7217
|
+
fileExtension,
|
|
7218
|
+
contentType,
|
|
7219
|
+
};
|
|
7220
|
+
} catch ( error ) {
|
|
7221
|
+
console.error( 'Error processing image buffer:', error.message );
|
|
7222
|
+
throw error;
|
|
7223
|
+
}
|
|
7224
|
+
};
|
|
7225
|
+
|
|
7226
|
+
|
|
7227
|
+
if ( !req?.body?.storeName ) {
|
|
7228
|
+
return res.sendError( 'No store supplied', 200 );
|
|
7229
|
+
}
|
|
7230
|
+
|
|
7231
|
+
let storeQuery = {
|
|
7232
|
+
clientId: '11',
|
|
7233
|
+
$and: [
|
|
7234
|
+
{ storeName: req.body.storeName },
|
|
7235
|
+
// { storeName: { $in: [ 'LKST98' ] } },
|
|
7236
|
+
// { storeName: { $nin: [ 'LKST98', 'LKST1193' ] } },
|
|
7237
|
+
],
|
|
7238
|
+
};
|
|
7239
|
+
|
|
7240
|
+
let storeList = await storeService.find( storeQuery );
|
|
7241
|
+
|
|
7242
|
+
// const constantFixtureLength = 1220;
|
|
7243
|
+
const constantDetailedFixtureLength = 1220;
|
|
7244
|
+
|
|
7245
|
+
// const constantFixtureWidth = 610;
|
|
7246
|
+
const constantDetailedFixtureWidth = 1524;
|
|
7247
|
+
|
|
7248
|
+
const mmToFeet = 305;
|
|
7249
|
+
|
|
7250
|
+
function roundToTwo( num ) {
|
|
7251
|
+
return Math.round( num * 100 ) / 100;
|
|
7252
|
+
}
|
|
7253
|
+
|
|
7254
|
+
|
|
7255
|
+
for ( let i = 0; i < storeList.length; i++ ) {
|
|
7256
|
+
const storeData = await fetchStoreData( storeList[i], staticToken, res );
|
|
7257
|
+
|
|
7258
|
+
if ( storeData?.data?.message !== 'SUCCESS' ) continue;
|
|
7259
|
+
|
|
7260
|
+
|
|
7261
|
+
const storeDetails = storeList[i];
|
|
7262
|
+
|
|
7263
|
+
const existingPlanogram = await planoService.findOne( { storeName: storeData.storeName } );
|
|
7264
|
+
|
|
7265
|
+
// if ( existingPlanogram ) {
|
|
7266
|
+
// const checkTaskSubmitted = await planoTaskService.findOne( { planoId: existingPlanogram.toObject()._id } );
|
|
7267
|
+
|
|
7268
|
+
// const checkTaskCreated = await processedTaskService.findOne( { storeName: storeData.storeName, date_string: dayjs().format( 'YYYY-MM-DD' ), isPlano: true } );
|
|
7269
|
+
|
|
7270
|
+
// if ( checkTaskSubmitted || checkTaskCreated ) {
|
|
7271
|
+
// continue;
|
|
7272
|
+
// }
|
|
7273
|
+
// }
|
|
7274
|
+
|
|
7275
|
+
|
|
7276
|
+
if ( existingPlanogram?.toObject()?._id && mongoose.Types.ObjectId.isValid( existingPlanogram?.toObject()?._id ) ) {
|
|
7277
|
+
await Promise.all( [ planoService.deleteOne( { _id: existingPlanogram?.toObject()?._id } ), storeBuilderService.deleteMany( { planoId: existingPlanogram?.toObject()?._id } ),
|
|
7278
|
+
storeFixtureService.deleteMany( { planoId: existingPlanogram?.toObject()?._id } ), fixtureShelfService.deleteMany( { planoId: existingPlanogram?.toObject()?._id } ),
|
|
7279
|
+
planoMappingService.deleteMany( { planoId: existingPlanogram?.toObject()?._id } ),
|
|
7280
|
+
] );
|
|
7281
|
+
}
|
|
7282
|
+
|
|
7283
|
+
|
|
7284
|
+
const planoInsertData = {
|
|
7285
|
+
storeName: storeData.storeName,
|
|
7286
|
+
storeId: storeDetails?.toObject()?.storeId ? storeDetails.toObject().storeId : 'nil',
|
|
7287
|
+
layoutName: `${storeData.storeName} - Layout`,
|
|
7288
|
+
clientId: '11',
|
|
7289
|
+
attachments: [],
|
|
7290
|
+
createdBy: new mongoose.Types.ObjectId( '66a78cd82734f4f857cd6db6' ),
|
|
7291
|
+
createdByName: 'Bejan',
|
|
7292
|
+
createdByEmail: 'bejan@tangotech.co.in',
|
|
7293
|
+
status: 'completed',
|
|
7294
|
+
floorNumber: 1,
|
|
7295
|
+
productResolutionLevel: 'L2',
|
|
7296
|
+
scanType: 'qr',
|
|
7297
|
+
};
|
|
7298
|
+
|
|
7299
|
+
const insertedPlano = await planoService.upsertOne( { storeName: storeData.storeName }, planoInsertData );
|
|
7300
|
+
const planoDoc = insertedPlano.toObject();
|
|
7301
|
+
|
|
7302
|
+
const floors = new Set();
|
|
7303
|
+
|
|
7304
|
+
for ( const item of storeData.data.result ) {
|
|
7305
|
+
if ( item.floor ) {
|
|
7306
|
+
floors.add( item.floor );
|
|
7307
|
+
}
|
|
7308
|
+
|
|
7309
|
+
if ( Array.isArray( item.fixtures ) ) {
|
|
7310
|
+
for ( const fixture of item.fixtures ) {
|
|
7311
|
+
if ( fixture.floor ) {
|
|
7312
|
+
floors.add( fixture.floor );
|
|
7313
|
+
}
|
|
7314
|
+
}
|
|
7315
|
+
}
|
|
7316
|
+
}
|
|
7317
|
+
|
|
7318
|
+
const floorArray = Array.from( floors );
|
|
7319
|
+
|
|
7320
|
+
let isFloorKeyExist = true;
|
|
7321
|
+
|
|
7322
|
+
if ( !floorArray.length ) {
|
|
7323
|
+
isFloorKeyExist = false;
|
|
7324
|
+
floorArray.push( 'GROUND' );
|
|
7325
|
+
}
|
|
7326
|
+
|
|
7327
|
+
for ( let floorIndex = 0; floorIndex < floorArray.length; floorIndex++ ) {
|
|
7328
|
+
const leftWall = storeData.data.result.filter( ( entry ) => entry['main'] === 'LEFT WALL' );
|
|
7329
|
+
let leftFixtures = leftWall.flatMap( ( wall ) => wall.fixtures );
|
|
7330
|
+
if ( isFloorKeyExist ) {
|
|
7331
|
+
leftFixtures = leftFixtures.filter( ( fixture ) => fixture.floor === floorArray[floorIndex] );
|
|
7332
|
+
}
|
|
7333
|
+
const rightWall = storeData.data.result.filter( ( entry ) => entry['main'] === 'RIGHT WALL' );
|
|
7334
|
+
let rightFixtures = rightWall.flatMap( ( wall ) => wall.fixtures );
|
|
7335
|
+
if ( isFloorKeyExist ) {
|
|
7336
|
+
rightFixtures = rightFixtures.filter( ( fixture ) => fixture.floor === floorArray[floorIndex] );
|
|
7337
|
+
}
|
|
7338
|
+
const backWall = storeData.data.result.filter( ( entry ) => entry['main'] === 'RIGHT VERTICAL WALL' );
|
|
7339
|
+
let backFixtures = backWall.flatMap( ( wall ) => wall.fixtures );
|
|
7340
|
+
if ( isFloorKeyExist ) {
|
|
7341
|
+
backFixtures = backFixtures.filter( ( fixture ) => fixture.floor === floorArray[floorIndex] );
|
|
7342
|
+
}
|
|
7343
|
+
let floorFixtures = storeData.data.result.filter(
|
|
7344
|
+
( entry ) => entry['main'] === 'Euro Center' || entry['main'] === 'Euro Center Dr',
|
|
7345
|
+
);
|
|
7346
|
+
if ( isFloorKeyExist ) {
|
|
7347
|
+
floorFixtures = floorFixtures.filter( ( fixture ) => fixture.floor === floorArray[floorIndex] );
|
|
7348
|
+
}
|
|
7349
|
+
|
|
7350
|
+
// const leftXDistanceFeet = leftFixtures.length ? roundToTwo( ( leftFixtures.length * ( constantFixtureLength / mmToFeet ) ) ) : 0;
|
|
7351
|
+
const leftXDetailedDistanceFeet = leftFixtures.length ? roundToTwo( ( leftFixtures.length * ( constantDetailedFixtureLength / mmToFeet ) ) ) : 0;
|
|
7352
|
+
|
|
7353
|
+
// const leftYDistanceFeet = leftFixtures.length ? roundToTwo( ( ( constantFixtureWidth / mmToFeet ) ) ) : 0;
|
|
7354
|
+
const leftYDetailedDistanceFeet = leftFixtures.length ? roundToTwo( ( ( constantDetailedFixtureWidth / mmToFeet ) ) ) : 0;
|
|
7355
|
+
|
|
7356
|
+
// const rightXDistanceFeet = rightFixtures.length ? roundToTwo( ( rightFixtures.length * ( constantFixtureLength / mmToFeet ) ) ) : 0;
|
|
7357
|
+
const rightXDetailedDistanceFeet = rightFixtures.length ? roundToTwo( ( rightFixtures.length * ( constantDetailedFixtureLength / mmToFeet ) ) ) : 0;
|
|
7358
|
+
|
|
7359
|
+
// const rightYDistanceFeet = rightFixtures.length ? roundToTwo( ( constantFixtureWidth / mmToFeet ) ) : 0;
|
|
7360
|
+
const rightYDetailedDistanceFeet = rightFixtures.length ? roundToTwo( ( constantDetailedFixtureWidth / mmToFeet ) ): 0;
|
|
7361
|
+
|
|
7362
|
+
const maxFixturesPerRow = floorFixtures.length/2;
|
|
7363
|
+
const totalRows = 2;
|
|
7364
|
+
|
|
7365
|
+
// const floorXDistanceFeet = floorFixtures.length ? roundToTwo( ( ( floorFixtures.length/2 ) * ( constantFixtureLength / mmToFeet ) ) ) : 0;
|
|
7366
|
+
const floorXDetailedDistanceFeet = floorFixtures.length ? roundToTwo( ( ( floorFixtures.length/2 ) * ( constantDetailedFixtureLength / mmToFeet ) ) ): 0;
|
|
7367
|
+
|
|
7368
|
+
// const floorYDistanceFeet = floorFixtures.length ? roundToTwo( ( 2 * ( constantFixtureWidth/ mmToFeet ) ) ): 0;
|
|
7369
|
+
const floorYDetailedDistanceFeet = floorFixtures.length ? roundToTwo( 2 * ( constantDetailedFixtureWidth/mmToFeet ) ): 0;
|
|
7370
|
+
|
|
7371
|
+
// const backXDistanceFeet = backFixtures.length ? roundToTwo( ( constantFixtureWidth / mmToFeet ) ) : 0;
|
|
7372
|
+
const backXDetailedDistanceFeet = backFixtures.length ? roundToTwo( ( constantDetailedFixtureLength / mmToFeet ) ) : 0;
|
|
7373
|
+
|
|
7374
|
+
// const backYDistanceFeet = backFixtures.length ? roundToTwo( ( ( backFixtures.length * ( constantFixtureLength / mmToFeet ) ) + ( ( ( leftFixtures.length ? 1 : 0 ) + ( rightFixtures.length ? 1 : 0 ) * constantFixtureWidth )/mmToFeet ) ) ) : 0;
|
|
7375
|
+
const backYDetailedDistanceFeet = backFixtures.length ? roundToTwo( ( ( backFixtures.length * ( constantDetailedFixtureWidth / mmToFeet ) ) + ( ( ( leftFixtures.length ? 1 : 0 ) + ( rightFixtures.length ? 1 : 0 ) * constantDetailedFixtureWidth )/mmToFeet ) ) ): 0;
|
|
7376
|
+
|
|
7377
|
+
// const maxXDistance = Math.max( leftXDistanceFeet, rightXDistanceFeet, floorXDistanceFeet );
|
|
7378
|
+
const maxXDetailedDistance = Math.max( leftXDetailedDistanceFeet, rightXDetailedDistanceFeet, floorXDetailedDistanceFeet );
|
|
7379
|
+
|
|
7380
|
+
// const maxYDistance = Math.max( floorYDistanceFeet, backYDistanceFeet );
|
|
7381
|
+
const maxYDetailedDistance = Math.max( floorYDetailedDistanceFeet, backYDetailedDistanceFeet );
|
|
7382
|
+
|
|
7383
|
+
// const finalXDistance = roundToTwo( ( maxXDistance < ( backXDistanceFeet + floorXDistanceFeet )? ( ( backXDistanceFeet + floorXDistanceFeet ) + ( ( 2 * constantFixtureLength )/mmToFeet ) ) : ( floorFixtures.length && backFixtures.length ) ? ( maxXDistance + ( ( 2 * constantFixtureLength )/mmToFeet ) ) : maxXDistance ) );
|
|
7384
|
+
const finalXDetailedDistance = roundToTwo( ( maxXDetailedDistance < ( backXDetailedDistanceFeet + floorXDetailedDistanceFeet )? ( ( backXDetailedDistanceFeet + floorXDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureLength )/mmToFeet ) ) : ( floorFixtures.length && backFixtures.length ) ? ( maxXDetailedDistance + ( ( 2 * constantDetailedFixtureLength )/mmToFeet ) ) : maxXDetailedDistance ) );
|
|
7385
|
+
|
|
7386
|
+
// const finalYDistance = roundToTwo( ( maxYDistance < ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) ? ( ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) + ( ( 2 * constantFixtureWidth )/mmToFeet ) ) : ( maxYDistance + ( ( constantFixtureWidth )/mmToFeet ) ) ) );
|
|
7387
|
+
const finalYDetailedDistance = roundToTwo( ( maxYDetailedDistance < ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) ? ( ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureWidth )/mmToFeet ) ) : ( maxYDetailedDistance + ( ( constantDetailedFixtureWidth )/mmToFeet ) ) ) );
|
|
7388
|
+
|
|
7389
|
+
|
|
7390
|
+
const floorInsertData = {
|
|
7391
|
+
storeName: planoDoc.storeName,
|
|
7392
|
+
storeId: storeDetails?.toObject()?.storeId ? storeDetails.toObject().storeId : 'nil',
|
|
7393
|
+
layoutName: `${planoDoc.storeName} - Layout`,
|
|
7394
|
+
clientId: '11',
|
|
7395
|
+
floorNumber: floorIndex + 1,
|
|
7396
|
+
floorName: `${floorArray[floorIndex].toLowerCase()} floor`,
|
|
7397
|
+
crestLayout: true,
|
|
7398
|
+
layoutPolygon: [
|
|
7399
|
+
{
|
|
7400
|
+
elementType: 'wall',
|
|
7401
|
+
distance: finalXDetailedDistance,
|
|
7402
|
+
unit: 'ft',
|
|
7403
|
+
direction: 'right',
|
|
7404
|
+
angle: 90,
|
|
7405
|
+
elementNumber: 1,
|
|
7406
|
+
// detailedDistance: finalXDetailedDistance,
|
|
7407
|
+
},
|
|
7408
|
+
{
|
|
7409
|
+
elementType: 'wall',
|
|
7410
|
+
distance: finalYDetailedDistance,
|
|
7411
|
+
unit: 'ft',
|
|
7412
|
+
direction: 'down',
|
|
7413
|
+
angle: 90,
|
|
7414
|
+
elementNumber: 2,
|
|
7415
|
+
// detailedDistance: finalYDetailedDistance,
|
|
7416
|
+
},
|
|
7417
|
+
{
|
|
7418
|
+
elementType: 'wall',
|
|
7419
|
+
distance: finalXDetailedDistance,
|
|
7420
|
+
unit: 'ft',
|
|
7421
|
+
direction: 'left',
|
|
7422
|
+
angle: 90,
|
|
7423
|
+
elementNumber: 3,
|
|
7424
|
+
// detailedDistance: finalXDetailedDistance,
|
|
7425
|
+
},
|
|
7426
|
+
{
|
|
7427
|
+
elementType: 'wall',
|
|
7428
|
+
distance: roundToTwo( ( ( finalYDetailedDistance * 35 ) / 100 ) ),
|
|
7429
|
+
unit: 'ft',
|
|
7430
|
+
direction: 'up',
|
|
7431
|
+
angle: 90,
|
|
7432
|
+
elementNumber: 4,
|
|
7433
|
+
// detailedDistance: roundToTwo( ( ( finalYDetailedDistance * 35 ) / 100 ) ),
|
|
7434
|
+
},
|
|
7435
|
+
{
|
|
7436
|
+
elementType: 'entrance',
|
|
7437
|
+
distance: roundToTwo( ( ( finalYDetailedDistance * 30 ) / 100 ) ),
|
|
7438
|
+
unit: 'ft',
|
|
7439
|
+
direction: 'up',
|
|
7440
|
+
angle: 90,
|
|
7441
|
+
elementNumber: 1,
|
|
7442
|
+
// detailedDistance: roundToTwo( ( ( finalYDetailedDistance * 30 ) / 100 ) ),
|
|
7443
|
+
},
|
|
7444
|
+
{
|
|
7445
|
+
elementType: 'wall',
|
|
7446
|
+
distance: roundToTwo( ( ( finalYDetailedDistance * 35 ) / 100 ) ),
|
|
7447
|
+
unit: 'ft',
|
|
7448
|
+
direction: 'up',
|
|
7449
|
+
angle: 90,
|
|
7450
|
+
elementNumber: 5,
|
|
7451
|
+
// detailedDistance: roundToTwo( ( ( finalYDetailedDistance * 35 ) / 100 ) ),
|
|
7452
|
+
},
|
|
7453
|
+
],
|
|
7454
|
+
createdBy: new mongoose.Types.ObjectId( '66a78cd82734f4f857cd6db6' ),
|
|
7455
|
+
createdByName: 'Bejan',
|
|
7456
|
+
createdByEmail: 'bejan@tangotech.co.in',
|
|
7457
|
+
status: 'completed',
|
|
7458
|
+
planoId: planoDoc._id,
|
|
7459
|
+
};
|
|
7460
|
+
|
|
7461
|
+
const layoutDoc = await storeBuilderService.upsertOne( { planoId: planoDoc._id, floorNumber: floorIndex + 1 }, floorInsertData );
|
|
7462
|
+
|
|
7463
|
+
let fixtureCounter = 1;
|
|
7464
|
+
|
|
7465
|
+
|
|
7466
|
+
for ( let index = 0; index < leftFixtures.length; index++ ) {
|
|
7467
|
+
const fixture = leftFixtures[index];
|
|
7468
|
+
|
|
7469
|
+
const fixtureConfig = await fixtureLibraryService.findOne( { fixtureCategory: fixture.fixtureType } );
|
|
7470
|
+
if ( !fixtureConfig ) continue;
|
|
7471
|
+
const fixtureConfigDoc = fixtureConfig.toObject();
|
|
7472
|
+
|
|
7473
|
+
let mapKey = `${fixtureConfigDoc.fixtureCategory}${fixtureConfigDoc.fixtureWidth.value}${fixtureConfigDoc.fixtureWidth.unit},${fixture.header}`;
|
|
7474
|
+
|
|
7475
|
+
const fixtureProductSubBrandName = new Set();
|
|
7476
|
+
|
|
7477
|
+
|
|
7478
|
+
const shelfTemplate = fixtureConfigDoc.shelfConfig.map( ( configShelf, j ) => {
|
|
7479
|
+
const shelfZone = fixture.productZones.find( ( zone ) => zone.zoneName === configShelf.shelfZone );
|
|
7480
|
+
const shelfSection = shelfZone?.products.find( ( product ) => !product.isMerchandisingElement );
|
|
7481
|
+
|
|
7482
|
+
const shelfIdentifier = `shelf${j + 1}=${shelfSection?.productName}`;
|
|
7483
|
+
|
|
7484
|
+
mapKey += ','+shelfIdentifier;
|
|
7485
|
+
|
|
7486
|
+
const productSubBrandName = shelfSection?.productName?.replace( /\s*PIDs\b/g, '' )?.split( /\s*\+\s*/ ) || [];
|
|
7487
|
+
|
|
7488
|
+
productSubBrandName.forEach( ( item ) => fixtureProductSubBrandName.add( item ) );
|
|
7489
|
+
|
|
7490
|
+
return {
|
|
7491
|
+
shelfNumber: j+1,
|
|
7492
|
+
shelfType: configShelf?.shelfType,
|
|
7493
|
+
productPerShelf: configShelf?.productPerShelf,
|
|
7494
|
+
trayRows: configShelf?.trayRows,
|
|
7495
|
+
productBrandName: productSubBrandName,
|
|
7496
|
+
zone: configShelf.shelfZone,
|
|
7497
|
+
};
|
|
7498
|
+
} );
|
|
7499
|
+
|
|
7500
|
+
const vmConfig = fixture.productZones?.flatMap( ( zone ) => {
|
|
7501
|
+
const vms = zone.products.filter( ( vm ) => vm.isMerchandisingElement );
|
|
7502
|
+
const vmConfig = fixtureConfigDoc.vmConfig.filter( ( vm ) => vm.position === zone.zoneName );
|
|
7503
|
+
const pids = zone.products.filter( ( vm ) => !vm.isMerchandisingElement );
|
|
7504
|
+
|
|
7505
|
+
return vms.map( ( vm, k ) => {
|
|
7506
|
+
let configData = vmConfig[0];
|
|
7507
|
+
|
|
7508
|
+
if ( vm.productName === 'Creatr' && zone.zoneName === 'Mid' ) {
|
|
7509
|
+
configData = vmConfig.find( ( config ) => config.vmWidthmm === 905 );
|
|
7510
|
+
}
|
|
7511
|
+
|
|
7512
|
+
if ( vm.productName === 'Creatr' && zone.zoneName === 'Mid' && pids.length ) {
|
|
7513
|
+
configData = vmConfig.find( ( config ) => config.vmWidthmm === 230 );
|
|
7514
|
+
}
|
|
7515
|
+
|
|
7516
|
+
if ( configData.vmWidthmm === 905 ) {
|
|
7517
|
+
configData.zone = 'stretch';
|
|
7518
|
+
}
|
|
7519
|
+
|
|
7520
|
+
if ( configData.vmWidthmm === 230 ) {
|
|
7521
|
+
configData.zone = 'left';
|
|
7522
|
+
}
|
|
7523
|
+
|
|
7524
|
+
if ( !configData ) return;
|
|
7525
|
+
|
|
7526
|
+
const vmIdentifier = `vm${k+1}=${vm.productName}+${configData.vmHeightmm}+${configData.vmWidthmm}+${configData.startShelf}+${configData.endShelf}+${configData.zone}`;
|
|
7527
|
+
|
|
7528
|
+
mapKey += ','+vmIdentifier;
|
|
7529
|
+
|
|
7530
|
+
return {
|
|
7531
|
+
startYPosition: configData.startShelf,
|
|
7532
|
+
endYPosition: configData.endShelf,
|
|
7533
|
+
xZone: configData.zone,
|
|
7534
|
+
vmName: vm.productName,
|
|
7535
|
+
vmHeight: configData.vmHeightmm,
|
|
7536
|
+
vmWidth: configData.vmWidthmm,
|
|
7537
|
+
imageUrl: zone?.actual_image_url,
|
|
7538
|
+
};
|
|
7539
|
+
} );
|
|
7540
|
+
} );
|
|
7541
|
+
|
|
7542
|
+
const vmTemplate = await Promise.all( vmConfig.map( async ( vmTemplate ) => {
|
|
7543
|
+
const vmInsertData = {
|
|
7544
|
+
clientId: '11',
|
|
7545
|
+
vmName: vmTemplate.vmName,
|
|
7546
|
+
vmHeight: {
|
|
7547
|
+
value: vmTemplate.vmHeight,
|
|
7548
|
+
unit: 'mm',
|
|
7549
|
+
},
|
|
7550
|
+
vmWidth: {
|
|
7551
|
+
value: vmTemplate.vmWidth,
|
|
7552
|
+
unit: 'mm',
|
|
7553
|
+
},
|
|
7554
|
+
status: 'complete',
|
|
7555
|
+
vmBrand: vmTemplate.vmBrand,
|
|
7556
|
+
};
|
|
7557
|
+
if ( vmTemplate?.imageUrl ) {
|
|
7558
|
+
const parsedUrl = new URL( vmTemplate.imageUrl );
|
|
7559
|
+
const attachmentId = parsedUrl.searchParams.get( 'attachment_id' );
|
|
7560
|
+
|
|
7561
|
+
const isVmImageExist = await planoVmService.findOne( { crestImageId: attachmentId } );
|
|
7562
|
+
|
|
7563
|
+
if ( !isVmImageExist ) {
|
|
7564
|
+
const vmImageData = await fetchVmImage( attachmentId );
|
|
7565
|
+
|
|
7566
|
+
const imageMeta = await getImageMetadata( vmImageData );
|
|
7567
|
+
|
|
7568
|
+
const params = {
|
|
7569
|
+
Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
|
|
7570
|
+
Key: `vmType/`,
|
|
7571
|
+
fileName: `${attachmentId}.${imageMeta.fileExtension}`,
|
|
7572
|
+
ContentType: imageMeta.contentType,
|
|
7573
|
+
body: vmImageData,
|
|
7574
|
+
};
|
|
7575
|
+
|
|
7576
|
+
const imgUpload = await fileUpload( params );
|
|
7577
|
+
|
|
7578
|
+
vmInsertData.crestImageId = attachmentId;
|
|
7579
|
+
vmInsertData.vmImageUrl = imgUpload.Key;
|
|
7580
|
+
|
|
7581
|
+
|
|
7582
|
+
if ( imageMeta.imageShape === 'square' ) {
|
|
7583
|
+
vmInsertData.vmHeight.value = 100;
|
|
7584
|
+
vmInsertData.vmWidth.value = 230;
|
|
7585
|
+
}
|
|
7586
|
+
} else {
|
|
7587
|
+
vmInsertData.crestImageId = attachmentId;
|
|
7588
|
+
vmInsertData.vmImageUrl = isVmImageExist.toObject().vmImageUrl;
|
|
7589
|
+
}
|
|
7590
|
+
}
|
|
7591
|
+
|
|
7592
|
+
const vmDetails = await planoVmService.upsertOne(
|
|
7593
|
+
{
|
|
7594
|
+
'vmName': vmInsertData.vmName,
|
|
7595
|
+
},
|
|
7596
|
+
vmInsertData,
|
|
7597
|
+
);
|
|
7598
|
+
|
|
7599
|
+
return {
|
|
7600
|
+
vmId: vmDetails.toObject()._id,
|
|
7601
|
+
startYPosition: vmTemplate.startYPosition,
|
|
7602
|
+
endYPosition: vmTemplate.endYPosition,
|
|
7603
|
+
xZone: vmTemplate.xZone,
|
|
7604
|
+
};
|
|
7605
|
+
} ) );
|
|
7606
|
+
|
|
7607
|
+
const existingTemplateWithMaxIndex = await fixtureConfigService.sortAndFindOne(
|
|
7608
|
+
{ fixtureCategory: fixtureConfigDoc.fixtureCategory,
|
|
7609
|
+
fixtureWidth: fixtureConfigDoc.fixtureWidth }, {}, { templateIndex: -1 } );
|
|
7610
|
+
|
|
7611
|
+
let templateIndex = 1;
|
|
7612
|
+
|
|
7613
|
+
if ( existingTemplateWithMaxIndex.length ) {
|
|
7614
|
+
templateIndex = existingTemplateWithMaxIndex[0].toObject().templateIndex + 1;
|
|
7615
|
+
}
|
|
7616
|
+
|
|
7617
|
+
let templateName = `Template-${templateIndex}-${fixtureConfigDoc.fixtureCategory}`;
|
|
7618
|
+
|
|
7619
|
+
const isTemplateExist = await fixtureConfigService.findOne( { crestMapKey: mapKey } );
|
|
7620
|
+
if ( isTemplateExist ) {
|
|
7621
|
+
templateIndex = undefined;
|
|
7622
|
+
templateName = undefined;
|
|
7623
|
+
}
|
|
7624
|
+
|
|
7625
|
+
|
|
7626
|
+
const fixtureTemplateData = {
|
|
7627
|
+
...fixtureConfigDoc,
|
|
7628
|
+
'shelfConfig': shelfTemplate,
|
|
7629
|
+
'vmConfig': vmTemplate,
|
|
7630
|
+
'clientId': fixtureConfigDoc.clientId,
|
|
7631
|
+
'fixtureName': templateName,
|
|
7632
|
+
'templateIndex': templateIndex,
|
|
7633
|
+
'header': {
|
|
7634
|
+
label: fixture.header ? fixture.header : fixture.fixtureSubname[0],
|
|
7635
|
+
isEnabled: true,
|
|
7636
|
+
},
|
|
7637
|
+
'footer': {
|
|
7638
|
+
label: fixture.footer,
|
|
7639
|
+
isEnabled: true,
|
|
7640
|
+
},
|
|
7641
|
+
'isBodyEnabled': true,
|
|
7642
|
+
'productResolutionLevel': 'L3',
|
|
7643
|
+
'productBrandName': [ ...fixtureProductSubBrandName ],
|
|
7644
|
+
'fixtureLibraryId': fixtureConfigDoc._id,
|
|
7645
|
+
'crestMapKey': mapKey,
|
|
7646
|
+
};
|
|
7647
|
+
|
|
7648
|
+
delete fixtureTemplateData._id;
|
|
7649
|
+
|
|
7650
|
+
|
|
7651
|
+
const fixtureTemplate = await fixtureConfigService.upsertOne(
|
|
7652
|
+
{ crestMapKey: mapKey },
|
|
7653
|
+
fixtureTemplateData,
|
|
7654
|
+
);
|
|
7655
|
+
|
|
7656
|
+
const fixtureData = {
|
|
7657
|
+
...fixtureTemplate.toObject(),
|
|
7658
|
+
'storeName': layoutDoc.storeName,
|
|
7659
|
+
'storeId': storeDetails?.toObject()?.storeId ? storeDetails.toObject().storeId : 'nil',
|
|
7660
|
+
'planoId': layoutDoc.planoId,
|
|
7661
|
+
'floorId': layoutDoc._id,
|
|
7662
|
+
'associatedElementType': 'wall',
|
|
7663
|
+
'associatedElementNumber': 1,
|
|
7664
|
+
'relativePosition': {
|
|
7665
|
+
'x': roundToTwo( ( index * ( constantDetailedFixtureLength / mmToFeet ) ) ),
|
|
7666
|
+
'y': 0,
|
|
7667
|
+
'unit': 'ft',
|
|
7668
|
+
},
|
|
7669
|
+
'fixtureNumber': fixtureCounter,
|
|
7670
|
+
// 'relativeDetailedPosition': {
|
|
7671
|
+
// 'x': roundToTwo( ( index * ( constantDetailedFixtureLength / mmToFeet ) ) ),
|
|
7672
|
+
// 'y': 0,
|
|
7673
|
+
// 'unit': 'ft',
|
|
7674
|
+
// },
|
|
7675
|
+
'associatedElementFixtureNumber': index+1,
|
|
7676
|
+
'fixtureConfigId': fixtureTemplate.toObject()._id,
|
|
7677
|
+
};
|
|
7678
|
+
|
|
7679
|
+
delete fixtureData._id;
|
|
7680
|
+
delete fixtureData.shelfConfig;
|
|
7681
|
+
|
|
7682
|
+
const createdFixture = await storeFixtureService.upsertOne(
|
|
7683
|
+
{
|
|
7684
|
+
floorId: layoutDoc._id,
|
|
7685
|
+
fixtureNumber: fixtureCounter++,
|
|
7686
|
+
},
|
|
7687
|
+
fixtureData,
|
|
7688
|
+
);
|
|
7689
|
+
|
|
7690
|
+
if ( !fixtureConfigDoc.shelfConfig.length || fixture.header === 'CL' || fixture.fixtureSubname?.includes( 'CL' ) ) continue;
|
|
7691
|
+
|
|
7692
|
+
fixtureTemplate.shelfConfig.forEach( async ( configShelf, j ) => {
|
|
7693
|
+
const shelfData = {
|
|
7694
|
+
'clientId': '11',
|
|
7695
|
+
'storeName': layoutDoc.storeName,
|
|
7696
|
+
'storeId': storeDetails?.toObject()?.storeId ? storeDetails.toObject().storeId : 'nil',
|
|
7697
|
+
'planoId': layoutDoc.planoId,
|
|
7698
|
+
'floorId': layoutDoc._id,
|
|
7699
|
+
'fixtureId': createdFixture._id,
|
|
7700
|
+
'shelfNumber': j + 1,
|
|
7701
|
+
'shelfOrder': 'LTR',
|
|
7702
|
+
'shelfCapacity': configShelf.shelfCapacity,
|
|
7703
|
+
'productBrandName': configShelf.productBrandName,
|
|
7704
|
+
'shelfType': configShelf.shelfType,
|
|
7705
|
+
'productPerShelf': configShelf.productPerShelf,
|
|
7706
|
+
'trayRows': configShelf.trayRows,
|
|
7707
|
+
'productPerTray': configShelf.productPerTray,
|
|
7708
|
+
'zone': configShelf.zone,
|
|
7709
|
+
};
|
|
7710
|
+
|
|
7711
|
+
await fixtureShelfService.upsertOne(
|
|
7712
|
+
{
|
|
7713
|
+
fixtureId: createdFixture._id,
|
|
7714
|
+
shelfNumber: j + 1,
|
|
7715
|
+
},
|
|
7716
|
+
shelfData,
|
|
7717
|
+
);
|
|
7718
|
+
} );
|
|
7719
|
+
}
|
|
7720
|
+
|
|
7721
|
+
for ( let index = 0; index < backFixtures.length; index++ ) {
|
|
7722
|
+
const fixture = backFixtures[index];
|
|
7723
|
+
|
|
7724
|
+
const fixtureConfig = await fixtureLibraryService.findOne( { fixtureCategory: fixture.fixtureType } );
|
|
7725
|
+
if ( !fixtureConfig ) continue;
|
|
7726
|
+
const fixtureConfigDoc = fixtureConfig.toObject();
|
|
7727
|
+
|
|
7728
|
+
let mapKey = `${fixtureConfigDoc.fixtureCategory}${fixtureConfigDoc.fixtureWidth.value}${fixtureConfigDoc.fixtureWidth.unit},${fixture.header}`;
|
|
7729
|
+
|
|
7730
|
+
const fixtureProductSubBrandName = new Set();
|
|
7731
|
+
|
|
7732
|
+
|
|
7733
|
+
const shelfTemplate = fixtureConfigDoc.shelfConfig.map( ( configShelf, j ) => {
|
|
7734
|
+
const shelfZone = fixture.productZones.find( ( zone ) => zone.zoneName === configShelf.shelfZone );
|
|
7735
|
+
const shelfSection = shelfZone?.products.find( ( product ) => !product.isMerchandisingElement );
|
|
7736
|
+
|
|
7737
|
+
const shelfIdentifier = `shelf${j + 1}=${shelfSection?.productName}`;
|
|
7738
|
+
|
|
7739
|
+
mapKey += ','+shelfIdentifier;
|
|
7740
|
+
|
|
7741
|
+
const productSubBrandName = shelfSection?.productName?.replace( /\s*PIDs\b/g, '' )?.split( /\s*\+\s*/ ) || [];
|
|
7742
|
+
|
|
7743
|
+
productSubBrandName.forEach( ( item ) => fixtureProductSubBrandName.add( item ) );
|
|
7744
|
+
|
|
7745
|
+
return {
|
|
7746
|
+
shelfNumber: j+1,
|
|
7747
|
+
shelfType: configShelf?.shelfType,
|
|
7748
|
+
productPerShelf: configShelf?.productPerShelf,
|
|
7749
|
+
trayRows: configShelf?.trayRows,
|
|
7750
|
+
productBrandName: productSubBrandName,
|
|
7751
|
+
zone: configShelf.shelfZone,
|
|
7752
|
+
};
|
|
7753
|
+
} );
|
|
7754
|
+
|
|
7755
|
+
const vmConfig = fixture.productZones?.flatMap( ( zone ) => {
|
|
7756
|
+
const vms = zone.products.filter( ( vm ) => vm.isMerchandisingElement );
|
|
7757
|
+
const vmConfig = fixtureConfigDoc.vmConfig.filter( ( vm ) => vm.position === zone.zoneName );
|
|
7758
|
+
const pids = zone.products.filter( ( vm ) => !vm.isMerchandisingElement );
|
|
7759
|
+
|
|
7760
|
+
return vms.map( ( vm, k ) => {
|
|
7761
|
+
let configData = vmConfig[0];
|
|
7762
|
+
|
|
7763
|
+
if ( vm.productName === 'Creatr' && zone.zoneName === 'Mid' ) {
|
|
7764
|
+
configData = vmConfig.find( ( config ) => config.vmWidthmm === 905 );
|
|
7765
|
+
}
|
|
7766
|
+
|
|
7767
|
+
if ( vm.productName === 'Creatr' && zone.zoneName === 'Mid' && pids.length ) {
|
|
7768
|
+
configData = vmConfig.find( ( config ) => config.vmWidthmm === 230 );
|
|
7769
|
+
}
|
|
7770
|
+
|
|
7771
|
+
if ( configData.vmWidthmm === 905 ) {
|
|
7772
|
+
configData.zone = 'stretch';
|
|
7773
|
+
}
|
|
7774
|
+
|
|
7775
|
+
if ( configData.vmWidthmm === 230 ) {
|
|
7776
|
+
configData.zone = 'left';
|
|
7777
|
+
}
|
|
7778
|
+
|
|
7779
|
+
if ( !configData ) return;
|
|
7780
|
+
|
|
7781
|
+
const vmIdentifier = `vm${k+1}=${vm.productName}+${configData.vmHeightmm}+${configData.vmWidthmm}+${configData.startShelf}+${configData.endShelf}+${configData.zone}`;
|
|
7782
|
+
|
|
7783
|
+
mapKey += ','+vmIdentifier;
|
|
7784
|
+
|
|
7785
|
+
return {
|
|
7786
|
+
startYPosition: configData.startShelf,
|
|
7787
|
+
endYPosition: configData.endShelf,
|
|
7788
|
+
xZone: configData.zone,
|
|
7789
|
+
vmName: vm.productName,
|
|
7790
|
+
vmHeight: configData.vmHeightmm,
|
|
7791
|
+
vmWidth: configData.vmWidthmm,
|
|
7792
|
+
imageUrl: zone?.actual_image_url,
|
|
7793
|
+
};
|
|
7794
|
+
} );
|
|
7795
|
+
} );
|
|
7796
|
+
|
|
7797
|
+
const vmTemplate = await Promise.all( vmConfig.map( async ( vmTemplate ) => {
|
|
7798
|
+
const vmInsertData = {
|
|
7799
|
+
clientId: '11',
|
|
7800
|
+
vmName: vmTemplate.vmName,
|
|
7801
|
+
vmHeight: {
|
|
7802
|
+
value: vmTemplate.vmHeight,
|
|
7803
|
+
unit: 'mm',
|
|
7804
|
+
},
|
|
7805
|
+
vmWidth: {
|
|
7806
|
+
value: vmTemplate.vmWidth,
|
|
7807
|
+
unit: 'mm',
|
|
7808
|
+
},
|
|
7809
|
+
status: 'complete',
|
|
7810
|
+
vmBrand: vmTemplate.vmBrand,
|
|
7811
|
+
};
|
|
7812
|
+
if ( vmTemplate?.imageUrl ) {
|
|
7813
|
+
const parsedUrl = new URL( vmTemplate.imageUrl );
|
|
7814
|
+
const attachmentId = parsedUrl.searchParams.get( 'attachment_id' );
|
|
7815
|
+
|
|
7816
|
+
const isVmImageExist = await planoVmService.findOne( { crestImageId: attachmentId } );
|
|
7817
|
+
|
|
7818
|
+
if ( !isVmImageExist ) {
|
|
7819
|
+
const vmImageData = await fetchVmImage( attachmentId );
|
|
7820
|
+
|
|
7821
|
+
const imageMeta = await getImageMetadata( vmImageData );
|
|
7822
|
+
|
|
7823
|
+
const params = {
|
|
7824
|
+
Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
|
|
7825
|
+
Key: `vmType/`,
|
|
7826
|
+
fileName: `${attachmentId}.${imageMeta.fileExtension}`,
|
|
7827
|
+
ContentType: imageMeta.contentType,
|
|
7828
|
+
body: vmImageData,
|
|
7829
|
+
};
|
|
7830
|
+
|
|
7831
|
+
const imgUpload = await fileUpload( params );
|
|
7832
|
+
|
|
7833
|
+
|
|
7834
|
+
vmInsertData.crestImageId = attachmentId;
|
|
7835
|
+
vmInsertData.vmImageUrl = imgUpload.Key;
|
|
7836
|
+
|
|
7837
|
+
|
|
7838
|
+
if ( imageMeta.imageShape === 'square' ) {
|
|
7839
|
+
vmInsertData.vmHeight.value = 100;
|
|
7840
|
+
vmInsertData.vmWidth.value = 230;
|
|
7841
|
+
}
|
|
7842
|
+
} else {
|
|
7843
|
+
vmInsertData.crestImageId = attachmentId;
|
|
7844
|
+
vmInsertData.vmImageUrl = isVmImageExist.toObject().vmImageUrl;
|
|
7845
|
+
}
|
|
7846
|
+
}
|
|
7847
|
+
|
|
7848
|
+
const vmDetails = await planoVmService.upsertOne(
|
|
7849
|
+
{
|
|
7850
|
+
'vmName': vmInsertData.vmName,
|
|
7851
|
+
},
|
|
7852
|
+
vmInsertData,
|
|
7853
|
+
);
|
|
7854
|
+
|
|
7855
|
+
return {
|
|
7856
|
+
vmId: vmDetails.toObject()._id,
|
|
7857
|
+
startYPosition: vmTemplate.startYPosition,
|
|
7858
|
+
endYPosition: vmTemplate.endYPosition,
|
|
7859
|
+
xZone: vmTemplate.xZone,
|
|
7860
|
+
};
|
|
7861
|
+
} ) );
|
|
7862
|
+
|
|
7863
|
+
const existingTemplateWithMaxIndex = await fixtureConfigService.sortAndFindOne(
|
|
7864
|
+
{ fixtureCategory: fixtureConfigDoc.fixtureCategory,
|
|
7865
|
+
fixtureWidth: fixtureConfigDoc.fixtureWidth }, {}, { templateIndex: -1 } );
|
|
7866
|
+
|
|
7867
|
+
let templateIndex = 1;
|
|
7868
|
+
|
|
7869
|
+
if ( existingTemplateWithMaxIndex.length ) {
|
|
7870
|
+
templateIndex = existingTemplateWithMaxIndex[0].toObject().templateIndex + 1;
|
|
7871
|
+
}
|
|
7872
|
+
|
|
7873
|
+
let templateName = `Template-${templateIndex}-${fixtureConfigDoc.fixtureCategory}`;
|
|
7874
|
+
|
|
7875
|
+
const isTemplateExist = await fixtureConfigService.findOne( { crestMapKey: mapKey } );
|
|
7876
|
+
if ( isTemplateExist ) {
|
|
7877
|
+
templateIndex = undefined;
|
|
7878
|
+
templateName = undefined;
|
|
7879
|
+
}
|
|
7880
|
+
|
|
7881
|
+
const fixtureTemplateData = {
|
|
7882
|
+
...fixtureConfigDoc,
|
|
7883
|
+
'shelfConfig': shelfTemplate,
|
|
7884
|
+
'vmConfig': vmTemplate,
|
|
7885
|
+
'clientId': fixtureConfigDoc.clientId,
|
|
7886
|
+
'fixtureName': templateName,
|
|
7887
|
+
'templateIndex': templateIndex,
|
|
7888
|
+
'header': {
|
|
7889
|
+
label: fixture.header ? fixture.header : fixture.fixtureSubname[0],
|
|
7890
|
+
isEnabled: true,
|
|
7891
|
+
},
|
|
7892
|
+
'footer': {
|
|
7893
|
+
label: fixture.footer,
|
|
7894
|
+
isEnabled: true,
|
|
7895
|
+
},
|
|
7896
|
+
'isBodyEnabled': true,
|
|
7897
|
+
'productResolutionLevel': 'L3',
|
|
7898
|
+
'productBrandName': [ ...fixtureProductSubBrandName ],
|
|
7899
|
+
'fixtureLibraryId': fixtureConfigDoc._id,
|
|
7900
|
+
'crestMapKey': mapKey,
|
|
7901
|
+
};
|
|
7902
|
+
|
|
7903
|
+
delete fixtureTemplateData._id;
|
|
7904
|
+
|
|
7905
|
+
|
|
7906
|
+
const fixtureTemplate = await fixtureConfigService.upsertOne(
|
|
7907
|
+
{ crestMapKey: mapKey },
|
|
7908
|
+
fixtureTemplateData,
|
|
7909
|
+
);
|
|
7910
|
+
|
|
7911
|
+
const fixtureData = {
|
|
7912
|
+
...fixtureTemplate.toObject(),
|
|
7913
|
+
'storeName': layoutDoc.storeName,
|
|
7914
|
+
'storeId': storeDetails?.toObject()?.storeId ? storeDetails.toObject().storeId : 'nil',
|
|
7915
|
+
'planoId': layoutDoc.planoId,
|
|
7916
|
+
'floorId': layoutDoc._id,
|
|
7917
|
+
'associatedElementType': 'wall',
|
|
7918
|
+
'associatedElementNumber': 2,
|
|
7919
|
+
'relativePosition': {
|
|
7920
|
+
'x': roundToTwo( ( finalXDetailedDistance - ( constantDetailedFixtureLength/mmToFeet ) ) ),
|
|
7921
|
+
'y': roundToTwo( ( ( index * ( ( constantDetailedFixtureWidth/mmToFeet ) ) ) + ( ( leftFixtures.length ? 1 : 0 ) * constantDetailedFixtureWidth/mmToFeet ) ) ),
|
|
7922
|
+
'unit': 'ft',
|
|
7923
|
+
},
|
|
7924
|
+
'fixtureNumber': fixtureCounter,
|
|
7925
|
+
// 'relativeDetailedPosition': {
|
|
7926
|
+
// 'x': roundToTwo( ( finalXDetailedDistance - ( constantDetailedFixtureLength/mmToFeet ) ) ),
|
|
7927
|
+
// 'y': roundToTwo( ( ( index * ( ( constantDetailedFixtureWidth/mmToFeet ) ) ) + ( ( leftFixtures.length ? 1 : 0 ) * constantDetailedFixtureWidth/mmToFeet ) ) ),
|
|
7928
|
+
// 'unit': 'ft',
|
|
7929
|
+
// },
|
|
7930
|
+
'associatedElementFixtureNumber': index+1,
|
|
7931
|
+
'fixtureConfigId': fixtureTemplate.toObject()._id,
|
|
7932
|
+
};
|
|
7933
|
+
|
|
7934
|
+
delete fixtureData._id;
|
|
7935
|
+
delete fixtureData.shelfConfig;
|
|
7936
|
+
|
|
7937
|
+
const createdFixture = await storeFixtureService.upsertOne(
|
|
7938
|
+
{
|
|
7939
|
+
floorId: layoutDoc._id,
|
|
7940
|
+
fixtureNumber: fixtureCounter++,
|
|
7941
|
+
},
|
|
7942
|
+
fixtureData,
|
|
7943
|
+
);
|
|
7944
|
+
|
|
7945
|
+
if ( !fixtureConfigDoc.shelfConfig.length || fixture.header === 'CL' || fixture.fixtureSubname?.includes( 'CL' ) ) continue;
|
|
7946
|
+
|
|
7947
|
+
fixtureTemplate.shelfConfig.forEach( async ( configShelf, j ) => {
|
|
7948
|
+
const shelfData = {
|
|
7949
|
+
'clientId': '11',
|
|
7950
|
+
'storeName': layoutDoc.storeName,
|
|
7951
|
+
'storeId': storeDetails?.toObject()?.storeId ? storeDetails.toObject().storeId : 'nil',
|
|
7952
|
+
'planoId': layoutDoc.planoId,
|
|
7953
|
+
'floorId': layoutDoc._id,
|
|
7954
|
+
'fixtureId': createdFixture._id,
|
|
7955
|
+
'shelfNumber': j + 1,
|
|
7956
|
+
'shelfOrder': 'LTR',
|
|
7957
|
+
'shelfCapacity': configShelf.shelfCapacity,
|
|
7958
|
+
'productBrandName': configShelf.productBrandName,
|
|
7959
|
+
'shelfType': configShelf.shelfType,
|
|
7960
|
+
'productPerShelf': configShelf.productPerShelf,
|
|
7961
|
+
'trayRows': configShelf.trayRows,
|
|
7962
|
+
'productPerTray': configShelf.productPerTray,
|
|
7963
|
+
'zone': configShelf.zone,
|
|
7964
|
+
};
|
|
7965
|
+
|
|
7966
|
+
await fixtureShelfService.upsertOne(
|
|
7967
|
+
{
|
|
7968
|
+
fixtureId: createdFixture._id,
|
|
7969
|
+
shelfNumber: j + 1,
|
|
7970
|
+
},
|
|
7971
|
+
shelfData,
|
|
7972
|
+
);
|
|
7973
|
+
} );
|
|
7974
|
+
}
|
|
7975
|
+
|
|
7976
|
+
for ( let index = 0; index < rightFixtures.length; index++ ) {
|
|
7977
|
+
const fixture = rightFixtures[index];
|
|
7978
|
+
|
|
7979
|
+
const fixtureConfig = await fixtureLibraryService.findOne( { fixtureCategory: fixture.fixtureType } );
|
|
7980
|
+
if ( !fixtureConfig ) continue;
|
|
7981
|
+
const fixtureConfigDoc = fixtureConfig.toObject();
|
|
7982
|
+
|
|
7983
|
+
let mapKey = `${fixtureConfigDoc.fixtureCategory}${fixtureConfigDoc.fixtureWidth.value}${fixtureConfigDoc.fixtureWidth.unit},${fixture.header}`;
|
|
7984
|
+
|
|
7985
|
+
const fixtureProductSubBrandName = new Set();
|
|
7986
|
+
|
|
7987
|
+
|
|
7988
|
+
const shelfTemplate = fixtureConfigDoc.shelfConfig.map( ( configShelf, j ) => {
|
|
7989
|
+
const shelfZone = fixture.productZones.find( ( zone ) => zone.zoneName === configShelf.shelfZone );
|
|
7990
|
+
const shelfSection = shelfZone?.products.find( ( product ) => !product.isMerchandisingElement );
|
|
7991
|
+
|
|
7992
|
+
const shelfIdentifier = `shelf${j + 1}=${shelfSection?.productName}`;
|
|
7993
|
+
|
|
7994
|
+
mapKey += ','+shelfIdentifier;
|
|
7995
|
+
|
|
7996
|
+
const productSubBrandName = shelfSection?.productName?.replace( /\s*PIDs\b/g, '' )?.split( /\s*\+\s*/ ) || [];
|
|
7997
|
+
|
|
7998
|
+
productSubBrandName.forEach( ( item ) => fixtureProductSubBrandName.add( item ) );
|
|
7999
|
+
|
|
8000
|
+
return {
|
|
8001
|
+
shelfNumber: j+1,
|
|
8002
|
+
shelfType: configShelf?.shelfType,
|
|
8003
|
+
productPerShelf: configShelf?.productPerShelf,
|
|
8004
|
+
trayRows: configShelf?.trayRows,
|
|
8005
|
+
productBrandName: productSubBrandName,
|
|
8006
|
+
zone: configShelf.shelfZone,
|
|
8007
|
+
};
|
|
8008
|
+
} );
|
|
8009
|
+
|
|
8010
|
+
const vmConfig = fixture.productZones?.flatMap( ( zone ) => {
|
|
8011
|
+
const vms = zone.products.filter( ( vm ) => vm.isMerchandisingElement );
|
|
8012
|
+
const vmConfig = fixtureConfigDoc.vmConfig.filter( ( vm ) => vm.position === zone.zoneName );
|
|
8013
|
+
const pids = zone.products.filter( ( vm ) => !vm.isMerchandisingElement );
|
|
8014
|
+
|
|
8015
|
+
return vms.map( ( vm, k ) => {
|
|
8016
|
+
let configData = vmConfig[0];
|
|
8017
|
+
|
|
8018
|
+
if ( vm.productName === 'Creatr' && zone.zoneName === 'Mid' ) {
|
|
8019
|
+
configData = vmConfig.find( ( config ) => config.vmWidthmm === 905 );
|
|
8020
|
+
}
|
|
8021
|
+
|
|
8022
|
+
if ( vm.productName === 'Creatr' && zone.zoneName === 'Mid' && pids.length ) {
|
|
8023
|
+
configData = vmConfig.find( ( config ) => config.vmWidthmm === 230 );
|
|
8024
|
+
}
|
|
8025
|
+
|
|
8026
|
+
if ( configData.vmWidthmm === 905 ) {
|
|
8027
|
+
configData.zone = 'stretch';
|
|
8028
|
+
}
|
|
8029
|
+
|
|
8030
|
+
if ( configData.vmWidthmm === 230 ) {
|
|
8031
|
+
configData.zone = 'left';
|
|
8032
|
+
}
|
|
8033
|
+
|
|
8034
|
+
if ( !configData ) return;
|
|
8035
|
+
|
|
8036
|
+
const vmIdentifier = `vm${k+1}=${vm.productName}+${configData.vmHeightmm}+${configData.vmWidthmm}+${configData.startShelf}+${configData.endShelf}+${configData.zone}`;
|
|
8037
|
+
|
|
8038
|
+
mapKey += ','+vmIdentifier;
|
|
8039
|
+
|
|
8040
|
+
return {
|
|
8041
|
+
startYPosition: configData.startShelf,
|
|
8042
|
+
endYPosition: configData.endShelf,
|
|
8043
|
+
xZone: configData.zone,
|
|
8044
|
+
vmName: vm.productName,
|
|
8045
|
+
vmHeight: configData.vmHeightmm,
|
|
8046
|
+
vmWidth: configData.vmWidthmm,
|
|
8047
|
+
imageUrl: zone?.actual_image_url,
|
|
8048
|
+
};
|
|
8049
|
+
} );
|
|
8050
|
+
} );
|
|
8051
|
+
|
|
8052
|
+
const vmTemplate = await Promise.all( vmConfig.map( async ( vmTemplate ) => {
|
|
8053
|
+
const vmInsertData = {
|
|
8054
|
+
clientId: '11',
|
|
8055
|
+
vmName: vmTemplate.vmName,
|
|
8056
|
+
vmHeight: {
|
|
8057
|
+
value: vmTemplate.vmHeight,
|
|
8058
|
+
unit: 'mm',
|
|
8059
|
+
},
|
|
8060
|
+
vmWidth: {
|
|
8061
|
+
value: vmTemplate.vmWidth,
|
|
8062
|
+
unit: 'mm',
|
|
8063
|
+
},
|
|
8064
|
+
status: 'complete',
|
|
8065
|
+
vmBrand: vmTemplate.vmBrand,
|
|
8066
|
+
};
|
|
8067
|
+
if ( vmTemplate?.imageUrl ) {
|
|
8068
|
+
const parsedUrl = new URL( vmTemplate.imageUrl );
|
|
8069
|
+
const attachmentId = parsedUrl.searchParams.get( 'attachment_id' );
|
|
8070
|
+
|
|
8071
|
+
const isVmImageExist = await planoVmService.findOne( { crestImageId: attachmentId } );
|
|
8072
|
+
|
|
8073
|
+
if ( !isVmImageExist ) {
|
|
8074
|
+
const vmImageData = await fetchVmImage( attachmentId );
|
|
8075
|
+
|
|
8076
|
+
const imageMeta = await getImageMetadata( vmImageData );
|
|
8077
|
+
|
|
8078
|
+
const params = {
|
|
8079
|
+
Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
|
|
8080
|
+
Key: `vmType/`,
|
|
8081
|
+
fileName: `${attachmentId}.${imageMeta.fileExtension}`,
|
|
8082
|
+
ContentType: imageMeta.contentType,
|
|
8083
|
+
body: vmImageData,
|
|
8084
|
+
};
|
|
8085
|
+
|
|
8086
|
+
const imgUpload = await fileUpload( params );
|
|
8087
|
+
|
|
8088
|
+
vmInsertData.crestImageId = attachmentId;
|
|
8089
|
+
vmInsertData.vmImageUrl = imgUpload.Key;
|
|
8090
|
+
|
|
8091
|
+
|
|
8092
|
+
if ( imageMeta.imageShape === 'square' ) {
|
|
8093
|
+
vmInsertData.vmHeight.value = 100;
|
|
8094
|
+
vmInsertData.vmWidth.value = 230;
|
|
8095
|
+
}
|
|
8096
|
+
} else {
|
|
8097
|
+
vmInsertData.crestImageId = attachmentId;
|
|
8098
|
+
vmInsertData.vmImageUrl = isVmImageExist.toObject().vmImageUrl;
|
|
8099
|
+
}
|
|
8100
|
+
}
|
|
8101
|
+
|
|
8102
|
+
const vmDetails = await planoVmService.upsertOne(
|
|
8103
|
+
{
|
|
8104
|
+
'vmNameName': vmInsertData.vmName,
|
|
8105
|
+
},
|
|
8106
|
+
vmInsertData,
|
|
8107
|
+
);
|
|
8108
|
+
|
|
8109
|
+
return {
|
|
8110
|
+
vmId: vmDetails.toObject()._id,
|
|
8111
|
+
startYPosition: vmTemplate.startYPosition,
|
|
8112
|
+
endYPosition: vmTemplate.endYPosition,
|
|
8113
|
+
xZone: vmTemplate.xZone,
|
|
8114
|
+
};
|
|
8115
|
+
} ) );
|
|
8116
|
+
|
|
8117
|
+
const existingTemplateWithMaxIndex = await fixtureConfigService.sortAndFindOne(
|
|
8118
|
+
{ fixtureCategory: fixtureConfigDoc.fixtureCategory,
|
|
8119
|
+
fixtureWidth: fixtureConfigDoc.fixtureWidth }, {}, { templateIndex: -1 } );
|
|
8120
|
+
|
|
8121
|
+
let templateIndex = 1;
|
|
8122
|
+
|
|
8123
|
+
if ( existingTemplateWithMaxIndex.length ) {
|
|
8124
|
+
templateIndex = existingTemplateWithMaxIndex[0].toObject().templateIndex + 1;
|
|
8125
|
+
}
|
|
8126
|
+
|
|
8127
|
+
let templateName = `Template-${templateIndex}-${fixtureConfigDoc.fixtureCategory}`;
|
|
8128
|
+
|
|
8129
|
+
const isTemplateExist = await fixtureConfigService.findOne( { crestMapKey: mapKey } );
|
|
8130
|
+
if ( isTemplateExist ) {
|
|
8131
|
+
templateIndex = undefined;
|
|
8132
|
+
templateName = undefined;
|
|
8133
|
+
}
|
|
8134
|
+
|
|
8135
|
+
const fixtureTemplateData = {
|
|
8136
|
+
...fixtureConfigDoc,
|
|
8137
|
+
'shelfConfig': shelfTemplate,
|
|
8138
|
+
'vmConfig': vmTemplate,
|
|
8139
|
+
'clientId': fixtureConfigDoc.clientId,
|
|
8140
|
+
'fixtureName': templateName,
|
|
8141
|
+
'templateIndex': templateIndex,
|
|
8142
|
+
'header': {
|
|
8143
|
+
label: fixture.header ? fixture.header : fixture.fixtureSubname[0],
|
|
8144
|
+
isEnabled: true,
|
|
8145
|
+
},
|
|
8146
|
+
'footer': {
|
|
8147
|
+
label: fixture.footer,
|
|
8148
|
+
isEnabled: true,
|
|
8149
|
+
},
|
|
8150
|
+
'isBodyEnabled': true,
|
|
8151
|
+
'productResolutionLevel': 'L3',
|
|
8152
|
+
'productBrandName': [ ...fixtureProductSubBrandName ],
|
|
8153
|
+
'fixtureLibraryId': fixtureConfigDoc._id,
|
|
8154
|
+
'crestMapKey': mapKey,
|
|
8155
|
+
};
|
|
8156
|
+
|
|
8157
|
+
delete fixtureTemplateData._id;
|
|
8158
|
+
|
|
8159
|
+
|
|
8160
|
+
const fixtureTemplate = await fixtureConfigService.upsertOne(
|
|
8161
|
+
{ crestMapKey: mapKey },
|
|
8162
|
+
fixtureTemplateData,
|
|
8163
|
+
);
|
|
8164
|
+
|
|
8165
|
+
const fixtureData = {
|
|
8166
|
+
...fixtureTemplate.toObject(),
|
|
8167
|
+
'storeName': layoutDoc.storeName,
|
|
8168
|
+
'storeId': storeDetails?.toObject()?.storeId ? storeDetails.toObject().storeId : 'nil',
|
|
8169
|
+
'planoId': layoutDoc.planoId,
|
|
8170
|
+
'floorId': layoutDoc._id,
|
|
8171
|
+
'associatedElementType': 'wall',
|
|
8172
|
+
'associatedElementNumber': 3,
|
|
8173
|
+
'relativePosition': {
|
|
8174
|
+
'x': roundToTwo( ( index * ( constantDetailedFixtureLength / mmToFeet ) ) ),
|
|
8175
|
+
'y': roundToTwo( ( finalYDetailedDistance - ( constantDetailedFixtureWidth / mmToFeet ) ) ),
|
|
8176
|
+
'unit': 'ft',
|
|
8177
|
+
},
|
|
8178
|
+
'fixtureNumber': fixtureCounter,
|
|
8179
|
+
// 'relativeDetailedPosition': {
|
|
8180
|
+
// 'x': roundToTwo( ( index * ( constantDetailedFixtureLength / mmToFeet ) ) ),
|
|
8181
|
+
// 'y': roundToTwo( ( finalYDetailedDistance - ( constantDetailedFixtureWidth / mmToFeet ) ) ),
|
|
8182
|
+
// 'unit': 'ft',
|
|
8183
|
+
// },
|
|
8184
|
+
'associatedElementFixtureNumber': index+1,
|
|
8185
|
+
'fixtureConfigId': fixtureTemplate.toObject()._id,
|
|
8186
|
+
};
|
|
8187
|
+
|
|
8188
|
+
delete fixtureData._id;
|
|
8189
|
+
delete fixtureData.shelfConfig;
|
|
8190
|
+
|
|
8191
|
+
const createdFixture = await storeFixtureService.upsertOne(
|
|
8192
|
+
{
|
|
8193
|
+
floorId: layoutDoc._id,
|
|
8194
|
+
fixtureNumber: fixtureCounter++,
|
|
8195
|
+
},
|
|
8196
|
+
fixtureData,
|
|
8197
|
+
);
|
|
8198
|
+
|
|
8199
|
+
if ( !fixtureConfigDoc.shelfConfig.length || fixture.header === 'CL' || fixture.fixtureSubname?.includes( 'CL' ) ) continue;
|
|
8200
|
+
|
|
8201
|
+
fixtureTemplate.shelfConfig.forEach( async ( configShelf, j ) => {
|
|
8202
|
+
const shelfData = {
|
|
8203
|
+
'clientId': '11',
|
|
8204
|
+
'storeName': layoutDoc.storeName,
|
|
8205
|
+
'storeId': storeDetails?.toObject()?.storeId ? storeDetails.toObject().storeId : 'nil',
|
|
8206
|
+
'planoId': layoutDoc.planoId,
|
|
8207
|
+
'floorId': layoutDoc._id,
|
|
8208
|
+
'fixtureId': createdFixture._id,
|
|
8209
|
+
'shelfNumber': j + 1,
|
|
8210
|
+
'shelfOrder': 'LTR',
|
|
8211
|
+
'shelfCapacity': configShelf.shelfCapacity,
|
|
8212
|
+
'productBrandName': configShelf.productBrandName,
|
|
8213
|
+
'shelfType': configShelf.shelfType,
|
|
8214
|
+
'productPerShelf': configShelf.productPerShelf,
|
|
8215
|
+
'trayRows': configShelf.trayRows,
|
|
8216
|
+
'productPerTray': configShelf.productPerTray,
|
|
8217
|
+
'zone': configShelf.zone,
|
|
8218
|
+
};
|
|
8219
|
+
|
|
8220
|
+
await fixtureShelfService.upsertOne(
|
|
8221
|
+
{
|
|
8222
|
+
fixtureId: createdFixture._id,
|
|
8223
|
+
shelfNumber: j + 1,
|
|
8224
|
+
},
|
|
8225
|
+
shelfData,
|
|
8226
|
+
);
|
|
8227
|
+
} );
|
|
8228
|
+
}
|
|
8229
|
+
|
|
8230
|
+
for ( let index = 0; index < floorFixtures.length; index++ ) {
|
|
8231
|
+
const fixture = floorFixtures[index];
|
|
8232
|
+
|
|
8233
|
+
const centerRow = Math.floor( totalRows / 2 );
|
|
8234
|
+
|
|
8235
|
+
// const startingX = roundToTwo( ( finalXDistance / 2 - ( maxFixturesPerRow / 2 ) * ( constantFixtureLength / mmToFeet ) ) );
|
|
8236
|
+
const detailedStartingX = roundToTwo( ( finalXDetailedDistance / 2 - ( maxFixturesPerRow / 2 ) * ( constantDetailedFixtureLength / mmToFeet ) ) );
|
|
8237
|
+
|
|
8238
|
+
// const startingY = finalYDistance / 2 - centerRow * ( constantFixtureWidth / mmToFeet );
|
|
8239
|
+
const detailedStartingY = finalYDetailedDistance / 2 - centerRow * ( constantDetailedFixtureWidth / mmToFeet );
|
|
8240
|
+
|
|
8241
|
+
const colIndex = Math.floor( index / 2 );
|
|
8242
|
+
const rowIndex = index % 2 === 0 ? 1 : 0;
|
|
8243
|
+
|
|
8244
|
+
// const xPos = roundToTwo( startingX + colIndex * ( constantFixtureLength / mmToFeet ) );
|
|
8245
|
+
// const yPos = roundToTwo( startingY + rowIndex * ( constantFixtureWidth / mmToFeet ) );
|
|
8246
|
+
|
|
8247
|
+
const detailedXPos = roundToTwo( ( detailedStartingX + colIndex * ( constantDetailedFixtureLength / mmToFeet ) ) );
|
|
8248
|
+
const detailedYPos = roundToTwo( ( detailedStartingY + rowIndex * ( constantDetailedFixtureWidth / mmToFeet ) ) );
|
|
8249
|
+
|
|
8250
|
+
const fixtureConfig = await fixtureLibraryService.findOne( { fixtureCategory: fixture.main } );
|
|
8251
|
+
if ( !fixtureConfig ) continue;
|
|
8252
|
+
const fixtureConfigDoc = fixtureConfig.toObject();
|
|
8253
|
+
|
|
8254
|
+
let mapKey = `${fixtureConfigDoc.fixtureCategory}${fixtureConfigDoc.fixtureWidth.value}${fixtureConfigDoc.fixtureWidth.unit},${fixture.centerSubMain}`;
|
|
8255
|
+
|
|
8256
|
+
const fixtureProductSubBrandName = new Set();
|
|
8257
|
+
|
|
8258
|
+
|
|
8259
|
+
const shelfTemplate = fixtureConfigDoc.shelfConfig.map( ( configShelf, j ) => {
|
|
8260
|
+
const shelfSection = fixture?.centerSuperSubMain?.find( ( product ) => !product.isVisualMerchandiser );
|
|
8261
|
+
|
|
8262
|
+
const shelfIdentifier = `shelf${j + 1}=${fixture.centerSubMain}`;
|
|
8263
|
+
|
|
8264
|
+
mapKey += ','+shelfIdentifier;
|
|
8265
|
+
|
|
8266
|
+
|
|
8267
|
+
let productSubBrandName = fixture.centerSubMain.replace( /\s*PIDs\b/g, '' )?.split( /\s*\+\s*/ ) || [];
|
|
8268
|
+
|
|
8269
|
+
if ( shelfSection ) {
|
|
8270
|
+
productSubBrandName = shelfSection.name.replace( /\s*PIDs\b/g, '' )?.split( /\s*\+\s*/ ) || [];
|
|
8271
|
+
}
|
|
8272
|
+
|
|
8273
|
+
productSubBrandName.forEach( ( item ) => fixtureProductSubBrandName.add( item ) );
|
|
8274
|
+
|
|
8275
|
+
return {
|
|
8276
|
+
shelfNumber: j+1,
|
|
8277
|
+
shelfType: configShelf?.shelfType,
|
|
8278
|
+
productPerShelf: configShelf?.productPerShelf,
|
|
8279
|
+
trayRows: configShelf?.trayRows,
|
|
8280
|
+
productBrandName: productSubBrandName,
|
|
8281
|
+
zone: configShelf.shelfZone,
|
|
8282
|
+
};
|
|
8283
|
+
} );
|
|
8284
|
+
|
|
8285
|
+
const vmConfig = fixture.centerSuperSubMain?.flatMap( ( vm, k ) => {
|
|
8286
|
+
if ( !vm?.isVisualMerchandiser ) {
|
|
8287
|
+
return [];
|
|
8288
|
+
}
|
|
8289
|
+
const vmConfig = fixtureConfigDoc.vmConfig;
|
|
8290
|
+
|
|
8291
|
+
const [ configData1, configData2 ] = [ vmConfig[0], vmConfig[1] ];
|
|
8292
|
+
|
|
8293
|
+
const vmIdentifier = `vm${k+1}=${vm.name}+${configData1.vmHeightmm}+${configData1.vmWidthmm}+${configData1.startShelf}+${configData1.endShelf}+${configData1.zone}`;
|
|
8294
|
+
|
|
8295
|
+
mapKey += ','+vmIdentifier;
|
|
8296
|
+
|
|
8297
|
+
return [
|
|
8298
|
+
{
|
|
8299
|
+
startYPosition: configData1.startShelf,
|
|
8300
|
+
endYPosition: configData1.endShelf,
|
|
8301
|
+
xZone: 'left',
|
|
8302
|
+
vmName: vm.name + ' - 1',
|
|
8303
|
+
vmHeight: configData1.vmHeightmm,
|
|
8304
|
+
vmWidth: configData1.vmWidthmm,
|
|
8305
|
+
},
|
|
8306
|
+
{
|
|
8307
|
+
startYPosition: configData2.startShelf,
|
|
8308
|
+
endYPosition: configData2.endShelf,
|
|
8309
|
+
xZone: 'stretch',
|
|
8310
|
+
vmName: vm.name + ' - 2',
|
|
8311
|
+
vmHeight: configData2.vmHeightmm,
|
|
8312
|
+
vmWidth: configData2.vmWidthmm,
|
|
8313
|
+
},
|
|
8314
|
+
];
|
|
8315
|
+
} );
|
|
8316
|
+
|
|
8317
|
+
const vmTemplate = await Promise.all( vmConfig.map( async ( vmTemplate ) => {
|
|
8318
|
+
const vmInsertData = {
|
|
8319
|
+
clientId: '11',
|
|
8320
|
+
vmName: vmTemplate.vmName,
|
|
8321
|
+
vmHeight: {
|
|
8322
|
+
value: vmTemplate.vmHeight,
|
|
8323
|
+
unit: 'mm',
|
|
8324
|
+
},
|
|
8325
|
+
vmWidth: {
|
|
8326
|
+
value: vmTemplate.vmWidth,
|
|
8327
|
+
unit: 'mm',
|
|
8328
|
+
},
|
|
8329
|
+
status: 'complete',
|
|
8330
|
+
vmBrand: vmTemplate.vmBrand,
|
|
8331
|
+
};
|
|
8332
|
+
|
|
8333
|
+
const vmDetails = await planoVmService.upsertOne(
|
|
8334
|
+
{
|
|
8335
|
+
'vmName': vmInsertData.vmName,
|
|
8336
|
+
},
|
|
8337
|
+
vmInsertData,
|
|
8338
|
+
);
|
|
8339
|
+
|
|
8340
|
+
return {
|
|
8341
|
+
vmId: vmDetails.toObject()._id,
|
|
8342
|
+
startYPosition: vmTemplate.startYPosition,
|
|
8343
|
+
endYPosition: vmTemplate.endYPosition,
|
|
8344
|
+
xZone: vmTemplate.xZone,
|
|
8345
|
+
};
|
|
8346
|
+
} ) );
|
|
8347
|
+
|
|
8348
|
+
const existingTemplateWithMaxIndex = await fixtureConfigService.sortAndFindOne(
|
|
8349
|
+
{ fixtureCategory: fixtureConfigDoc.fixtureCategory,
|
|
8350
|
+
fixtureWidth: fixtureConfigDoc.fixtureWidth }, {}, { templateIndex: -1 } );
|
|
8351
|
+
|
|
8352
|
+
let templateIndex = 1;
|
|
8353
|
+
|
|
8354
|
+
if ( existingTemplateWithMaxIndex.length ) {
|
|
8355
|
+
templateIndex = existingTemplateWithMaxIndex[0].toObject().templateIndex + 1;
|
|
8356
|
+
}
|
|
8357
|
+
|
|
8358
|
+
let templateName = `Template-${templateIndex}-${fixtureConfigDoc.fixtureCategory}`;
|
|
8359
|
+
|
|
8360
|
+
const isTemplateExist = await fixtureConfigService.findOne( { crestMapKey: mapKey } );
|
|
8361
|
+
if ( isTemplateExist ) {
|
|
8362
|
+
templateIndex = undefined;
|
|
8363
|
+
templateName = undefined;
|
|
8364
|
+
}
|
|
8365
|
+
|
|
8366
|
+
const fixtureTemplateData = {
|
|
8367
|
+
...fixtureConfigDoc,
|
|
8368
|
+
'shelfConfig': shelfTemplate,
|
|
8369
|
+
'vmConfig': vmTemplate,
|
|
8370
|
+
'clientId': fixtureConfigDoc.clientId,
|
|
8371
|
+
'fixtureName': templateName,
|
|
8372
|
+
'templateIndex': templateIndex,
|
|
8373
|
+
'header': {
|
|
8374
|
+
label: fixture.centerSubMain,
|
|
8375
|
+
isEnabled: true,
|
|
8376
|
+
},
|
|
8377
|
+
'footer': {
|
|
8378
|
+
label: 'Storage Box',
|
|
8379
|
+
isEnabled: true,
|
|
8380
|
+
},
|
|
8381
|
+
'isBodyEnabled': true,
|
|
8382
|
+
'productResolutionLevel': 'L3',
|
|
8383
|
+
'productBrandName': [ ...fixtureProductSubBrandName ],
|
|
8384
|
+
'fixtureLibraryId': fixtureConfigDoc._id,
|
|
8385
|
+
'crestMapKey': mapKey,
|
|
8386
|
+
};
|
|
8387
|
+
|
|
8388
|
+
|
|
8389
|
+
delete fixtureTemplateData._id;
|
|
8390
|
+
|
|
8391
|
+
|
|
8392
|
+
const fixtureTemplate = await fixtureConfigService.upsertOne(
|
|
8393
|
+
{ crestMapKey: mapKey },
|
|
8394
|
+
fixtureTemplateData,
|
|
8395
|
+
);
|
|
8396
|
+
|
|
8397
|
+
const fixtureData = {
|
|
8398
|
+
...fixtureTemplate.toObject(),
|
|
8399
|
+
'storeName': layoutDoc.storeName,
|
|
8400
|
+
'storeId': storeDetails?.toObject()?.storeId ? storeDetails.toObject().storeId : 'nil',
|
|
8401
|
+
'planoId': layoutDoc.planoId,
|
|
8402
|
+
'floorId': layoutDoc._id,
|
|
8403
|
+
'relativePosition': {
|
|
8404
|
+
'x': detailedXPos,
|
|
8405
|
+
'y': detailedYPos,
|
|
8406
|
+
'unit': 'ft',
|
|
8407
|
+
},
|
|
8408
|
+
'fixtureNumber': fixtureCounter,
|
|
8409
|
+
// 'relativeDetailedPosition': {
|
|
8410
|
+
// 'x': detailedXPos,
|
|
8411
|
+
// 'y': detailedYPos,
|
|
8412
|
+
// 'unit': 'ft',
|
|
8413
|
+
// },
|
|
8414
|
+
'associatedElementFixtureNumber': index+1,
|
|
8415
|
+
'fixtureConfigId': fixtureTemplate.toObject()._id,
|
|
8416
|
+
};
|
|
8417
|
+
|
|
8418
|
+
delete fixtureData._id;
|
|
8419
|
+
delete fixtureData.shelfConfig;
|
|
8420
|
+
|
|
8421
|
+
const createdFixture = await storeFixtureService.upsertOne(
|
|
8422
|
+
{
|
|
8423
|
+
floorId: layoutDoc._id,
|
|
8424
|
+
fixtureNumber: fixtureCounter++,
|
|
8425
|
+
},
|
|
8426
|
+
fixtureData,
|
|
8427
|
+
);
|
|
8428
|
+
|
|
8429
|
+
if ( !fixtureConfigDoc.shelfConfig.length || fixture.header === 'CL' || fixture.fixtureSubname?.includes( 'CL' ) ) continue;
|
|
8430
|
+
|
|
8431
|
+
fixtureTemplate.shelfConfig.forEach( async ( configShelf, j ) => {
|
|
8432
|
+
const shelfData = {
|
|
8433
|
+
'clientId': '11',
|
|
8434
|
+
'storeName': layoutDoc.storeName,
|
|
8435
|
+
'storeId': storeDetails?.toObject()?.storeId ? storeDetails.toObject().storeId : 'nil',
|
|
8436
|
+
'planoId': layoutDoc.planoId,
|
|
8437
|
+
'floorId': layoutDoc._id,
|
|
8438
|
+
'fixtureId': createdFixture._id,
|
|
8439
|
+
'shelfNumber': j + 1,
|
|
8440
|
+
'shelfOrder': 'LTR',
|
|
8441
|
+
'shelfCapacity': configShelf.shelfCapacity,
|
|
8442
|
+
'productBrandName': configShelf.productBrandName,
|
|
8443
|
+
'shelfType': configShelf.shelfType,
|
|
8444
|
+
'productPerShelf': configShelf.productPerShelf,
|
|
8445
|
+
'trayRows': configShelf.trayRows,
|
|
8446
|
+
'productPerTray': configShelf.productPerTray,
|
|
8447
|
+
'zone': configShelf.zone,
|
|
8448
|
+
};
|
|
8449
|
+
|
|
8450
|
+
await fixtureShelfService.upsertOne(
|
|
8451
|
+
{
|
|
8452
|
+
fixtureId: createdFixture._id,
|
|
8453
|
+
shelfNumber: j + 1,
|
|
8454
|
+
},
|
|
8455
|
+
shelfData,
|
|
8456
|
+
);
|
|
8457
|
+
} );
|
|
8458
|
+
}
|
|
8459
|
+
|
|
8460
|
+
|
|
8461
|
+
const now = Date.now();
|
|
8462
|
+
const elapsedMinutes = ( now - startTime ) / 1000 / 60;
|
|
8463
|
+
console.log( `Store name: ${storeData.storeName},Floor name: ${floorArray[floorIndex]} Iteration ${i + 1}/${storeList?.length}: total elapsed time = ${elapsedMinutes.toFixed( 2 )} minutes` );
|
|
8464
|
+
logger.info( { functionName: 'updateCrestPlanogram', body: `Store name: ${storeData.storeName},Floor name: ${floorArray[floorIndex]} Iteration ${i + 1}/${storeList?.length}: total elapsed time = ${elapsedMinutes.toFixed( 2 )} minutes` } );
|
|
8465
|
+
}
|
|
8466
|
+
}
|
|
8467
|
+
|
|
8468
|
+
res.sendSuccess( 'Updated Successfully' );
|
|
8469
|
+
} catch ( e ) {
|
|
8470
|
+
logger.error( { functionName: 'updateCrestPlanogram', error: e } );
|
|
8471
|
+
return res.sendError( e.message || 'Internal Server Error', 500 );
|
|
8472
|
+
}
|
|
8473
|
+
}
|
|
8474
|
+
// function fillFeedbackFromJson( excelPath, jsonData, outputPath ) {
|
|
8475
|
+
// const workbook = xlsx.readFile( excelPath );
|
|
8476
|
+
// const sheetName = workbook.SheetNames[0];
|
|
8477
|
+
// const sheet = workbook.Sheets[sheetName];
|
|
8478
|
+
|
|
8479
|
+
// const data = xlsx.utils.sheet_to_json( sheet, { defval: 'Transformed by Data.Page' } );
|
|
8480
|
+
|
|
8481
|
+
// const feedbackMap = {};
|
|
8482
|
+
// jsonData.forEach( ( entry ) => {
|
|
8483
|
+
// feedbackMap[entry.store] = entry.videoUrl;
|
|
8484
|
+
// } );
|
|
8485
|
+
|
|
8486
|
+
// const updatedData = data.map( ( row ) => {
|
|
8487
|
+
// const store = row.storeName;
|
|
8488
|
+
// if ( feedbackMap[store] ) {
|
|
8489
|
+
// row.FeedBack = feedbackMap[store];
|
|
8490
|
+
// }
|
|
8491
|
+
// return row;
|
|
8492
|
+
// } );
|
|
8493
|
+
|
|
8494
|
+
// const newSheet = xlsx.utils.json_to_sheet( updatedData );
|
|
8495
|
+
|
|
8496
|
+
// workbook.Sheets[sheetName] = newSheet;
|
|
8497
|
+
|
|
8498
|
+
// xlsx.writeFile( workbook, outputPath );
|
|
8499
|
+
// }
|
|
8500
|
+
|
|
8501
|
+
// fillFeedbackFromJson('input.xlsx', feedbackJson, 'output.xlsx');
|
|
8502
|
+
|
|
8503
|
+
|
|
8504
|
+
// function exportFixtureJsonToExcel( fixtures, filePath ) {
|
|
8505
|
+
// const fixtureInfoArr = [];
|
|
8506
|
+
// const shelfConfigArr = [];
|
|
8507
|
+
// const vmConfigArr = [];
|
|
8508
|
+
|
|
8509
|
+
// for ( const fixture of fixtures ) {
|
|
8510
|
+
// fixtureInfoArr.push( {
|
|
8511
|
+
// clientId: fixture.clientId,
|
|
8512
|
+
// fixtureCode: fixture.fixtureCode,
|
|
8513
|
+
// fixtureCategory: fixture.fixtureCategory,
|
|
8514
|
+
// fixtureConfigType: fixture.fixtureConfigType,
|
|
8515
|
+
// fixtureLength: `${fixture.fixtureLength?.value} ${fixture.fixtureLength?.unit}`,
|
|
8516
|
+
// fixtureCapacity: fixture.fixtureCapacity,
|
|
8517
|
+
// } );
|
|
8518
|
+
|
|
8519
|
+
// ( fixture.shelfConfig || [] ).forEach( ( shelf ) => {
|
|
8520
|
+
// shelfConfigArr.push( {
|
|
8521
|
+
// fixtureCode: fixture.fixtureCode,
|
|
8522
|
+
// ...shelf,
|
|
8523
|
+
// } );
|
|
8524
|
+
// } );
|
|
8525
|
+
|
|
8526
|
+
// ( fixture.vmConfig || [] ).forEach( ( vm ) => {
|
|
8527
|
+
// vmConfigArr.push( {
|
|
8528
|
+
// fixtureCode: fixture.fixtureCode,
|
|
8529
|
+
// ...vm,
|
|
8530
|
+
// } );
|
|
8531
|
+
// } );
|
|
8532
|
+
// }
|
|
8533
|
+
|
|
8534
|
+
// const workbook = xlsx.utils.book_new();
|
|
8535
|
+
// xlsx.utils.book_append_sheet( workbook, xlsx.utils.json_to_sheet( fixtureInfoArr ), 'Fixture Info' );
|
|
8536
|
+
// xlsx.utils.book_append_sheet( workbook, xlsx.utils.json_to_sheet( shelfConfigArr ), 'Shelf Config' );
|
|
8537
|
+
// xlsx.utils.book_append_sheet( workbook, xlsx.utils.json_to_sheet( vmConfigArr ), 'VM Config' );
|
|
8538
|
+
|
|
8539
|
+
// xlsx.writeFile( workbook, filePath );
|
|
8540
|
+
// }
|
|
7153
8541
|
|
|
7154
8542
|
// const fixtures = JSON.parse( fs.readFileSync( './input.json', 'utf-8' ) );
|
|
7155
8543
|
// exportFixtureJsonToExcel( fixtures, 'output.xlsx' );
|