-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
delete functionality working with db and click events
- Loading branch information
1 parent
efe5fb3
commit 7e8e391
Showing
6 changed files
with
71 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -1,9 +1,30 @@ | ||
import Product from '../../models/Product'; | ||
|
||
|
||
export default async (req, res) => { | ||
switch (req.method) { | ||
case "GET": | ||
await handleGetRequest(req, res); | ||
break; | ||
case "DELETE": | ||
await handleDeleteRequest(req, res); | ||
break; | ||
default: | ||
//405 no method provided | ||
res.status(405).send(`Method ${req.method} not allowed`); | ||
break; | ||
} | ||
} | ||
|
||
async function handleGetRequest(req, res) { | ||
const {_id} = req.query; | ||
const product = await Product.findOne({_id}); | ||
res.status(200).json(product); | ||
} | ||
|
||
|
||
async function handleDeleteRequest(req, res) { | ||
const {_id} = req.query; | ||
const product = await Product.findOneAndDelete({_id}); | ||
//204 no content | ||
res.status(204).json({}); | ||
} |
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 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,5 @@ | ||
const baseUrl = | ||
process.env.NODE_ENV === 'production' ? "https://deployment-url.now.sh" : "http://localhost:3000"; | ||
|
||
|
||
export default baseUrl; |