tango-app-api-store-builder 1.0.0-beta-75 → 1.0.0-beta-76
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/crest_scrap.json +1160 -0
- package/package.json +1 -1
- package/src/controllers/script.controller.js +376 -27
- package/src/controllers/storeBuilder.controller.js +3 -1
- package/src/controllers/task.controller.js +3 -1
- package/src/routes/script.routes.js +4 -1
- package/src/routes/storeBuilder.routes.js +3 -3
- package/src/service/fixtureShelf.service.js +4 -0
- package/src/service/planoMapping.service.js +8 -0
- package/src/service/storeFixture.service.js +8 -0
package/package.json
CHANGED
|
@@ -15,6 +15,9 @@ import * as planoTaskService from '../service/planoTask.service.js';
|
|
|
15
15
|
import * as fixtureConfigService from '../service/fixtureConfig.service.js';
|
|
16
16
|
import mongoose from 'mongoose';
|
|
17
17
|
import JSZip from 'jszip';
|
|
18
|
+
import { signedUrl } from 'tango-app-api-middleware';
|
|
19
|
+
import fs from 'fs';
|
|
20
|
+
import https from 'https';
|
|
18
21
|
|
|
19
22
|
|
|
20
23
|
export async function getStoreNames( req, res ) {
|
|
@@ -1777,6 +1780,28 @@ export async function getProdTaskData( req, res ) {
|
|
|
1777
1780
|
}
|
|
1778
1781
|
}
|
|
1779
1782
|
|
|
1783
|
+
export async function extractZipFileNames( req, res ) {
|
|
1784
|
+
try {
|
|
1785
|
+
if ( req?.headers?.authorization?.split( ' ' )[1] !== 'hwjXfCD6TgMvc82cuSGZ9bNv9MuXsaiQ6uvx' ) {
|
|
1786
|
+
return res.sendError( 'Unauthorized', 401 );
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
if ( !req.files.file ) {
|
|
1790
|
+
return res.sendError( 'No file uploaded', 400 );
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
const zip = new JSZip();
|
|
1794
|
+
const zipContents = await zip.loadAsync( req.files.file.data );
|
|
1795
|
+
|
|
1796
|
+
const fileNames = Object.keys( zipContents.files );
|
|
1797
|
+
|
|
1798
|
+
return res.sendSuccess( { fileNames } );
|
|
1799
|
+
} catch ( e ) {
|
|
1800
|
+
logger.error( { functionName: 'extractZipFileNames', error: e } );
|
|
1801
|
+
return res.sendError( e.message || 'Internal Server Error', 500 );
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1780
1805
|
export async function updatelayoutFeedback( req, res ) {
|
|
1781
1806
|
try {
|
|
1782
1807
|
if ( req?.headers?.authorization?.split( ' ' )[1] !== 'hwjXfCD6TgMvc82cuSGZ9bNv9MuXsaiQ6uvx' ) {
|
|
@@ -1825,6 +1850,9 @@ export async function updatelayoutFeedback( req, res ) {
|
|
|
1825
1850
|
case 'Wall 3':
|
|
1826
1851
|
rightFixtures.push( {} );
|
|
1827
1852
|
break;
|
|
1853
|
+
case 'centre':
|
|
1854
|
+
floorFixtures.push( {} );
|
|
1855
|
+
break;
|
|
1828
1856
|
|
|
1829
1857
|
default:
|
|
1830
1858
|
break;
|
|
@@ -1939,28 +1967,6 @@ export async function updatelayoutFeedback( req, res ) {
|
|
|
1939
1967
|
}
|
|
1940
1968
|
}
|
|
1941
1969
|
|
|
1942
|
-
export async function extractZipFileNames( req, res ) {
|
|
1943
|
-
try {
|
|
1944
|
-
if ( req?.headers?.authorization?.split( ' ' )[1] !== 'hwjXfCD6TgMvc82cuSGZ9bNv9MuXsaiQ6uvx' ) {
|
|
1945
|
-
return res.sendError( 'Unauthorized', 401 );
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
if ( !req.files.file ) {
|
|
1949
|
-
return res.sendError( 'No file uploaded', 400 );
|
|
1950
|
-
}
|
|
1951
|
-
|
|
1952
|
-
const zip = new JSZip();
|
|
1953
|
-
const zipContents = await zip.loadAsync( req.files.file.data );
|
|
1954
|
-
|
|
1955
|
-
const fileNames = Object.keys( zipContents.files );
|
|
1956
|
-
|
|
1957
|
-
return res.sendSuccess( { fileNames } );
|
|
1958
|
-
} catch ( e ) {
|
|
1959
|
-
logger.error( { functionName: 'extractZipFileNames', error: e } );
|
|
1960
|
-
return res.sendError( e.message || 'Internal Server Error', 500 );
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
|
|
1964
1970
|
export async function updateFixtureFeedback( req, res ) {
|
|
1965
1971
|
try {
|
|
1966
1972
|
if ( req?.headers?.authorization?.split( ' ' )[1] !== 'hwjXfCD6TgMvc82cuSGZ9bNv9MuXsaiQ6uvx' ) {
|
|
@@ -1987,7 +1993,7 @@ export async function updateFixtureFeedback( req, res ) {
|
|
|
1987
1993
|
|
|
1988
1994
|
const planogram = await planoService.findOne( { storeName: store.storeName } );
|
|
1989
1995
|
|
|
1990
|
-
const fixtureTaskList = await planoTaskService.find( { planoId: planogram.toObject()._id, type: 'fixture' } );
|
|
1996
|
+
const fixtureTaskList = await planoTaskService.find( { planoId: planogram.toObject()._id, type: 'fixture', date_string: store.date } );
|
|
1991
1997
|
|
|
1992
1998
|
for ( let j = 0; j < fixtureTaskList.length; j++ ) {
|
|
1993
1999
|
const fixtureTask = fixtureTaskList[j].toObject();
|
|
@@ -2002,6 +2008,38 @@ export async function updateFixtureFeedback( req, res ) {
|
|
|
2002
2008
|
|
|
2003
2009
|
const fixtureDoc = fixture?.toObject();
|
|
2004
2010
|
|
|
2011
|
+
if ( q1.issues.includes( 'Fixture size is wrong' ) ) {
|
|
2012
|
+
const fixtureConfig = await fixtureConfigService.findOne( { 'fixtureLength.value': q1.data.fixtureSize.value } );
|
|
2013
|
+
|
|
2014
|
+
if ( fixtureConfig && fixtureConfig.toObject()?.fixtureCode ) {
|
|
2015
|
+
await storeFixtureService.updateOne( { _id: fixtureDoc._id }, { fixtureCode: fixtureConfig.toObject().fixtureCode } );
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
if ( q1.issues.includes( 'Fixture type is wrong' ) ) {
|
|
2020
|
+
const fixtureConfig = await fixtureConfigService.findOne( { fixtureCategory: q1.data.fixtureType } );
|
|
2021
|
+
|
|
2022
|
+
if ( fixtureConfig && fixtureConfig.toObject().fixtureCode ) {
|
|
2023
|
+
await storeFixtureService.updateOne( { _id: fixtureDoc._id }, { fixtureCode: fixtureConfig.toObject().fixtureCode } );
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
if ( q1.issues.includes( 'Fixture brand is wrong' ) ) {
|
|
2028
|
+
const fixtureBrand = q1.data.fixtureBrand;
|
|
2029
|
+
|
|
2030
|
+
if ( fixtureBrand?.length ) {
|
|
2031
|
+
const formattedfixtureBrand = fixtureBrand.length ? ( fixtureBrand.length > 1 ? fixtureBrand.join( ' + ' ) : fixtureBrand[0] ) : undefined;
|
|
2032
|
+
|
|
2033
|
+
await storeFixtureService.updateOne( { _id: fixtureDoc._id }, { fixtureName: formattedfixtureBrand, fixtureBrandCategory: formattedfixtureBrand } );
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
if ( q1.issues.includes( 'Fixture not in the store' ) ) {
|
|
2038
|
+
await storeFixtureService.deleteOne( { _id: fixtureDoc._id } );
|
|
2039
|
+
await fixtureShelfService.deleteMany( { fixtureId: fixtureDoc._id } );
|
|
2040
|
+
await planoMappingService.deleteMany( { fixtureId: fixtureDoc._id } );
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2005
2043
|
|
|
2006
2044
|
if ( q1.issues.includes( 'Shelves count/Product Category/Capacity is wrong' ) ) {
|
|
2007
2045
|
const taskShelves = q1.data.shelves;
|
|
@@ -2022,7 +2060,6 @@ export async function updateFixtureFeedback( req, res ) {
|
|
|
2022
2060
|
const section = taskShelf.section;
|
|
2023
2061
|
const subBrand = taskShelf.subBrand;
|
|
2024
2062
|
const formattedsubBrand = subBrand.length ? ( subBrand.length > 1 ? subBrand.join( ' + ' ) : subBrand[0] ) : undefined;
|
|
2025
|
-
// const formattedsubBrand = subBrand ? subBrand : undefined;
|
|
2026
2063
|
|
|
2027
2064
|
if ( taskShelves.length === fixtureShelves.length ) {
|
|
2028
2065
|
const fixtureShelf = fixtureShelves.filter( ( shelf ) => {
|
|
@@ -2037,18 +2074,17 @@ export async function updateFixtureFeedback( req, res ) {
|
|
|
2037
2074
|
return shelf.toObject().shelfNumber === k+1;
|
|
2038
2075
|
} );
|
|
2039
2076
|
|
|
2040
|
-
|
|
2041
2077
|
const updateShelf = await fixtureShelfService.updateOne( { _id: fixtureShelf?.[0].toObject()._id }, { shelfCapacity: productCapacity, sectionName: formattedsubBrand, sectionZone: section } );
|
|
2042
2078
|
|
|
2043
2079
|
console.log( updateShelf );
|
|
2044
2080
|
|
|
2045
|
-
|
|
2046
2081
|
const shelfDifference = fixtureShelves.length - taskShelves.length;
|
|
2047
2082
|
|
|
2048
2083
|
const shelvesToDelete = fixtureShelves.slice( -shelfDifference );
|
|
2049
2084
|
|
|
2050
2085
|
shelvesToDelete.map( async ( shelf ) => {
|
|
2051
2086
|
await fixtureShelfService.deleteOne( { _id: shelf.toObject()._id } );
|
|
2087
|
+
await planoMappingService.deleteMany( { shelfId: shelf.toObject()._id } );
|
|
2052
2088
|
} );
|
|
2053
2089
|
} else if ( taskShelves.length > fixtureShelves.length ) {
|
|
2054
2090
|
if ( k + 1 <= fixtureShelves.length ) {
|
|
@@ -2082,11 +2118,324 @@ export async function updateFixtureFeedback( req, res ) {
|
|
|
2082
2118
|
}
|
|
2083
2119
|
}
|
|
2084
2120
|
}
|
|
2121
|
+
|
|
2122
|
+
const vmTaskList = await planoTaskService.find( { planoId: planogram.toObject()._id, type: 'vm', date_string: store.date } );
|
|
2123
|
+
|
|
2124
|
+
for ( let j = 0; j < vmTaskList.length; j++ ) {
|
|
2125
|
+
const vmTask = vmTaskList[j].toObject();
|
|
2126
|
+
|
|
2127
|
+
const [ q1, q2 ] = vmTask.answers;
|
|
2128
|
+
|
|
2129
|
+
if ( q1.value ) continue;
|
|
2130
|
+
|
|
2131
|
+
const removeVms = q1.selectedVMs.forEach( async ( vmId ) => {
|
|
2132
|
+
if ( !vmId ) return;
|
|
2133
|
+
const vmObjectId = new mongoose.Types.ObjectId( vmId );
|
|
2134
|
+
|
|
2135
|
+
const deletedVm = await planoMappingService.deleteOne( { _id: vmObjectId } );
|
|
2136
|
+
|
|
2137
|
+
return deletedVm;
|
|
2138
|
+
} );
|
|
2139
|
+
|
|
2140
|
+
console.log( removeVms, 'removed vms' );
|
|
2141
|
+
|
|
2142
|
+
const newVms = q1.newVmsType.forEach( async ( vmType ) => {
|
|
2143
|
+
const vm = await planoProductService.findOne( { type: 'vm', productName: vmType } );
|
|
2144
|
+
|
|
2145
|
+
if ( !vm ) return;
|
|
2146
|
+
|
|
2147
|
+
const insertData = {
|
|
2148
|
+
'clientId': planogram.toObject().clientId,
|
|
2149
|
+
'storeName': planogram.toObject().storeName,
|
|
2150
|
+
'storeId': planogram.toObject().storeId,
|
|
2151
|
+
'type': 'vm',
|
|
2152
|
+
'planoId': planogram.toObject()._id,
|
|
2153
|
+
'floorId': vmTask.floorId,
|
|
2154
|
+
'fixtureId': vmTask.fixtureId,
|
|
2155
|
+
'productId': vm.toObject()._id,
|
|
2156
|
+
};
|
|
2157
|
+
|
|
2158
|
+
const insertedVm = await planoMappingService.create( insertData );
|
|
2159
|
+
|
|
2160
|
+
return insertedVm;
|
|
2161
|
+
} );
|
|
2162
|
+
|
|
2163
|
+
console.log( newVms, 'new vms' );
|
|
2164
|
+
}
|
|
2085
2165
|
}
|
|
2086
2166
|
|
|
2087
2167
|
res.sendSuccess( 'Updated successfully' );
|
|
2088
2168
|
} catch ( e ) {
|
|
2089
|
-
logger.error( { functionName: '
|
|
2169
|
+
logger.error( { functionName: 'updateFixtureFeedback', error: e } );
|
|
2170
|
+
return res.sendError( e.message || 'Internal Server Error', 500 );
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
export async function getVmTaskData( req, res ) {
|
|
2175
|
+
try {
|
|
2176
|
+
const { storeName, date } = req.body;
|
|
2177
|
+
|
|
2178
|
+
const planogram = await planoService.findOne( { storeName: storeName } );
|
|
2179
|
+
|
|
2180
|
+
const vmTaskList = await planoTaskService.find( { planoId: planogram.toObject()._id, type: 'vm', date_string: date } );
|
|
2181
|
+
|
|
2182
|
+
if ( !vmTaskList?.length ) {
|
|
2183
|
+
return res.sendError( 'No data', 204 );
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
const storefixtures = await storeFixtureService.findAndSort( { planoId: planogram.toObject()._id, fixtureType: { $ne: 'other' } }, { fixtureName: 1, fixtureNumber: 1, _id: 1 }, { fixtureNumber: 1 } );
|
|
2187
|
+
|
|
2188
|
+
const fixtureVmData = await Promise.all(
|
|
2189
|
+
storefixtures.map( async ( fixture ) => {
|
|
2190
|
+
const fixtureDoc = fixture.toObject();
|
|
2191
|
+
const vmTasks = await planoTaskService.find( { fixtureId: fixture._id, type: 'vm' } );
|
|
2192
|
+
|
|
2193
|
+
const q2 = vmTasks[0].toObject().answers?.[1];
|
|
2194
|
+
|
|
2195
|
+
const params = {
|
|
2196
|
+
Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
|
|
2197
|
+
file_path: q2?.image || null,
|
|
2198
|
+
};
|
|
2199
|
+
|
|
2200
|
+
const fixtureImage = await signedUrl( params );
|
|
2201
|
+
|
|
2202
|
+
const vmTaskData = await Promise.all(
|
|
2203
|
+
vmTasks.flatMap( ( task ) => {
|
|
2204
|
+
const q1 = task.toObject().answers?.[0];
|
|
2205
|
+
|
|
2206
|
+
if ( !q1?.newVmsType || !q1?.newVms ) return [];
|
|
2207
|
+
|
|
2208
|
+
return q1.newVmsType.map( async ( vmtype, k ) => {
|
|
2209
|
+
const params = {
|
|
2210
|
+
Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
|
|
2211
|
+
file_path: q1.newVms[k]?.imageUrl || null,
|
|
2212
|
+
};
|
|
2213
|
+
const signedImg = await signedUrl( params );
|
|
2214
|
+
|
|
2215
|
+
return {
|
|
2216
|
+
vmtype,
|
|
2217
|
+
vmImg: signedImg,
|
|
2218
|
+
};
|
|
2219
|
+
} );
|
|
2220
|
+
} ),
|
|
2221
|
+
);
|
|
2222
|
+
|
|
2223
|
+
return {
|
|
2224
|
+
vms: vmTaskData,
|
|
2225
|
+
fixtureImg: fixtureImage,
|
|
2226
|
+
...fixtureDoc,
|
|
2227
|
+
};
|
|
2228
|
+
} ),
|
|
2229
|
+
);
|
|
2230
|
+
return res.sendSuccess( fixtureVmData );
|
|
2231
|
+
} catch ( e ) {
|
|
2232
|
+
logger.error( { functionName: 'getVmTaskData', error: e } );
|
|
2090
2233
|
return res.sendError( e.message || 'Internal Server Error', 500 );
|
|
2091
2234
|
}
|
|
2092
2235
|
}
|
|
2236
|
+
|
|
2237
|
+
|
|
2238
|
+
export async function updateVmData( req, res ) {
|
|
2239
|
+
try {
|
|
2240
|
+
if ( req?.headers?.authorization?.split( ' ' )[1] !== 'hwjXfCD6TgMvc82cuSGZ9bNv9MuXsaiQ6uvx' ) {
|
|
2241
|
+
return res.sendError( 'Unauthorized', 401 );
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
if ( !req.files.file ) {
|
|
2245
|
+
return res.sendError( 'Excel file is required', 400 );
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
const workbook = xlsx.read( req.files.file.data, { type: 'buffer' } );
|
|
2249
|
+
const sheetName = 'Basha';
|
|
2250
|
+
const raw = xlsx.utils.sheet_to_json( workbook.Sheets[sheetName] );
|
|
2251
|
+
|
|
2252
|
+
let initId = 81;
|
|
2253
|
+
|
|
2254
|
+
for ( let i = 0; i < raw.length; i++ ) {
|
|
2255
|
+
const vmData = raw[i];
|
|
2256
|
+
|
|
2257
|
+
const vmInsertData = {
|
|
2258
|
+
'clientId': '11',
|
|
2259
|
+
'type': 'vm',
|
|
2260
|
+
'productId': 'VM' + initId,
|
|
2261
|
+
'productName': vmData?.['VM Categories '],
|
|
2262
|
+
'productHeight': {
|
|
2263
|
+
'value': vmData?.['VM Height mm'],
|
|
2264
|
+
'unit': 'mm',
|
|
2265
|
+
},
|
|
2266
|
+
'productWidth': {
|
|
2267
|
+
'value': vmData?.['VM Width mm'],
|
|
2268
|
+
'unit': 'mm',
|
|
2269
|
+
},
|
|
2270
|
+
'startYPosition': vmData?.['StartPosition '],
|
|
2271
|
+
'endYPosition': vmData?.['End Position'],
|
|
2272
|
+
'xZone': vmData?.['Start Zone '],
|
|
2273
|
+
};
|
|
2274
|
+
|
|
2275
|
+
const createdVm = await planoProductService.create( vmInsertData );
|
|
2276
|
+
|
|
2277
|
+
initId += 1;
|
|
2278
|
+
|
|
2279
|
+
const fixture = await storeFixtureService.findOne( { storeName: vmData?.['Store name '], fixtureNumber: vmData?.['Fixture Number'] } );
|
|
2280
|
+
|
|
2281
|
+
const fixtureDoc = fixture?.toObject();
|
|
2282
|
+
|
|
2283
|
+
if ( !fixture ) {
|
|
2284
|
+
continue;
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
const mappingData = {
|
|
2288
|
+
'clientId': '11',
|
|
2289
|
+
'storeName': fixtureDoc.storeName,
|
|
2290
|
+
'storeId': fixtureDoc.storeId,
|
|
2291
|
+
'type': 'vm',
|
|
2292
|
+
'planoId': fixtureDoc.planoId,
|
|
2293
|
+
'floorId': fixtureDoc.floorId,
|
|
2294
|
+
'fixtureId': fixtureDoc._id,
|
|
2295
|
+
'productId': createdVm.toObject()._id,
|
|
2296
|
+
};
|
|
2297
|
+
|
|
2298
|
+
await planoMappingService.create( mappingData );
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
res.sendSuccess( 'Updated Successfully' );
|
|
2302
|
+
} catch ( e ) {
|
|
2303
|
+
logger.error( { functionName: 'getVmTaskData', error: e } );
|
|
2304
|
+
return res.sendError( e.message || 'Internal Server Error', 500 );
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
|
|
2308
|
+
|
|
2309
|
+
async function scrapeCrest() {
|
|
2310
|
+
const storeIds = [];
|
|
2311
|
+
const apiUrl = 'https://api.getcrest.ai/api/ms_shelfsensei/layout/';
|
|
2312
|
+
const bearerToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQzNjY5ODIyLCJpYXQiOjE3NDM2NjYyMjIsImp0aSI6IjA5ZDRjYTVhZGRiNzQxMDVhYjhjOWVjMmU3MjZiM2NiIiwidXNlcl9pZCI6MTA4NSwiaWQiOjEwODUsImN1c3RvbWVyX2dyb3VwIjozOTgsImxpY2VuY2Vfc2NvcGVzIjpbeyJyZXNvdXJjZV9zZXQiOiJwcF9zZXQiLCJzY29wZV9yb2xlIjoiY29udHJpYnV0b3IifSx7InJlc291cmNlX3NldCI6ImRwX3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9LHsicmVzb3VyY2Vfc2V0IjoiZGZfc2V0Iiwic2NvcGVfcm9sZSI6ImNvbnRyaWJ1dG9yIn0seyJyZXNvdXJjZV9zZXQiOiJkZWZhdWx0X3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9XX0.C3wLXzbv0bTDGiZqs8jSA3up0cq0wqA5PIMw45_T4Wg';
|
|
2313
|
+
const filePath = 'response.json';
|
|
2314
|
+
let allResults = [];
|
|
2315
|
+
|
|
2316
|
+
if ( fs.existsSync( filePath ) ) {
|
|
2317
|
+
try {
|
|
2318
|
+
const existingData = fs.readFileSync( filePath, 'utf8' );
|
|
2319
|
+
allResults = JSON.parse( existingData );
|
|
2320
|
+
if ( !Array.isArray( allResults ) ) {
|
|
2321
|
+
allResults = [];
|
|
2322
|
+
}
|
|
2323
|
+
} catch ( error ) {
|
|
2324
|
+
console.error( 'Error reading existing JSON file:', error.message );
|
|
2325
|
+
allResults = [];
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
for ( const storeId of storeIds ) {
|
|
2330
|
+
try {
|
|
2331
|
+
const result = await new Promise( ( resolve ) => {
|
|
2332
|
+
const payload = JSON.stringify( { store_id: storeId } );
|
|
2333
|
+
const options = {
|
|
2334
|
+
method: 'POST',
|
|
2335
|
+
headers: {
|
|
2336
|
+
'Authorization': `Bearer ${bearerToken}`,
|
|
2337
|
+
'Content-Type': 'application/json',
|
|
2338
|
+
'Content-Length': Buffer.byteLength( payload ),
|
|
2339
|
+
},
|
|
2340
|
+
};
|
|
2341
|
+
|
|
2342
|
+
const req = https.request( apiUrl, options, ( res ) => {
|
|
2343
|
+
let data = '';
|
|
2344
|
+
res.on( 'data', ( chunk ) => {
|
|
2345
|
+
data += chunk;
|
|
2346
|
+
} );
|
|
2347
|
+
res.on( 'end', () => {
|
|
2348
|
+
try {
|
|
2349
|
+
const jsonData = JSON.parse( data );
|
|
2350
|
+
const result = { storeName: storeId, data: jsonData };
|
|
2351
|
+
allResults.push( result );
|
|
2352
|
+
fs.writeFileSync( filePath, JSON.stringify( allResults, null, 2 ) );
|
|
2353
|
+
console.log( 'Received Data:', result );
|
|
2354
|
+
resolve( result );
|
|
2355
|
+
} catch ( error ) {
|
|
2356
|
+
console.error( `Error parsing JSON for ${storeId}:`, error.message );
|
|
2357
|
+
resolve( { storeName: storeId, data: null } );
|
|
2358
|
+
}
|
|
2359
|
+
} );
|
|
2360
|
+
} );
|
|
2361
|
+
|
|
2362
|
+
req.on( 'error', ( error ) => {
|
|
2363
|
+
console.error( `Error fetching data for ${storeId}:`, error.message );
|
|
2364
|
+
resolve( { storeName: storeId, data: null } );
|
|
2365
|
+
} );
|
|
2366
|
+
|
|
2367
|
+
req.write( payload );
|
|
2368
|
+
req.end();
|
|
2369
|
+
} );
|
|
2370
|
+
} catch ( error ) {
|
|
2371
|
+
console.error( `Unexpected error for ${storeId}:`, error.message );
|
|
2372
|
+
}
|
|
2373
|
+
await new Promise( ( resolve ) => setTimeout( resolve, 1000 ) );
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2377
|
+
export async function createCrestPlanogram( req, res ) {
|
|
2378
|
+
try {
|
|
2379
|
+
if ( req?.headers?.authorization?.split( ' ' )[1] !== 'hwjXfCD6TgMvc82cuSGZ9bNv9MuXsaiQ6uvx' ) {
|
|
2380
|
+
return res.sendError( 'Unauthorized', 401 );
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
if ( !req.files || !req.files.file ) {
|
|
2384
|
+
return res.sendError( 'JSON file is required', 400 );
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
const data = JSON.parse( req.files.file.data.toString( 'utf8' ) );
|
|
2388
|
+
|
|
2389
|
+
const crestData = data.filter( ( item ) => item.data.message === 'SUCCESS' );
|
|
2390
|
+
|
|
2391
|
+
const fixtureTypes = new Set();
|
|
2392
|
+
const centerSubMains = new Set();
|
|
2393
|
+
|
|
2394
|
+
crestData.forEach( ( store ) => {
|
|
2395
|
+
store.data.result.forEach( ( section ) => {
|
|
2396
|
+
if ( section.fixtures ) {
|
|
2397
|
+
section.fixtures.forEach( ( fixture ) => {
|
|
2398
|
+
if ( fixture.fixtureType ) {
|
|
2399
|
+
fixtureTypes.add( fixture.fixtureType );
|
|
2400
|
+
}
|
|
2401
|
+
} );
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
if ( section.main === 'Euro Center' && section.centerSubMain ) {
|
|
2405
|
+
centerSubMains.add( section.centerSubMain );
|
|
2406
|
+
}
|
|
2407
|
+
} );
|
|
2408
|
+
} );
|
|
2409
|
+
|
|
2410
|
+
return res.sendSuccess( {
|
|
2411
|
+
fixtureTypes: Array.from( fixtureTypes ),
|
|
2412
|
+
euroCenterSubMains: Array.from( centerSubMains ),
|
|
2413
|
+
} );
|
|
2414
|
+
} catch ( e ) {
|
|
2415
|
+
logger.error( { functionName: 'createCrestPlanogram', error: e } );
|
|
2416
|
+
return res.sendError( e.message || 'Internal Server Error', 500 );
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
const data = {
|
|
2421
|
+
'clientId': '11',
|
|
2422
|
+
'fixtureCode': 'FX01',
|
|
2423
|
+
'fixtureCategory': 'Shelves',
|
|
2424
|
+
'fixtureConfigLength': {
|
|
2425
|
+
'value': 3,
|
|
2426
|
+
'unit': 'ft',
|
|
2427
|
+
},
|
|
2428
|
+
'fixtureConfigWidth': {
|
|
2429
|
+
'value': 2,
|
|
2430
|
+
'unit': 'ft',
|
|
2431
|
+
},
|
|
2432
|
+
'fixtureConfigType': 'Shelves',
|
|
2433
|
+
'shelfConfig': [
|
|
2434
|
+
{
|
|
2435
|
+
shelfNumber: 1,
|
|
2436
|
+
shelfZone: 'Top',
|
|
2437
|
+
shelfSplitup: 0,
|
|
2438
|
+
shelfProducts: 10,
|
|
2439
|
+
},
|
|
2440
|
+
],
|
|
2441
|
+
};
|
|
@@ -2633,6 +2633,7 @@ export const getFixtureTypes = async ( req, res ) => {
|
|
|
2633
2633
|
$project:
|
|
2634
2634
|
{
|
|
2635
2635
|
fixtureCategory: 1,
|
|
2636
|
+
fixtureLength: 1,
|
|
2636
2637
|
},
|
|
2637
2638
|
},
|
|
2638
2639
|
{
|
|
@@ -2643,12 +2644,13 @@ export const getFixtureTypes = async ( req, res ) => {
|
|
|
2643
2644
|
{
|
|
2644
2645
|
$group: {
|
|
2645
2646
|
_id: '$fixtureCategory',
|
|
2647
|
+
fixtureLength: { $first: '$fixtureLength' },
|
|
2646
2648
|
},
|
|
2647
2649
|
},
|
|
2648
2650
|
{
|
|
2649
2651
|
$group: {
|
|
2650
2652
|
'_id': null,
|
|
2651
|
-
'fixtureCategory': { '$push': '$_id' },
|
|
2653
|
+
'fixtureCategory': { '$push': { $concat: [ '$_id', '-', { $toString: '$fixtureLength.value' }, '$fixtureLength.unit' ] } },
|
|
2652
2654
|
},
|
|
2653
2655
|
},
|
|
2654
2656
|
{
|
|
@@ -139,6 +139,8 @@ export async function createTask( req, res ) {
|
|
|
139
139
|
}
|
|
140
140
|
let endDate = dayjs().add( req.body.days, 'day' ).format( 'YYYY-MM-DD' );
|
|
141
141
|
await Promise.all( taskDetails.map( async ( task ) => {
|
|
142
|
+
let splitName = task?.checkListName.split( ' ' );
|
|
143
|
+
splitName.pop();
|
|
142
144
|
let data = {
|
|
143
145
|
client_id: req.body.clientId,
|
|
144
146
|
date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
|
|
@@ -180,7 +182,7 @@ export async function createTask( req, res ) {
|
|
|
180
182
|
approvalEnable: false,
|
|
181
183
|
redoStatus: false,
|
|
182
184
|
isPlano: true,
|
|
183
|
-
planoType:
|
|
185
|
+
planoType: splitName.length == 1 ? splitName[0].toLowerCase() : splitName[0].toLowerCase() + splitName[2],
|
|
184
186
|
};
|
|
185
187
|
let query = [
|
|
186
188
|
{
|
|
@@ -19,4 +19,7 @@ scriptRouter
|
|
|
19
19
|
.post( '/getProdTaskData', scriptController.getProdTaskData )
|
|
20
20
|
.post( '/updateLayoutFeedback', scriptController.updatelayoutFeedback )
|
|
21
21
|
.post( '/updateFixtureFeedback', scriptController.updateFixtureFeedback )
|
|
22
|
-
.post( '/getFileNames', scriptController.extractZipFileNames )
|
|
22
|
+
.post( '/getFileNames', scriptController.extractZipFileNames )
|
|
23
|
+
.post( '/getVmTaskData', scriptController.getVmTaskData )
|
|
24
|
+
.post( '/updateVmData', scriptController.updateVmData )
|
|
25
|
+
.post( '/createCrestPlanogram', scriptController.createCrestPlanogram );
|
|
@@ -10,7 +10,7 @@ export const storeBuilderRouter = express.Router();
|
|
|
10
10
|
storeBuilderRouter
|
|
11
11
|
.post( '/createStoreLayout', isAllowedSessionHandler, validate( validateDtos.createBuilder ), storeBuilderController.createStoreBuilder )
|
|
12
12
|
.post( '/updateStoreLayout', isAllowedSessionHandler, validate( validateDtos.updateStoreLayout ), storeBuilderController.updateStoreLayout )
|
|
13
|
-
.post( '/storeLayoutList',
|
|
13
|
+
.post( '/storeLayoutList', validate( validateDtos.storeLayoutList ), storeBuilderController.getLayoutList )
|
|
14
14
|
.post( '/updateFloor', isAllowedSessionHandler, validate( validateDtos.updateFloor ), storeBuilderController.updateFloor )
|
|
15
15
|
.post( '/uploadBulkStore', isAllowedSessionHandler, storeBuilderController.uploadBulkStore )
|
|
16
16
|
.post( '/uploadFile', isAllowedSessionHandler, storeBuilderController.uploadFile )
|
|
@@ -23,7 +23,7 @@ storeBuilderRouter
|
|
|
23
23
|
// .post( '/FixtureShelfDetails', storeBuilderController.fixtureShelfProduct )
|
|
24
24
|
// .post( '/scan', storeBuilderController.scan )
|
|
25
25
|
.post( '/storeLayout', isAllowedSessionHandler, validate( validateDtos.storeList ), storeBuilderController.storeLayout )
|
|
26
|
-
.post( '/storeFixtures',
|
|
26
|
+
.post( '/storeFixtures', validate( validateDtos.storeList ), storeBuilderController.storeFixturesv1 )
|
|
27
27
|
.post( '/FixtureShelfDetails', isAllowedSessionHandler, validate( validateDtos.fixtureShelfProduct ), storeBuilderController.fixtureShelfProductv1 )
|
|
28
28
|
.post( '/scan', isAllowedSessionHandler, storeBuilderController.scanv1 )
|
|
29
29
|
.post( '/updateMissing', isAllowedSessionHandler, storeBuilderController.updateMissing )
|
|
@@ -41,5 +41,5 @@ storeBuilderRouter
|
|
|
41
41
|
.post( '/getFixtureTypes', isAllowedSessionHandler, storeBuilderController.getFixtureTypes )
|
|
42
42
|
.post( '/getFixtureLengths', isAllowedSessionHandler, storeBuilderController.getFixtureLengths )
|
|
43
43
|
.post( '/getFixtureBrands', isAllowedSessionHandler, storeBuilderController.getFixtureBrands )
|
|
44
|
-
.post( '/checkPlanoExist',
|
|
44
|
+
.post( '/checkPlanoExist', storeBuilderController.checkPlanoExist )
|
|
45
45
|
.post( '/storeLayoutElements', isAllowedSessionHandler, storeBuilderController.storeLayoutElements );
|
|
@@ -26,3 +26,11 @@ export async function count( query ) {
|
|
|
26
26
|
export async function create( data ) {
|
|
27
27
|
return model.planoMappingModel.create( data );
|
|
28
28
|
}
|
|
29
|
+
|
|
30
|
+
export async function deleteOne( query ) {
|
|
31
|
+
return model.planoMappingModel.deleteOne( query );
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function deleteMany( query ) {
|
|
35
|
+
return model.planoMappingModel.deleteMany( query );
|
|
36
|
+
}
|
|
@@ -31,3 +31,11 @@ export async function findOneAndUpdate2( query={}, field={} ) {
|
|
|
31
31
|
export async function create( data ) {
|
|
32
32
|
return model.storeFixtureModel.create( data );
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
export async function deleteOne( query ) {
|
|
36
|
+
return model.storeFixtureModel.deleteOne( query );
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function findAndSort( query={}, field={}, sortField={} ) {
|
|
40
|
+
return model.storeFixtureModel.find( query, field ).sort( sortField );
|
|
41
|
+
}
|