Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/components/FeaturedProduct.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class FeaturedProduct extends Component {
loading: true
}
}
// OB/LM: you can do
/*
state = {products: [], loading: true}
*/

async componentDidMount() {
try {
Expand Down
1 change: 1 addition & 0 deletions client/components/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from 'semantic-ui-react'
import {NavLink} from 'react-router-dom'

// OB/LM: listen to linter
const getWidth = () => {
const isSSR = typeof window === 'undefined'

Expand Down
1 change: 1 addition & 0 deletions client/components/ProductCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import axios from 'axios'
import {Button, Icon, Item, Label} from 'semantic-ui-react'
import ReactHtmlParser from 'react-html-parser'

// OB/LM: could make for a good test (especially if you separate out the local storage stuff)
const addToCart = async (product, setCartSize, user) => {
const currentItems = JSON.parse(localStorage.getItem('cart'))

Expand Down
2 changes: 2 additions & 0 deletions client/components/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Profile extends React.Component {
key: orderNumber,
title: orderNumber,
content: {
// Maybe could be <OrderTable {...} />
content: orderTable(order.id, products, totalPrice)
}
}
Expand Down Expand Up @@ -86,6 +87,7 @@ const orderTable = (id, products, totalPrice) => {
</Table.Row>
</Table.Header>
<Table.Body>
{/* OB/LM: maybe group by product id before mapping */}
{products.map((product, idx) => {
totalPrice += product.price
return (
Expand Down
1 change: 1 addition & 0 deletions client/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import user from './user'
import cart from './cart'
import checkout from './checkout'

// OB/LM: redux middleware for persisting cart to `localStorage` (could help reduce "multiple update" issues)
const reducer = combineReducers({user, cart, checkout})
const middleware = composeWithDevTools(
applyMiddleware(thunkMiddleware, createLogger({collapsed: true}))
Expand Down
1 change: 1 addition & 0 deletions server/api/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const paymentApi = app => {
})

app.post('/', (req, res) => {
// OB/LM: client can define charge amount (not good), sanitize the request body (recommend util method for this)
stripe.charges.create(req.body, postStripeCharge(res))
})

Expand Down
5 changes: 5 additions & 0 deletions server/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ router.get('/', async (req, res, next) => {
next(err)
}
}
// OB/LM: missing else
})

// GET api/users/:id
Expand Down Expand Up @@ -69,8 +70,10 @@ router.put('/:id/cart', checkUser, async (req, res, next) => {
orderData: req.body.products,
completed: !!req.body.completed
})
// OB/LM: consider moving the innards of the POST logic below to here (detect if a new cart needs to be made and make it)
res.sendStatus(201)
} catch (error) {
// OB/LM: firewood here, burn it
console.log('PUT CART ERROR')
next(error)
}
Expand All @@ -93,8 +96,10 @@ router.post('/:id/cart', checkUser, async (req, res, next) => {
// POST /api/users/guestCheckout
// saves a completed guest order in DB with userId null

// OB/LM: could be a POST /api/orders instead (more RESTful)
router.post('/guestCheckout', async (req, res, next) => {
try {
// OB/LM: web security issue, client can define the price of the order, maybe you want a method to calculate it
await Order.create(req.body)
res.sendStatus(201)
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions server/db/models/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const Order = db.define(
},
{
hooks: {
// OB/LM: recommend a setter method instead of a hook
beforeValidate: function(order) {
if (typeof order.orderData !== 'string') {
order.orderData = JSON.stringify(order.orderData)
Expand Down