tango-app-api-store-builder 1.0.0-beta-134 → 1.0.0-beta-135
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/controllers/fixtureTemplate.controller.js +45 -4
- package/src/controllers/managePlano.controller.js +16 -2
- package/src/controllers/planoLibrary.controller.js +142 -99
- package/src/controllers/script.controller.js +149 -46
- package/src/controllers/storeBuilder.controller.js +385 -27
- package/src/controllers/task.controller.js +5 -2
- package/src/routes/script.routes.js +1 -0
- package/src/routes/storeBuilder.routes.js +5 -4
- package/src/service/fixtureShelf.service.js +4 -0
- package/src/service/planoTask.service.js +3 -0
|
@@ -2323,62 +2323,62 @@ export async function updateVmData( req, res ) {
|
|
|
2323
2323
|
|
|
2324
2324
|
// import https from 'https';
|
|
2325
2325
|
// async function scrapeCrest() {
|
|
2326
|
-
// const storeIds = [ '
|
|
2326
|
+
// const storeIds = [ 'LKST682' ];
|
|
2327
2327
|
// const apiUrl = 'https://api.getcrest.ai/api/ms_shelfsensei/layout/';
|
|
2328
|
-
// const bearerToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
|
|
2328
|
+
// const bearerToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzUwODQwMzE1LCJpYXQiOjE3NTA4MzY3MTUsImp0aSI6IjFlOTM1ZmUwMTkwNzQzMDM5ZmJjYmZlOWVkOWM5Y2IwIiwidXNlcl9pZCI6MTA4NSwiaWQiOjEwODUsImlzX21lZXNlZWtfYWNjb3VudCI6ZmFsc2UsImN1c3RvbWVyX2dyb3VwIjozOTgsImxpY2VuY2Vfc2NvcGVzIjpbeyJyZXNvdXJjZV9zZXQiOiJwcF9zZXQiLCJzY29wZV9yb2xlIjoiY29udHJpYnV0b3IifSx7InJlc291cmNlX3NldCI6ImRwX3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9LHsicmVzb3VyY2Vfc2V0IjoiZGZfc2V0Iiwic2NvcGVfcm9sZSI6ImNvbnRyaWJ1dG9yIn0seyJyZXNvdXJjZV9zZXQiOiJkZWZhdWx0X3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9XX0.zxWZKlUPec5vEwKsWx0DvZ2ckJRkZBzvbH41uid6YJQ';
|
|
2329
2329
|
// const filePath = 'response.json';
|
|
2330
2330
|
// let allResults = [];
|
|
2331
2331
|
|
|
2332
|
-
//
|
|
2333
|
-
//
|
|
2334
|
-
//
|
|
2335
|
-
//
|
|
2336
|
-
//
|
|
2337
|
-
// allResults = [];
|
|
2338
|
-
// }
|
|
2339
|
-
// } catch ( error ) {
|
|
2340
|
-
// console.error( 'Error reading existing JSON file:', error.message );
|
|
2332
|
+
// if ( fs.existsSync( filePath ) ) {
|
|
2333
|
+
// try {
|
|
2334
|
+
// const existingData = fs.readFileSync( filePath, 'utf8' );
|
|
2335
|
+
// allResults = JSON.parse( existingData );
|
|
2336
|
+
// if ( !Array.isArray( allResults ) ) {
|
|
2341
2337
|
// allResults = [];
|
|
2342
2338
|
// }
|
|
2339
|
+
// } catch ( error ) {
|
|
2340
|
+
// console.error( 'Error reading existing JSON file:', error.message );
|
|
2341
|
+
// allResults = [];
|
|
2343
2342
|
// }
|
|
2343
|
+
// }
|
|
2344
2344
|
|
|
2345
|
-
//
|
|
2346
|
-
//
|
|
2347
|
-
//
|
|
2348
|
-
//
|
|
2349
|
-
//
|
|
2350
|
-
//
|
|
2351
|
-
//
|
|
2352
|
-
//
|
|
2353
|
-
//
|
|
2354
|
-
//
|
|
2355
|
-
//
|
|
2356
|
-
//
|
|
2357
|
-
|
|
2358
|
-
//
|
|
2359
|
-
//
|
|
2360
|
-
//
|
|
2361
|
-
//
|
|
2362
|
-
// } );
|
|
2363
|
-
// res.on( 'end', () => {
|
|
2364
|
-
// try {
|
|
2365
|
-
// const jsonData = JSON.parse( data );
|
|
2366
|
-
// const result = { storeName: storeId, data: jsonData };
|
|
2367
|
-
// allResults.push( result );
|
|
2368
|
-
// fs.writeFileSync( filePath, JSON.stringify( allResults, null, 2 ) );
|
|
2369
|
-
// console.log( 'Received Data:', result );
|
|
2370
|
-
// resolve( result );
|
|
2371
|
-
// } catch ( error ) {
|
|
2372
|
-
// console.error( `Error parsing JSON for ${storeId}:`, error.message );
|
|
2373
|
-
// resolve( { storeName: storeId, data: null } );
|
|
2374
|
-
// }
|
|
2375
|
-
// } );
|
|
2345
|
+
// for ( const storeId of storeIds ) {
|
|
2346
|
+
// try {
|
|
2347
|
+
// const result = await new Promise( ( resolve ) => {
|
|
2348
|
+
// const payload = JSON.stringify( { store_id: storeId } );
|
|
2349
|
+
// const options = {
|
|
2350
|
+
// method: 'POST',
|
|
2351
|
+
// headers: {
|
|
2352
|
+
// 'Authorization': `Bearer ${bearerToken}`,
|
|
2353
|
+
// 'Content-Type': 'application/json',
|
|
2354
|
+
// 'Content-Length': Buffer.byteLength( payload ),
|
|
2355
|
+
// },
|
|
2356
|
+
// };
|
|
2357
|
+
|
|
2358
|
+
// const req = https.request( apiUrl, options, ( res ) => {
|
|
2359
|
+
// let data = '';
|
|
2360
|
+
// res.on( 'data', ( chunk ) => {
|
|
2361
|
+
// data += chunk;
|
|
2376
2362
|
// } );
|
|
2377
|
-
|
|
2378
|
-
//
|
|
2379
|
-
//
|
|
2380
|
-
//
|
|
2363
|
+
// res.on( 'end', () => {
|
|
2364
|
+
// try {
|
|
2365
|
+
// const jsonData = JSON.parse( data );
|
|
2366
|
+
// const result = { storeName: storeId, data: jsonData };
|
|
2367
|
+
// allResults.push( result );
|
|
2368
|
+
// fs.writeFileSync( filePath, JSON.stringify( allResults, null, 2 ) );
|
|
2369
|
+
// console.log( 'Received Data:', result );
|
|
2370
|
+
// resolve( result );
|
|
2371
|
+
// } catch ( error ) {
|
|
2372
|
+
// console.error( `Error parsing JSON for ${storeId}:`, error.message );
|
|
2373
|
+
// resolve( { storeName: storeId, data: null } );
|
|
2374
|
+
// }
|
|
2381
2375
|
// } );
|
|
2376
|
+
// } );
|
|
2377
|
+
|
|
2378
|
+
// req.on( 'error', ( error ) => {
|
|
2379
|
+
// console.error( `Error fetching data for ${storeId}:`, error.message );
|
|
2380
|
+
// resolve( { storeName: storeId, data: null } );
|
|
2381
|
+
// } );
|
|
2382
2382
|
|
|
2383
2383
|
// req.write( payload );
|
|
2384
2384
|
// req.end();
|
|
@@ -8879,3 +8879,106 @@ export async function migrateCrestv1( req, res ) {
|
|
|
8879
8879
|
// } catch (err) {
|
|
8880
8880
|
// console.error('Error processing file:', err);
|
|
8881
8881
|
// }
|
|
8882
|
+
|
|
8883
|
+
|
|
8884
|
+
export async function updatePlanoMappings( req, res ) {
|
|
8885
|
+
if ( req?.headers?.authorization?.split( ' ' )[1] !== 'hwjXfCD6TgMvc82cuSGZ9bNv9MuXsaiQ6uvx' ) {
|
|
8886
|
+
return res.sendError( 'Unauthorized', 401 );
|
|
8887
|
+
}
|
|
8888
|
+
try {
|
|
8889
|
+
console.log( JSON.stringify( req.body ) );
|
|
8890
|
+
const floor = await storeBuilderService.findOne( { storeName: req.body.storeName } );
|
|
8891
|
+
|
|
8892
|
+
for ( let i = 0; i < req.body?.walls?.length; i++ ) {
|
|
8893
|
+
const wall = req.body.walls[i];
|
|
8894
|
+
|
|
8895
|
+
let associatedElementNumber = undefined;
|
|
8896
|
+
let associatedElementType = undefined;
|
|
8897
|
+
|
|
8898
|
+
if ( wall.wallName === 'LEFT' ) {
|
|
8899
|
+
associatedElementNumber = 1;
|
|
8900
|
+
associatedElementType = 'wall';
|
|
8901
|
+
}
|
|
8902
|
+
|
|
8903
|
+
if ( wall.wallName === 'BACK' ) {
|
|
8904
|
+
associatedElementNumber = 2;
|
|
8905
|
+
associatedElementType = 'wall';
|
|
8906
|
+
}
|
|
8907
|
+
|
|
8908
|
+
if ( wall.wallName === 'RIGHT' ) {
|
|
8909
|
+
associatedElementNumber = 3;
|
|
8910
|
+
associatedElementType = 'wall';
|
|
8911
|
+
}
|
|
8912
|
+
|
|
8913
|
+
for ( let j = 0; j < wall?.fixtures?.length; j++ ) {
|
|
8914
|
+
const fixture = wall.fixtures[j];
|
|
8915
|
+
|
|
8916
|
+
const associatedElementFixtureNumber = fixture.fixtureNumber;
|
|
8917
|
+
|
|
8918
|
+
let storeFixture = null;
|
|
8919
|
+
|
|
8920
|
+
if ( wall.wallName === 'CENTRE' ) {
|
|
8921
|
+
storeFixture = await storeFixtureService.findOne( { floorId: floor.toObject()._id, $and: [
|
|
8922
|
+
{ associatedElementType: { $exists: false } },
|
|
8923
|
+
{ associatedElementNumber: { $exists: false } },
|
|
8924
|
+
], associatedElementFixtureNumber: associatedElementFixtureNumber } );
|
|
8925
|
+
} else {
|
|
8926
|
+
storeFixture = await storeFixtureService.findOne( { floorId: floor.toObject()._id,
|
|
8927
|
+
associatedElementType: associatedElementType,
|
|
8928
|
+
associatedElementNumber: associatedElementNumber,
|
|
8929
|
+
associatedElementFixtureNumber: associatedElementFixtureNumber,
|
|
8930
|
+
} );
|
|
8931
|
+
}
|
|
8932
|
+
|
|
8933
|
+
if ( !storeFixture ) continue;
|
|
8934
|
+
|
|
8935
|
+
await planoMappingService.deleteMany( { fixtureId: storeFixture.toObject()._id } );
|
|
8936
|
+
|
|
8937
|
+
|
|
8938
|
+
for ( let k = 0; k < fixture?.sections?.length; k++ ) {
|
|
8939
|
+
const section = fixture.sections[k];
|
|
8940
|
+
|
|
8941
|
+
const shelves = await fixtureShelfService.find( {
|
|
8942
|
+
floorId: floor.toObject()._id,
|
|
8943
|
+
fixtureId: storeFixture.toObject()._id,
|
|
8944
|
+
zone: { $regex: `^${section.zone}$`, $options: 'i' },
|
|
8945
|
+
} );
|
|
8946
|
+
|
|
8947
|
+
const totalShelves = shelves.length;
|
|
8948
|
+
|
|
8949
|
+
if ( !totalShelves ) continue;
|
|
8950
|
+
|
|
8951
|
+
const shelvesToUpdate = shelves.map( ( shelf ) => shelf.toObject()._id );
|
|
8952
|
+
|
|
8953
|
+
await fixtureShelfService.updateMany( { _id: { $in: shelvesToUpdate } }, { sectionName: section.sectionName } );
|
|
8954
|
+
|
|
8955
|
+
for ( let l = 0; l < section?.products?.length; l++ ) {
|
|
8956
|
+
const product = section.products[l];
|
|
8957
|
+
|
|
8958
|
+
const shelf = shelves[l % totalShelves];
|
|
8959
|
+
|
|
8960
|
+
const productMapping = {
|
|
8961
|
+
clientId: storeFixture.toObject().clientId,
|
|
8962
|
+
storeName: storeFixture.toObject().storeName,
|
|
8963
|
+
storeId: storeFixture.toObject().storeId,
|
|
8964
|
+
planoId: storeFixture.toObject().planoId,
|
|
8965
|
+
floorId: storeFixture.toObject().floorId,
|
|
8966
|
+
fixtureId: storeFixture.toObject()._id,
|
|
8967
|
+
shelfId: shelf._id,
|
|
8968
|
+
rfId: product.qr,
|
|
8969
|
+
pid: product.pid,
|
|
8970
|
+
type: 'product',
|
|
8971
|
+
};
|
|
8972
|
+
|
|
8973
|
+
await planoMappingService.create( productMapping );
|
|
8974
|
+
}
|
|
8975
|
+
}
|
|
8976
|
+
}
|
|
8977
|
+
}
|
|
8978
|
+
|
|
8979
|
+
res.sendSuccess( 'success' );
|
|
8980
|
+
} catch ( e ) {
|
|
8981
|
+
console.log( e );
|
|
8982
|
+
return res.sendError( e, 500 );
|
|
8983
|
+
}
|
|
8984
|
+
}
|