tango-app-api-store-builder 1.0.0-beta-28 → 1.0.0-beta-30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-store-builder",
3
- "version": "1.0.0-beta-28",
3
+ "version": "1.0.0-beta-30",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,7 +1,7 @@
1
1
  import * as storeBuilderService from '../service/storeBuilder.service.js';
2
2
  import * as storeService from '../service/store.service.js';
3
3
  import * as planoService from '../service/planogram.service.js';
4
- import { logger, fileUpload, signedUrl } from 'tango-app-api-middleware';
4
+ import { logger, fileUpload, signedUrl, sendMessageToQueue } from 'tango-app-api-middleware';
5
5
  import dayjs from 'dayjs';
6
6
  import customParseFormat from 'dayjs/plugin/customParseFormat.js';
7
7
  import utc from 'dayjs/plugin/utc.js';
@@ -12,6 +12,8 @@ import * as planoProductService from '../service/planoProduct.service.js';
12
12
  import * as planoMappingService from '../service/planoMapping.service.js';
13
13
  import * as planoComplianceService from '../service/planoCompliance.service.js';
14
14
  import * as planoTaskComplianceService from '../service/planoTask.service.js';
15
+ import path from 'path';
16
+
15
17
 
16
18
  dayjs.extend( utc );
17
19
  dayjs.extend( customParseFormat );
@@ -636,6 +638,15 @@ export async function storeFixturesv1( req, res ) {
636
638
 
637
639
  const centerFixturesWithStatus = await Promise.all(
638
640
  centerFixtures.map( async ( fixture ) => {
641
+ if ( fixture?.imageUrl ) {
642
+ let params = {
643
+ Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
644
+ file_path: fixture.imageUrl,
645
+ };
646
+ fixture.imageUrl = await signedUrl( params );
647
+ } else {
648
+ fixture.imageUrl = '';
649
+ }
639
650
  const productCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'product' } );
640
651
 
641
652
  const vmCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'vm' } );
@@ -948,6 +959,13 @@ export async function fixtureShelfProductv1( req, res ) {
948
959
  if ( !planogram ) return res.sendError( 'Planogram not found', 204 );
949
960
  if ( !fixture ) return res.sendError( 'Fixture not found', 204 );
950
961
 
962
+ let params = {
963
+ Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
964
+ file_path: fixture.imageUrl,
965
+ };
966
+
967
+ fixture.imageUrl = await signedUrl( params );
968
+
951
969
  const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
952
970
 
953
971
  const getProducts = async ( mappings ) => {
@@ -972,6 +990,15 @@ export async function fixtureShelfProductv1( req, res ) {
972
990
  const vmMappings = await planoMappingService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), type: 'vm' } );
973
991
  const vmIds = vmMappings.map( ( mapping ) => mapping.productId );
974
992
  const vms = await planoProductService.find( { _id: { $in: vmIds }, type: 'vm' } );
993
+ await Promise.all( vms.map( async ( vm ) => {
994
+ if ( vm?.productImageUrl ) {
995
+ let params = {
996
+ Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
997
+ file_path: vm?.productImageUrl,
998
+ };
999
+ vm.productImageUrl = await signedUrl( params );
1000
+ }
1001
+ } ) );
975
1002
  const vmMap = new Map( vms.map( ( vm ) => [ vm._id.toString(), vm.toObject() ] ) );
976
1003
  const vmDetails = vmMappings.map( ( mapping ) => vmMap.get( mapping.productId.toString() ) || {} );
977
1004
 
@@ -1669,8 +1696,7 @@ export async function updateMissing( req, res ) {
1669
1696
 
1670
1697
  export async function bulkFixtureUpload( req, res ) {
1671
1698
  try {
1672
- console.log( req.body.id );
1673
- const fixture = await storeFixtureService.findOne( { _id: new mongoose.Types.ObjectId( '' ) } );
1699
+ const fixture = await storeFixtureService.findOne( { _id: new mongoose.Types.ObjectId( req.body.id ) } );
1674
1700
 
1675
1701
  console.log( fixture );
1676
1702
 
@@ -1901,6 +1927,15 @@ export async function storeFixturesTask( req, res ) {
1901
1927
 
1902
1928
  const fixturesWithStatus = await Promise.all(
1903
1929
  fixtures.map( async ( fixture ) => {
1930
+ if ( fixture?.imageUrl ) {
1931
+ let params = {
1932
+ Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
1933
+ file_path: fixture.imageUrl,
1934
+ };
1935
+ fixture.imageUrl = await signedUrl( params );
1936
+ } else {
1937
+ fixture.imageUrl = '';
1938
+ }
1904
1939
  const productCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'product' } );
1905
1940
 
1906
1941
  const vmCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'vm' } );
@@ -1959,6 +1994,15 @@ export async function storeFixturesTask( req, res ) {
1959
1994
 
1960
1995
  const centerFixturesWithStatus = await Promise.all(
1961
1996
  centerFixtures.map( async ( fixture ) => {
1997
+ if ( fixture?.imageUrl ) {
1998
+ let params = {
1999
+ Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
2000
+ file_path: fixture.imageUrl,
2001
+ };
2002
+ fixture.imageUrl = await signedUrl( params );
2003
+ } else {
2004
+ fixture.imageUrl = '';
2005
+ }
1962
2006
  const productCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'product' } );
1963
2007
 
1964
2008
  const vmCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'vm' } );
@@ -2027,3 +2071,68 @@ export async function storeFixturesTask( req, res ) {
2027
2071
  return res.sendError( e, 500 );
2028
2072
  }
2029
2073
  }
2074
+
2075
+
2076
+ export const qrVideoUpload = async ( req, res ) => {
2077
+ try {
2078
+ if ( !req.files?.file ) {
2079
+ return res.sendError( { message: 'Please upload a file' }, 400 );
2080
+ }
2081
+
2082
+ const { file } = req.files;
2083
+ const { fixtureId } = req.body;
2084
+
2085
+ if ( !fixtureId ) {
2086
+ return res.sendError( { message: 'Missing fixtureId' }, 400 );
2087
+ }
2088
+
2089
+ const format = path.extname( file.name ).toLowerCase().replace( '.', '' );
2090
+ file.name = file.name.replace( /\s/g, '' );
2091
+
2092
+ const bucket = JSON.parse( process.env.BUCKET || '{}' );
2093
+ if ( !bucket.storeBuilder ) {
2094
+ return res.sendError( { message: 'Storage bucket not configured' }, 500 );
2095
+ }
2096
+
2097
+ const uploadPath = 'planoQrVideos';
2098
+
2099
+ const params = {
2100
+ fileName: `/${fixtureId}.${format}`,
2101
+ Key: uploadPath,
2102
+ Bucket: bucket.storeBuilder,
2103
+ ContentType: file.mimetype,
2104
+ body: file.data,
2105
+ };
2106
+
2107
+ const fileUrl = await fileUpload( params );
2108
+
2109
+ const message = {
2110
+ 'fixtureId': fixtureId,
2111
+ 'date': dayjs().format( 'YYYY-MM-DD' ),
2112
+ 'bucket': bucket.storeBuilder,
2113
+ 'videoPath': fileUrl.Key,
2114
+ };
2115
+
2116
+ const sqs = JSON.parse( process.env.SQS || '{}' );
2117
+ if ( !sqs.url || !sqs.highcountTopic ) {
2118
+ return res.sendError( { message: 'SQS details not configured' }, 500 );
2119
+ }
2120
+
2121
+ let inputData = {
2122
+ Bucket: bucket.storeBuilder,
2123
+ file_path: fileUrl.Key,
2124
+ };
2125
+ const imgUrl = await signedUrl( inputData );
2126
+ if ( !imgUrl ) {
2127
+ return res.sendError( { message: 'Something went Wrong' }, 500 );
2128
+ }
2129
+
2130
+ const sqsPush = await sendMessageToQueue( `${sqs.url}${sqs.qrVideoTopic}`, JSON.stringify( message ) );
2131
+
2132
+ return res.sendSuccess( { message: 'Uploaded successfully', sqsPush } );
2133
+ } catch ( error ) {
2134
+ logger.error( 'uploadFixtureVideo =>', error );
2135
+ return res.sendError( { message: 'Internal Server Error' }, 500 );
2136
+ }
2137
+ };
2138
+
@@ -287,8 +287,7 @@ export async function updateStatus( req, res ) {
287
287
  if ( !taskDetails ) {
288
288
  return res.sendError( 'No data found', 204 );
289
289
  }
290
- taskDetails.checklistStatus = req.body.status;
291
- taskDetails.save();
290
+ await processedService.updateOne( { _id: req.body.taskId }, { checklistStatus: req.body.status } );
292
291
  return res.sendSuccess( 'Task status updated successfully' );
293
292
  } catch ( e ) {
294
293
  logger.error( { functionName: 'storeLayout', error: e } );
@@ -27,6 +27,7 @@ storeBuilderRouter
27
27
  .post( '/updateMissing', storeBuilderController.updateMissing )
28
28
  .post( '/bulkFixtureUpload', storeBuilderController.bulkFixtureUpload )
29
29
  .post( '/uploadImage', storeBuilderController.uploadImage )
30
- .post( '/storeFixturesTask', storeBuilderController.storeFixturesTask );
30
+ .post( '/storeFixturesTask', storeBuilderController.storeFixturesTask )
31
+ .post( '/qrVideoUpload', storeBuilderController.qrVideoUpload );
31
32
 
32
33
 
@@ -8,6 +8,10 @@ export async function findOne( query = {}, field = {} ) {
8
8
  return model.taskProcessedModel.findOne( query, field );
9
9
  }
10
10
 
11
+ export async function updateOne( query = {}, record = {} ) {
12
+ return model.taskProcessedModel.updateOne( query, { $set: record } );
13
+ }
14
+
11
15
  export async function find( query = {}, field = {} ) {
12
16
  return model.taskProcessedModel.find( query, field );
13
17
  }