Skip to content

Commit

Permalink
feat: enable retry for addItem and add more debug info
Browse files Browse the repository at this point in the history
Signed-off-by: Raymond Feng <[email protected]>
  • Loading branch information
raymondfeng committed Sep 21, 2018
1 parent ec06800 commit 44f163a
Show file tree
Hide file tree
Showing 7 changed files with 417 additions and 28 deletions.
169 changes: 166 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@loopback/repository": "^0.16.5",
"@loopback/rest": "^0.22.2",
"bcryptjs": "^2.4.3",
"debug": "^4.0.1",
"isemail": "^3.1.3",
"loopback-connector-kv-redis": "^3.0.0",
"loopback-connector-mongodb": "^3.7.1"
Expand All @@ -71,6 +72,7 @@
"@loopback/build": "^0.7.3",
"@loopback/testlab": "^0.12.2",
"@types/bcryptjs": "^2.4.1",
"@types/debug": "0.0.30",
"@types/mocha": "^5.0.0",
"@types/node": "^10.9.4",
"commitizen": "^2.10.1",
Expand Down
9 changes: 8 additions & 1 deletion src/controllers/shopping-cart.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
import {repository} from '@loopback/repository';
import {ShoppingCartRepository} from '../repositories';
import {ShoppingCart, ShoppingCartItem} from '../models';
import * as debugFactory from 'debug';
const debug = debugFactory('loopback:example:shopping');

/**
* Controller for shopping cart
Expand All @@ -35,6 +37,7 @@ export class ShoppingCartController {
@param.path.string('userId') userId: string,
@requestBody({description: 'shopping cart'}) cart: ShoppingCart,
) {
debug('Create shopping cart %s: %j', userId, cart);
if (userId !== cart.userId) {
throw new HttpErrors.BadRequest(
`User id does not match: ${userId} !== ${cart.userId}`,
Expand All @@ -49,7 +52,9 @@ export class ShoppingCartController {
*/
@get('/shoppingCarts/{userId}')
async get(@param.path.string('userId') userId: string) {
debug('Get shopping cart %s', userId);
const cart = await this.shoppingCartRepository.get(userId);
debug('Shopping cart %s: %j', userId, cart);
if (cart == null) {
throw new HttpErrors.NotFound(
`Shopping cart not found for user: ${userId}`,
Expand All @@ -65,6 +70,7 @@ export class ShoppingCartController {
*/
@del('/shoppingCarts/{userId}')
async remove(@param.path.string('userId') userId: string) {
debug('Remove shopping cart %s', userId);
await this.shoppingCartRepository.delete(userId);
}

Expand All @@ -78,6 +84,7 @@ export class ShoppingCartController {
@param.path.string('userId') userId: string,
@requestBody({description: 'shopping cart item'}) item: ShoppingCartItem,
) {
await this.shoppingCartRepository.addItem(userId, item);
debug('Add item %j to shopping cart %s', item, userId);
return this.shoppingCartRepository.addItem(userId, item);
}
}
Loading

0 comments on commit 44f163a

Please sign in to comment.