Skip to content

Commit e0497f7

Browse files
chg: refactor and reformat code for logistics selection
1 parent da1aab1 commit e0497f7

File tree

33 files changed

+297
-186
lines changed

33 files changed

+297
-186
lines changed

notifications/app/lib/mailer/emails/org-admin-user/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ForgotPassword extends Email {
2121

2222
let user = this.options.data.data.user;
2323

24-
console.log("org admin user detals -->",this.options.data.data)
24+
console.log('org admin user detals -->',this.options.data.data);
2525
let name = user.name;
2626

2727
return {

notifications/app/lib/mailer/mailer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Mailer {
1616
user: mergedEnvironmentConfig.email.transport.auth.user, // sender's email id
1717
pass: mergedEnvironmentConfig.email.transport.auth.pass,
1818
},
19-
}
19+
};
2020
this.sender = sender || mergedEnvironmentConfig.email.sender;
2121
this.transport = nodemailer.createTransport(transport);
2222
this.emailTemplate = new EmailTemplate({

notifications/app/lib/utils/HttpRequest.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class HttpRequest {
2020
this.data = data;
2121
this.headers = headers;
2222
this.options = options;
23-
};
23+
}
2424

2525
/**
2626
* Send http request to server to write data to / read data from server
@@ -61,7 +61,7 @@ class HttpRequest {
6161
reject(err);
6262
}
6363
});
64-
};
64+
}
6565
}
6666

6767
export default HttpRequest;

notifications/app/server.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ server.on('error', (error) => {
4545

4646
// handle specific listen errors with friendly messages
4747
switch (error.code) {
48-
case 'EACCES':
49-
console.error(`${bind} requires elevated privileges`);
50-
process.exit(1);
51-
break;
52-
case 'EADDRINUSE':
53-
console.error(`${bind} is already in use`);
54-
process.exit(1);
55-
break;
56-
default:
57-
throw error;
48+
case 'EACCES':
49+
console.error(`${bind} requires elevated privileges`);
50+
process.exit(1);
51+
break;
52+
case 'EADDRINUSE':
53+
console.error(`${bind} is already in use`);
54+
process.exit(1);
55+
break;
56+
default:
57+
throw error;
5858
}
5959
});
6060

@@ -114,7 +114,7 @@ const corsOptionsDelegate = function (req, callback) {
114114
// Wait for the DB connection to setup and initialize the DB models
115115

116116
// Resgister routes once the DB models are registered
117-
app.use(`/api`, cors(corsOptionsDelegate) ,routes);
117+
app.use('/api', cors(corsOptionsDelegate) ,routes);
118118
const routeDetails = getRoutes(app);
119119
console.log('Registered API paths are: \n', routeDetails);
120120
console.log('Registered API paths are: \n', mergedEnvironmentConfig);

notifications/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
"start": "nodemon --exec babel-node ./app/server.js --trace-deprecation",
1010
"cron": "nodemon --exec babel-node ./bin/cron.js",
1111
"build": "npx babel . --out-dir dist --ignore \"node_modules/*\" --copy-files",
12-
"dropall": "babel-node ./bin/dropAllDbs.js",
1312
"serve": "node ./dist/bin/www",
14-
"prepare": "cd .. && husky install",
15-
"pretest": "cross-env NODE_ENV=test npm run dropall",
16-
"test": "cross-env NODE_ENV=test nyc --reporter text-summary --reporter json-summary --reporter json --reporter cobertura --reporter lcov mocha --require @babel/register --timeout 10000"
13+
"prepare": "cd .. && husky install"
1714
},
1815
"dependencies": {
1916
"@jsreport/jsreport-chrome-pdf": "^3.1.0",

seller-app-api/package.json

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
2-
"name": "pshiny",
3-
"version": "0.0.0",
4-
"private": true,
2+
"name": "seller-api",
3+
"version": "2.0",
4+
"description": "ONDC",
5+
"main": "index.js",
6+
"author": "ONDC",
7+
"license": "ONDC",
58
"scripts": {
69
"start": "nodemon --exec babel-node ./bin/www",
710
"build": "npx babel . --out-dir dist --ignore \"node_modules/*\" --copy-files",
811
"serve": "node ./dist/bin/www"
912
},
1013
"dependencies": {
1114
"@hapi/joi": "^17.1.1",
12-
"aws-cloudfront-sign": "^2.2.0",
1315
"aws-sdk": "^2.860.0",
1416
"axios": "^0.19.0",
1517
"bcryptjs": "^2.4.3",
@@ -22,14 +24,11 @@
2224
"express": "~4.16.0",
2325
"firebase-admin": "^11.0.1",
2426
"fs": "0.0.1-security",
25-
"ioredis": "^4.28.4",
2627
"ip": "^1.1.5",
2728
"jsonwebtoken": "^8.4.0",
2829
"lodash": "^4.17.11",
2930
"moment": "^2.24.0",
3031
"morgan": "~1.9.0",
31-
"msg91": "0.0.6",
32-
"msg91-api": "^1.0.9",
3332
"mysql": "^2.17.1",
3433
"mysql2": "^1.6.5",
3534
"nconf": "^0.10.0",
@@ -56,5 +55,11 @@
5655
"@babel/preset-env": "^7.9.6",
5756
"js-beautify": "^1.8.9",
5857
"nodemon": "^1.18.9"
58+
},
59+
"engines": {
60+
"node": ">=16.0.0"
61+
},
62+
"lint-staged": {
63+
"*.js": "eslint --cache --fix"
5964
}
6065
}

seller-app-api/services/ondc.service.js

+19-27
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,11 @@ class OndcService {
442442
const initMessageId = payload.context.message_id;
443443
const logisticsMessageId = uuidv4(); //TODO: in future this is going to be array as packaging for single select request can be more than one
444444
const contextTimeStamp =new Date()
445+
446+
447+
let deliveryType = logistics.message.catalog["bpp/providers"][0].items.find((element)=>{return element.category_id === 'Next Day Delivery'});
448+
449+
445450
const initRequest = {
446451
"context": {
447452
"domain": "nic2004:60232",
@@ -463,7 +468,7 @@ class OndcService {
463468
"provider": {
464469
"id": logistics.message.catalog["bpp/providers"][0].id
465470
},
466-
"items": [logistics.message.catalog["bpp/providers"][0].items[0]],
471+
"items": [deliveryType],
467472
"fulfillments": [{
468473
"id": logistics.message.catalog["bpp/fulfillments"][0].id,
469474
"type": logistics.message.catalog["bpp/fulfillments"][0].type,
@@ -810,6 +815,9 @@ class OndcService {
810815
itemDetails.push(details)
811816
}
812817

818+
819+
let deliveryType = selectRequest.selectedLogistics.message.catalog['bpp/providers'][0].items.find((element)=>{return element.category_id === 'Next Day Delivery'});
820+
813821
const contextTimestamp = new Date()
814822
const confirmRequest = {
815823
"context": {
@@ -832,16 +840,16 @@ class OndcService {
832840
"items": itemDetails,
833841
"provider": {
834842
"descriptor": {
835-
"name": "Spice 9" //TODO: take details from seller service
843+
name: org.providerDetail.name
836844
},
837845
"address": {
838-
"name": "Spice 9",
839-
"building": "12",
840-
"locality": "prashanth nagar",
841-
"city": "Bangalore",
842-
"state": "Karnataka",
843-
"country": "IND",
844-
"area_code": "560036"
846+
area_code: org.providerDetail.storeDetails.address.area_code,
847+
name: org.providerDetail.name,
848+
building: org.providerDetail.storeDetails.address.building,
849+
locality: org.providerDetail.storeDetails.address.locality,
850+
city: org.providerDetail.storeDetails.address.city,
851+
state: org.providerDetail.storeDetails.address.state,
852+
country: org.providerDetail.storeDetails.address.country
845853
}
846854
},
847855
"order": {
@@ -853,7 +861,7 @@ class OndcService {
853861
}
854862
},
855863
"id": order.id,
856-
"items": [selectRequest.selectedLogistics.message.catalog['bpp/providers'][0].items[0]], //TODO: fix this map to right item id from select request
864+
"items": [deliveryType], //TODO: fix this map to right item id from select request
857865
"provider":initRequest.selectedLogistics.message.order.provider,
858866
"fulfillments": [{
859867
"id": order.fulfillments[0].id,
@@ -870,23 +878,7 @@ class OndcService {
870878
"collected_by": "BAP",
871879
"@ondc/org/settlement_details": []
872880
},
873-
"billing": { //TODO: hard coded
874-
"name": "Ek Second Technologies",
875-
"email": "[email protected]",
876-
"phone": "9000111111",
877-
"created_at": contextTimestamp,
878-
"updated_at": contextTimestamp,
879-
"address": {
880-
"name": "ONDC",
881-
"building": "8-7-171/10/14/B",
882-
"locality": "Old Bowenpally",
883-
"city": "secunderabad",
884-
"state": "Telangana",
885-
"country": "India",
886-
"area_code": "500011"
887-
},
888-
"tax_number": "ADFSDF34343"
889-
},
881+
"billing": {...payload.message.order.billing,"tax_number": "NA"},
890882
state: "Created",
891883
created_at:contextTimestamp,
892884
updated_at:contextTimestamp

seller-app-api/services/product.service.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -1263,29 +1263,34 @@ class ProductService {
12631263

12641264
let deliveryCharges ={}
12651265
let fulfillments =[]
1266-
if(isServiceable){
1266+
1267+
let deliveryType = logisticProvider.message.catalog["bpp/providers"][0].items.find((element)=>{return element.category_id === 'Next Day Delivery'});
1268+
1269+
console.log("deliveryType--logisticProvider.message.catalog[\"bpp/providers\"][0].items->",logisticProvider.message.catalog["bpp/providers"][0].items);
1270+
console.log("deliveryType--->",deliveryType);
1271+
if(isServiceable && deliveryType ){
12671272
//select logistic based on criteria-> for now first one will be picked up
12681273
deliveryCharges = {
12691274
"title": "Delivery charges",
12701275
"@ondc/org/title_type": "delivery",
1271-
"@ondc/org/item_id":logisticProvider.message.catalog["bpp/providers"][0].items[0].fulfillment_id,
1276+
"@ondc/org/item_id":deliveryType.fulfillment_id,
12721277
"price": {
1273-
"currency": '' + logisticProvider.message.catalog["bpp/providers"][0].items[0].price.currency,
1274-
"value": '' + logisticProvider.message.catalog["bpp/providers"][0].items[0].price.value
1278+
"currency": '' + deliveryType.price.currency,
1279+
"value": '' + deliveryType.price.value
12751280
}
12761281
}//TODO: need to map all items in the catalog to find out delivery charges
12771282

1278-
12791283
//added delivery charges in total price
12801284
totalPrice += parseInt(logisticProvider.message.catalog["bpp/providers"][0].items[0].price.value)
12811285

12821286
fulfillments = [
1287+
12831288
{
1284-
"id": logisticProvider.message.catalog["bpp/providers"][0].items[0].fulfillment_id, //TODO: check what needs to go here, ideally it should be item id
1289+
"id": deliveryType.fulfillment_id, //TODO: check what needs to go here, ideally it should be item id
12851290
"@ondc/org/provider_name": logisticProvider.message.catalog["bpp/descriptor"].name,
12861291
"tracking": true, //Hard coded
1287-
"@ondc/org/category": logisticProvider.message.catalog["bpp/providers"][0].items[0].category_id,
1288-
"@ondc/org/TAT": logisticProvider.message.catalog["bpp/providers"][0].items[0].time.duration,
1292+
"@ondc/org/category": deliveryType.category_id,
1293+
"@ondc/org/TAT": deliveryType.time.duration,
12891294
"state":
12901295
{
12911296
"descriptor":

0 commit comments

Comments
 (0)