|
|
|
@ -6,7 +6,6 @@ const productRoutes = (app: express.Application) => {
|
|
|
|
|
app.get('/products/:id', show)
|
|
|
|
|
app.post('/products', create)
|
|
|
|
|
app.delete('/products/:id', destroy)
|
|
|
|
|
app.post('/products/:id/')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const store = new ProductStore()
|
|
|
|
@ -25,10 +24,8 @@ const create = async (req: Request, res: Response) => {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const productInfo: Product = {
|
|
|
|
|
title: request.body.title,
|
|
|
|
|
author: request.body.author,
|
|
|
|
|
pages: request.body.pages,
|
|
|
|
|
price: request.body.price
|
|
|
|
|
name: request.body.name,
|
|
|
|
|
price: request.body.price,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const newProduct = await store.create(productInfo);
|
|
|
|
@ -44,10 +41,8 @@ const update = async (req: Request, res: Response) => {
|
|
|
|
|
try {
|
|
|
|
|
const product = await store.update(req.body);
|
|
|
|
|
res.json({
|
|
|
|
|
title: request.body.title,
|
|
|
|
|
author: request.body.author,
|
|
|
|
|
pages: request.body.pages,
|
|
|
|
|
price: request.body.price
|
|
|
|
|
name: request.body.name,
|
|
|
|
|
price: request.body.price,
|
|
|
|
|
})
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw new Error(`Can't update product. ${err}`)
|
|
|
|
|