Fix lint
This commit is contained in:
parent
70e4d4aec3
commit
18d0810580
5 changed files with 48 additions and 41 deletions
|
@ -2,7 +2,11 @@
|
||||||
"name": "grpc-currency-service",
|
"name": "grpc-currency-service",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "A gRPC currency conversion microservice",
|
"description": "A gRPC currency conversion microservice",
|
||||||
"repository": "TODO",
|
"repository": "https://github.com/GoogleCloudPlatform/microservices-demo",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"lint": "semistandard *.js"
|
||||||
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@google-cloud/debug-agent": "^2.6.0",
|
"@google-cloud/debug-agent": "^2.6.0",
|
||||||
|
@ -15,5 +19,8 @@
|
||||||
"left-pad": "^1.3.0",
|
"left-pad": "^1.3.0",
|
||||||
"request": "^2.87.0",
|
"request": "^2.87.0",
|
||||||
"xml2js": "^0.4.19"
|
"xml2js": "^0.4.19"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"semistandard": "^12.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,28 +52,23 @@ module.exports = function charge(request) {
|
||||||
const cardInfo = cardValidator(cardNumber);
|
const cardInfo = cardValidator(cardNumber);
|
||||||
const {
|
const {
|
||||||
card_type: cardType,
|
card_type: cardType,
|
||||||
valid,
|
valid
|
||||||
cvv_length: cvvLength,
|
|
||||||
} = cardInfo.getCardDetails();
|
} = cardInfo.getCardDetails();
|
||||||
|
|
||||||
if (!valid)
|
if (!valid) { throw new InvalidCreditCard(); }
|
||||||
throw new InvalidCreditCard();
|
|
||||||
|
|
||||||
// Only VISA and mastercard is accepted, other card types (AMEX, dinersclub) will
|
// Only VISA and mastercard is accepted, other card types (AMEX, dinersclub) will
|
||||||
// throw UnacceptedCreditCard error.
|
// throw UnacceptedCreditCard error.
|
||||||
if (!(cardType === 'visa' || cardType == 'mastercard'))
|
if (!(cardType === 'visa' || cardType === 'mastercard')) { throw new UnacceptedCreditCard(cardType); }
|
||||||
throw new UnacceptedCreditCard(cardType);
|
|
||||||
|
|
||||||
// Also validate expiration is > today.
|
// Also validate expiration is > today.
|
||||||
const currentMonth = new Date().getMonth() + 1;
|
const currentMonth = new Date().getMonth() + 1;
|
||||||
const currentYear = new Date().getFullYear();
|
const currentYear = new Date().getFullYear();
|
||||||
const { credit_card_expiration_year: year, credit_card_expiration_month: month } = creditCard;
|
const { credit_card_expiration_year: year, credit_card_expiration_month: month } = creditCard;
|
||||||
if ((currentYear * 12 + currentMonth) > (year * 12 + month))
|
if ((currentYear * 12 + currentMonth) > (year * 12 + month)) { throw new ExpiredCreditCard(cardNumber.replace('-', ''), month, year); }
|
||||||
throw new ExpiredCreditCard(cardNumber.replace('-', ''), month, year);
|
|
||||||
|
|
||||||
console.log(`Transaction processed: ${cardType} ending ${cardNumber.substr(-4)} \
|
console.log(`Transaction processed: ${cardType} ending ${cardNumber.substr(-4)} \
|
||||||
Amount: ${amount.currency_code}${amount.units}.${amount.nanos}`)
|
Amount: ${amount.currency_code}${amount.units}.${amount.nanos}`);
|
||||||
|
|
||||||
return { transaction_id: uuid() }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return { transaction_id: uuid() };
|
||||||
|
};
|
||||||
|
|
|
@ -28,14 +28,14 @@ require('@google-cloud/debug-agent').start({
|
||||||
service: 'paymentservice',
|
service: 'paymentservice',
|
||||||
version: 'VERSION'
|
version: 'VERSION'
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
const HipsterShopServer = require('./server');
|
const HipsterShopServer = require('./server');
|
||||||
|
|
||||||
const PORT = process.env['PORT'];
|
const PORT = process.env['PORT'];
|
||||||
const PROTO_PATH = __dirname + '/proto/';
|
const PROTO_PATH = path.join(__dirname, '/proto/');
|
||||||
|
|
||||||
const server = new HipsterShopServer(PROTO_PATH, PORT);
|
const server = new HipsterShopServer(PROTO_PATH, PORT);
|
||||||
|
|
||||||
server.listen();
|
server.listen();
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
"name": "paymentservice",
|
"name": "paymentservice",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "Payment Microservice demo",
|
"description": "Payment Microservice demo",
|
||||||
|
"repository": "https://github.com/GoogleCloudPlatform/microservices-demo",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"lint": "semistandard *.js"
|
||||||
},
|
},
|
||||||
"author": "Jonathan Lui",
|
"author": "Jonathan Lui",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
@ -16,5 +18,8 @@
|
||||||
"grpc": "^1.12.3",
|
"grpc": "^1.12.3",
|
||||||
"simple-card-validator": "^1.1.0",
|
"simple-card-validator": "^1.1.0",
|
||||||
"uuid": "^3.2.1"
|
"uuid": "^3.2.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"semistandard": "^12.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,8 @@ class HipsterShopServer {
|
||||||
*/
|
*/
|
||||||
static ChargeServiceHandler (call, callback) {
|
static ChargeServiceHandler (call, callback) {
|
||||||
try {
|
try {
|
||||||
console.log(`PaymentService#Charge invoked with request ${JSON.stringify(call.request)}`)
|
console.log(`PaymentService#Charge invoked with request ${JSON.stringify(call.request)}`);
|
||||||
const response = charge(call.request)
|
const response = charge(call.request);
|
||||||
callback(null, response);
|
callback(null, response);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
|
@ -65,7 +65,7 @@ class HipsterShopServer {
|
||||||
longs: String,
|
longs: String,
|
||||||
enums: String,
|
enums: String,
|
||||||
defaults: true,
|
defaults: true,
|
||||||
oneofs: true,
|
oneofs: true
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return grpc.loadPackageDefinition(packageDefinition);
|
return grpc.loadPackageDefinition(packageDefinition);
|
||||||
|
@ -78,7 +78,7 @@ class HipsterShopServer {
|
||||||
this.server.addService(
|
this.server.addService(
|
||||||
hipsterShopPackage.PaymentService.service,
|
hipsterShopPackage.PaymentService.service,
|
||||||
{
|
{
|
||||||
charge: HipsterShopServer.ChargeServiceHandler.bind(this),
|
charge: HipsterShopServer.ChargeServiceHandler.bind(this)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue