tango-app-api-store-builder 1.0.0-beta-29 → 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-29",
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' } );
@@ -1916,6 +1927,15 @@ export async function storeFixturesTask( req, res ) {
1916
1927
 
1917
1928
  const fixturesWithStatus = await Promise.all(
1918
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
+ }
1919
1939
  const productCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'product' } );
1920
1940
 
1921
1941
  const vmCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'vm' } );
@@ -1974,6 +1994,15 @@ export async function storeFixturesTask( req, res ) {
1974
1994
 
1975
1995
  const centerFixturesWithStatus = await Promise.all(
1976
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
+ }
1977
2006
  const productCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'product' } );
1978
2007
 
1979
2008
  const vmCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'vm' } );
@@ -2042,3 +2071,68 @@ export async function storeFixturesTask( req, res ) {
2042
2071
  return res.sendError( e, 500 );
2043
2072
  }
2044
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
+
@@ -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