tango-app-api-store-builder 1.0.35 → 1.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-store-builder",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.37",
|
|
4
4
|
"description": "storeBuilder",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"path": "^0.12.7",
|
|
33
33
|
"selenium-webdriver": "^4.31.0",
|
|
34
34
|
"sharp": "^0.34.1",
|
|
35
|
-
"tango-api-schema": "^2.5.
|
|
35
|
+
"tango-api-schema": "^2.5.23",
|
|
36
36
|
"tango-app-api-middleware": "3.1.48",
|
|
37
37
|
"url": "^0.11.4",
|
|
38
38
|
"winston": "^3.17.0",
|
|
@@ -125,6 +125,7 @@ export async function getplanoFeedback( req, res ) {
|
|
|
125
125
|
let data = {};
|
|
126
126
|
if ( aiDetails?.body?.hits?.hits.length ) {
|
|
127
127
|
data = aiDetails?.body?.hits?.hits?.[0]?._source;
|
|
128
|
+
console.log( data, 'data' );
|
|
128
129
|
delete data.isEmpty;
|
|
129
130
|
delete data.fixtureFound;
|
|
130
131
|
}
|
|
@@ -786,7 +787,6 @@ export async function updateStorePlano( req, res ) {
|
|
|
786
787
|
{ _id: new mongoose.Types.ObjectId( floorId ) },
|
|
787
788
|
{
|
|
788
789
|
layoutPolygon: layoutPolygon,
|
|
789
|
-
cadLayout:false,
|
|
790
790
|
...( req.body?.editMode === true && { isEdited: true } ),
|
|
791
791
|
},
|
|
792
792
|
);
|
|
@@ -1782,6 +1782,7 @@ export async function getAllPlanoRevisions( req, res ) {
|
|
|
1782
1782
|
|
|
1783
1783
|
res.sendSuccess( revisions );
|
|
1784
1784
|
} catch ( e ) {
|
|
1785
|
+
console.log( e );
|
|
1785
1786
|
logger.error( { functionName: 'getAllPlanoRevisions', error: e } );
|
|
1786
1787
|
res.sendError( 'Failed to fetch plano revisions', 500 );
|
|
1787
1788
|
}
|
|
@@ -2369,15 +2370,15 @@ export async function createPlanoFromCAD(req, res) {
|
|
|
2369
2370
|
const file = req.files.file;
|
|
2370
2371
|
const { storeId, floorNumber } = req.body;
|
|
2371
2372
|
|
|
2372
|
-
if (!req?.files?.file) return res.sendError(
|
|
2373
|
+
if (!req?.files?.file) return res.sendError('File is required', 400);
|
|
2373
2374
|
|
|
2374
|
-
if (!storeId || !floorNumber) return res.sendError(
|
|
2375
|
+
if (!storeId || !floorNumber) return res.sendError('storeId and floorNumber are required', 400);
|
|
2375
2376
|
|
|
2376
|
-
if (!file.name.endsWith('.dxf')) return res.sendError(
|
|
2377
|
+
if (!file.name.endsWith('.dxf')) return res.sendError('Only DXF files are allowed', 400);
|
|
2377
2378
|
|
|
2378
2379
|
|
|
2379
2380
|
// if (file.size > 20 * 1024 * 1024) {
|
|
2380
|
-
// return res.sendError(
|
|
2381
|
+
// return res.sendError('File size exceeds 20MB limit', 400);
|
|
2381
2382
|
// }
|
|
2382
2383
|
|
|
2383
2384
|
// File Upload
|
|
@@ -2391,7 +2392,7 @@ export async function createPlanoFromCAD(req, res) {
|
|
|
2391
2392
|
|
|
2392
2393
|
const fileRes = await fileUpload(fileUploadPayload);
|
|
2393
2394
|
|
|
2394
|
-
if (!fileRes?.Key) return res.sendError(
|
|
2395
|
+
if (!fileRes?.Key) return res.sendError('Failed to upload file to storage', 502);
|
|
2395
2396
|
|
|
2396
2397
|
// CAD Extraction
|
|
2397
2398
|
const dataExtractPayload = {
|
|
@@ -2411,7 +2412,7 @@ export async function createPlanoFromCAD(req, res) {
|
|
|
2411
2412
|
if (!cadRes.ok) {
|
|
2412
2413
|
const errorText = await cadRes.text();
|
|
2413
2414
|
logger.error({ cadLambdaError: errorText });
|
|
2414
|
-
return res.sendError(
|
|
2415
|
+
return res.sendError('CAD extraction service failed', 502);
|
|
2415
2416
|
}
|
|
2416
2417
|
|
|
2417
2418
|
const cadData = await cadRes.json();
|
|
@@ -2425,11 +2426,7 @@ export async function createPlanoFromCAD(req, res) {
|
|
|
2425
2426
|
cadData?.status !== 'success' ||
|
|
2426
2427
|
!cadData?.data?.layoutPolygon
|
|
2427
2428
|
) {
|
|
2428
|
-
return res.sendError(
|
|
2429
|
-
{
|
|
2430
|
-
errMsg: 'Invalid CAD layout data',
|
|
2431
|
-
errInfo: { cadData, input: dataExtractPayload }
|
|
2432
|
-
}, 502);
|
|
2429
|
+
return res.sendError('Invalid CAD layout data', 502);
|
|
2433
2430
|
}
|
|
2434
2431
|
|
|
2435
2432
|
const userMeta = {
|
|
@@ -2443,7 +2440,7 @@ export async function createPlanoFromCAD(req, res) {
|
|
|
2443
2440
|
|
|
2444
2441
|
if (!planoData) {
|
|
2445
2442
|
const storeData = await storeService.findOne({ storeId }, { clientId: 1, storeName: 1 });
|
|
2446
|
-
if (!storeData) return res.sendError(
|
|
2443
|
+
if (!storeData) return res.sendError('Unable to find the store to create planogram', 400);
|
|
2447
2444
|
|
|
2448
2445
|
const newPlano = {
|
|
2449
2446
|
clientId: storeData.clientId,
|
|
@@ -2459,7 +2456,7 @@ export async function createPlanoFromCAD(req, res) {
|
|
|
2459
2456
|
};
|
|
2460
2457
|
|
|
2461
2458
|
planoData = await planoService.create(newPlano);
|
|
2462
|
-
if (!planoData) return res.sendError(
|
|
2459
|
+
if (!planoData) return res.sendError('Failed to create new planogram', 400);
|
|
2463
2460
|
}
|
|
2464
2461
|
|
|
2465
2462
|
const floorPayload = {
|
|
@@ -2487,7 +2484,7 @@ export async function createPlanoFromCAD(req, res) {
|
|
|
2487
2484
|
};
|
|
2488
2485
|
|
|
2489
2486
|
floorData = await floorService.create(newFloor);
|
|
2490
|
-
if (!floorData) return res.sendError(
|
|
2487
|
+
if (!floorData) return res.sendError('Failed to create new floor layout', 400);
|
|
2491
2488
|
}
|
|
2492
2489
|
|
|
2493
2490
|
const meta = {
|
|
@@ -2500,17 +2497,13 @@ export async function createPlanoFromCAD(req, res) {
|
|
|
2500
2497
|
|
|
2501
2498
|
// Create Fixtures
|
|
2502
2499
|
const processedFixtures = createStoreFixtures(cadData.data, meta);
|
|
2503
|
-
|
|
2500
|
+
|
|
2504
2501
|
try {
|
|
2505
2502
|
await storeFixtureService.deleteMany({ floorId: meta.floorId });
|
|
2506
2503
|
await fixtureShelfService.deleteMany({ floorId: meta.floorId });
|
|
2507
2504
|
for (let i = 0; i < processedFixtures.length; i++) {
|
|
2508
2505
|
const fix = processedFixtures[i];
|
|
2509
|
-
|
|
2510
|
-
if (fixRes) {
|
|
2511
|
-
const fixture = fixRes.toObject();
|
|
2512
|
-
storeFixtures.push({ ...fixture, shelfConfig: fix.shelfConfig });
|
|
2513
|
-
}
|
|
2506
|
+
await storeFixtureService.create(fix);
|
|
2514
2507
|
}
|
|
2515
2508
|
} catch (e) {
|
|
2516
2509
|
logger.error({
|
|
@@ -2519,18 +2512,6 @@ export async function createPlanoFromCAD(req, res) {
|
|
|
2519
2512
|
});
|
|
2520
2513
|
}
|
|
2521
2514
|
|
|
2522
|
-
|
|
2523
|
-
try {
|
|
2524
|
-
const updateStoreFixtures = await processFixtureTemplates({ fixtures: storeFixtures });
|
|
2525
|
-
|
|
2526
|
-
if (updateStoreFixtures.length) await storeFixtureService.bulkUpsert(updateStoreFixtures);
|
|
2527
|
-
} catch (e) {
|
|
2528
|
-
logger.error({
|
|
2529
|
-
functionName: 'createPlanoFromCAD [Update Fixtures]',
|
|
2530
|
-
error: e,
|
|
2531
|
-
});
|
|
2532
|
-
}
|
|
2533
|
-
|
|
2534
2515
|
return res.sendSuccess(meta);
|
|
2535
2516
|
|
|
2536
2517
|
} catch (error) {
|
|
@@ -2539,7 +2520,7 @@ export async function createPlanoFromCAD(req, res) {
|
|
|
2539
2520
|
error,
|
|
2540
2521
|
});
|
|
2541
2522
|
|
|
2542
|
-
return res.sendError(
|
|
2523
|
+
return res.sendError('Failed to create planogram.', 500);
|
|
2543
2524
|
}
|
|
2544
2525
|
}
|
|
2545
2526
|
|
|
@@ -2617,13 +2598,11 @@ function processFixtureData(data) {
|
|
|
2617
2598
|
fixtureWidth: f?.fixtureWidth,
|
|
2618
2599
|
fixtureLength: f?.fixtureLength,
|
|
2619
2600
|
fixtureNumber: f?.fixtureNumber,
|
|
2620
|
-
templateGroupName: f?.templateGroupName ?? f?.header?.label,
|
|
2621
|
-
fixtureCategory: f?.fixtureCategory,
|
|
2622
2601
|
associatedElementNumber: data?.wallNumber,
|
|
2623
2602
|
associatedElementFixtureNumber: data.fixtureNumber,
|
|
2624
2603
|
associatedElementType: f?.associatedElementType === 'wall' ? 'wall' : undefined,
|
|
2625
2604
|
productBrandName: Array.isArray(f?.productBrandName) ? f?.productBrandName?.map(normalizeCadText) : normalizeCadText(f?.productBrandName),
|
|
2626
|
-
|
|
2605
|
+
|
|
2627
2606
|
fixtureHeight: {
|
|
2628
2607
|
value: 0,
|
|
2629
2608
|
unit: 'mm',
|
|
@@ -2641,114 +2620,4 @@ function processFixtureData(data) {
|
|
|
2641
2620
|
isMerchEdited: false,
|
|
2642
2621
|
isVmEdited: false,
|
|
2643
2622
|
};
|
|
2644
|
-
}
|
|
2645
|
-
|
|
2646
|
-
async function processFixtureTemplates(data) {
|
|
2647
|
-
const updateStoreFixtures = [];
|
|
2648
|
-
const newFixtureTemplates = [];
|
|
2649
|
-
|
|
2650
|
-
for (let i = 0; i < data.fixtures.length; i++) {
|
|
2651
|
-
let fixture = data.fixtures[i];
|
|
2652
|
-
const mapKey = `${fixture.fixtureCategory}${fixture.fixtureWidth.value}${fixture.fixtureWidth.unit}${fixture.header.label}`;
|
|
2653
|
-
|
|
2654
|
-
const subTemplateQuery = [
|
|
2655
|
-
{
|
|
2656
|
-
$addFields: {
|
|
2657
|
-
crestMapKey: { $toLower: '$crestMapKey' },
|
|
2658
|
-
},
|
|
2659
|
-
},
|
|
2660
|
-
{
|
|
2661
|
-
$match: {
|
|
2662
|
-
crestMapKey: mapKey.toLowerCase(),
|
|
2663
|
-
templateType: 'sub',
|
|
2664
|
-
},
|
|
2665
|
-
},
|
|
2666
|
-
];
|
|
2667
|
-
|
|
2668
|
-
const masterTemplateQuery = [
|
|
2669
|
-
{
|
|
2670
|
-
$addFields: {
|
|
2671
|
-
crestMapKey: { $toLower: '$crestMapKey' },
|
|
2672
|
-
},
|
|
2673
|
-
},
|
|
2674
|
-
{
|
|
2675
|
-
$match: {
|
|
2676
|
-
crestMapKey: mapKey.toLowerCase(),
|
|
2677
|
-
templateType: 'master',
|
|
2678
|
-
},
|
|
2679
|
-
},
|
|
2680
|
-
];
|
|
2681
|
-
|
|
2682
|
-
let [subTemplate, masterTemplate] = await Promise.all([
|
|
2683
|
-
await fixtureConfigService.aggregate(subTemplateQuery),
|
|
2684
|
-
await fixtureConfigService.aggregate(masterTemplateQuery),
|
|
2685
|
-
]);
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
if (!subTemplate?.length) {
|
|
2689
|
-
const templateGroupName = fixture.header.label;
|
|
2690
|
-
let templateIndex = 1;
|
|
2691
|
-
|
|
2692
|
-
let newTemplateData = {
|
|
2693
|
-
...fixture,
|
|
2694
|
-
templateGroupName: templateGroupName,
|
|
2695
|
-
status: 'complete',
|
|
2696
|
-
templateIndex: masterTemplate.length ? masterTemplate.length + 1 : 1,
|
|
2697
|
-
crestMapKey: mapKey,
|
|
2698
|
-
}
|
|
2699
|
-
|
|
2700
|
-
delete newTemplateData._id;
|
|
2701
|
-
|
|
2702
|
-
if (!masterTemplate.length) {
|
|
2703
|
-
const newMasterTemplate = {
|
|
2704
|
-
...newTemplateData,
|
|
2705
|
-
fixtureName: `${newTemplateData?.header?.label}-${newTemplateData?.fixtureCategory}`,
|
|
2706
|
-
templateType: 'master',
|
|
2707
|
-
crestMapKey: mapKey,
|
|
2708
|
-
}
|
|
2709
|
-
masterTemplate = await fixtureConfigService.create(newMasterTemplate);
|
|
2710
|
-
} else {
|
|
2711
|
-
masterTemplate = masterTemplate[0];
|
|
2712
|
-
|
|
2713
|
-
const masterTempIndexQuery = [
|
|
2714
|
-
{
|
|
2715
|
-
$match: {
|
|
2716
|
-
masterTemplateId: new mongoose.Types.ObjectId(masterTemplate._id),
|
|
2717
|
-
},
|
|
2718
|
-
}, {
|
|
2719
|
-
$group: {
|
|
2720
|
-
_id: '',
|
|
2721
|
-
tempId: { $max: '$templateIndex' },
|
|
2722
|
-
},
|
|
2723
|
-
},
|
|
2724
|
-
];
|
|
2725
|
-
|
|
2726
|
-
const getMaxTempIndex = await fixtureConfigService.aggregate(masterTempIndexQuery);
|
|
2727
|
-
templateIndex = getMaxTempIndex?.[0]?.tempId + 1;
|
|
2728
|
-
}
|
|
2729
|
-
|
|
2730
|
-
newTemplateData.fixtureName = `${fixture?.header?.label}-${fixture?.fixtureCategory}-${fixture?.fixtureWidth?.value}-${fixture?.fixtureWidth?.unit}-variant-${templateIndex}`;
|
|
2731
|
-
newTemplateData.templateType = 'sub';
|
|
2732
|
-
newTemplateData.masterTemplateId = masterTemplate._id;
|
|
2733
|
-
newTemplateData.templateIndex = templateIndex;
|
|
2734
|
-
newTemplateData.createdAt = new Date();
|
|
2735
|
-
newTemplateData.updatedAt = new Date();
|
|
2736
|
-
|
|
2737
|
-
subTemplate = await fixtureConfigService.create(newTemplateData);
|
|
2738
|
-
|
|
2739
|
-
fixture.fixtureConfigId = subTemplate._id;
|
|
2740
|
-
fixture.masterTemplateId = masterTemplate._id;
|
|
2741
|
-
fixture.fixtureName = newTemplateData.fixtureName;
|
|
2742
|
-
} else {
|
|
2743
|
-
const sub = subTemplate?.[0];
|
|
2744
|
-
fixture.fixtureName = sub.fixtureName;
|
|
2745
|
-
fixture.fixtureConfigId = sub?._id;
|
|
2746
|
-
fixture.masterTemplateId = sub?.masterTemplateId;
|
|
2747
|
-
}
|
|
2748
|
-
|
|
2749
|
-
newFixtureTemplates.push(subTemplate);
|
|
2750
|
-
updateStoreFixtures.push(fixture);
|
|
2751
|
-
}
|
|
2752
|
-
|
|
2753
|
-
return updateStoreFixtures;
|
|
2754
2623
|
}
|
|
@@ -18687,3 +18687,47 @@ export async function getFxCode( req, res ) {
|
|
|
18687
18687
|
}
|
|
18688
18688
|
}
|
|
18689
18689
|
|
|
18690
|
+
export async function getFixtureDetails( req, res ) {
|
|
18691
|
+
try {
|
|
18692
|
+
if ( !req.body?.storeName ) {
|
|
18693
|
+
return res.sendError( 'StoreName is required', 400 );
|
|
18694
|
+
}
|
|
18695
|
+
|
|
18696
|
+
let query = [
|
|
18697
|
+
{
|
|
18698
|
+
$match: {
|
|
18699
|
+
storeName: req.body?.storeName,
|
|
18700
|
+
fixtureType: { $ne: 'other' },
|
|
18701
|
+
},
|
|
18702
|
+
},
|
|
18703
|
+
{
|
|
18704
|
+
$sort: {
|
|
18705
|
+
fixtureNumber: 1,
|
|
18706
|
+
},
|
|
18707
|
+
},
|
|
18708
|
+
{
|
|
18709
|
+
$group: {
|
|
18710
|
+
_id: '',
|
|
18711
|
+
fixtureData: { $push: {
|
|
18712
|
+
k: { $concat: [ 'Fixture', ' ', { $toString: '$fixtureNumber' } ] },
|
|
18713
|
+
v: '$header.label',
|
|
18714
|
+
},
|
|
18715
|
+
},
|
|
18716
|
+
},
|
|
18717
|
+
},
|
|
18718
|
+
{
|
|
18719
|
+
$project: {
|
|
18720
|
+
_id: 0,
|
|
18721
|
+
fixtureData: {
|
|
18722
|
+
$arrayToObject: '$fixtureData',
|
|
18723
|
+
},
|
|
18724
|
+
},
|
|
18725
|
+
},
|
|
18726
|
+
];
|
|
18727
|
+
let fixtureDetails = await storeFixtureService.aggregate( query );
|
|
18728
|
+
return res.sendSuccess( fixtureDetails?.[0]?.fixtureData ?? {} );
|
|
18729
|
+
} catch ( e ) {
|
|
18730
|
+
logger.error( { functionName: "getFixtureDetails", error: e } );
|
|
18731
|
+
return res.sendError( e, 500 );
|
|
18732
|
+
}
|
|
18733
|
+
}
|
|
@@ -2,6 +2,8 @@ import express from 'express';
|
|
|
2
2
|
|
|
3
3
|
import * as scriptController from '../controllers/script.controller.js';
|
|
4
4
|
|
|
5
|
+
import { isAllowedInternalAPIHandler } from 'tango-app-api-middleware';
|
|
6
|
+
|
|
5
7
|
export const scriptRouter = express.Router();
|
|
6
8
|
|
|
7
9
|
scriptRouter
|
|
@@ -45,4 +47,5 @@ scriptRouter
|
|
|
45
47
|
.post( '/getmisMatchedGroup', scriptController.getmisMatchedGroup )
|
|
46
48
|
.post( '/updateProduct', scriptController.updateProduct )
|
|
47
49
|
.post( '/getFxCode', scriptController.getFxCode )
|
|
50
|
+
.post( '/getFixtureDetails', isAllowedInternalAPIHandler, scriptController.getFixtureDetails )
|
|
48
51
|
;
|