fix: working api

This commit is contained in:
Sebastian Rindom
2021-04-06 15:01:13 +02:00
parent 2b2555004e
commit 9d810971a7
8 changed files with 86 additions and 49 deletions
@@ -1,7 +1,7 @@
import { Validator, MedusaError } from "medusa-core-utils"
export default async (req, res) => {
const { variant_id } = req.parmas
const { variant_id } = req.params
const schema = Validator.object().keys({
email: Validator.string().required(),
@@ -9,7 +9,8 @@ export default async (req, res) => {
const { value, error } = schema.validate(req.body)
if (error) {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
res.status(400).json({ message: error.message })
return
}
try {
@@ -19,6 +20,6 @@ export default async (req, res) => {
await restockNotificationService.addEmail(variant_id, value.email)
res.sendStatus(200)
} catch (err) {
res.sendStatus(400).json({ message: err.message })
res.status(400).json({ message: err.message })
}
}
@@ -9,7 +9,7 @@ export default (app) => {
route.post(
"/variants/:variant_id",
bodyParser.raw({ type: "application/json" }),
bodyParser.json(),
middlewares.wrap(require("./add-email").default)
)
return app