forked from basir/next-amazona
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
142 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import nc from 'next-connect'; | ||
import { isAdmin, isAuth } from '../../../../utils/auth'; | ||
import Product from '../../../../models/Product'; | ||
import db from '../../../../utils/db'; | ||
|
||
const handler = nc(); | ||
handler.use(isAuth, isAdmin); | ||
|
||
handler.get(async (req, res) => { | ||
await db.connect(); | ||
const products = await Product.find({}); | ||
await db.disconnect(); | ||
res.send(products); | ||
}); | ||
|
||
handler.post(async (req, res) => { | ||
await db.connect(); | ||
const newProduct = new Product({ | ||
name: 'sample name', | ||
slug: 'sample-slug-' + Math.random(), | ||
image: '/images/shirt1.jpg', | ||
price: 0, | ||
category: 'sample category', | ||
brand: 'sample brand', | ||
countInStock: 0, | ||
description: 'sample description', | ||
rating: 0, | ||
numReviews: 0, | ||
}); | ||
|
||
const product = await newProduct.save(); | ||
await db.disconnect(); | ||
res.send({ message: 'Product Created', product }); | ||
}); | ||
|
||
export default handler; |