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