fix pr request

This commit is contained in:
Vilfred Sikker committed 2021-08-27 15:59:50 +02:00
1 parent 5261999d12
commit 15594f9d31
2 files changed
+11 -17

No files matched your search

@@ -28,25 +28,21 @@ export default (rootDirectory) => {
decode = jwt.decode(token, JWT_SECRET) decode = jwt.decode(token, JWT_SECRET)
if (!decode || !decode.customer_id) { if (!decode || !decode.customer_id) {
throw new MedusaError( throw new MedusaError(MedusaError.Types.NOT_FOUND, "Invalid token")
MedusaError.Types.NOT_FOUND,
"Invalid token",
400
)
} }
} catch (err) { } catch (err) {
res.status(400).json(err) res.status(400).json({ message: err.message })
} }
try { try {
const customer = await customerService.retrieve(decode.customer_id) const customer = await customerService.retrieve(decode.customer_id)
const response = { const wishlist = {
wishlist: customer.metadata.wishlist, items: customer.metadata.wishlist,
first_name: customer.first_name, first_name: customer.first_name,
} }
res.status(200).json({ response }) res.status(200).json({ wishlist })
} catch (err) { } catch (err) {
res.status(400).json(err) res.status(400).json({ message: err.message })
} }
} }
) )
@@ -83,17 +83,15 @@ export default () => {
let customer = await customerService.retrieve(req.params.id) let customer = await customerService.retrieve(req.params.id)
// check customer exists else throw 404
if (!customer?.id) {
throw new MedusaError(Medusa.Types.NOT_FOUND, "not found", 404)
}
// check customer has wishlist else throw 400 bad request // check customer has wishlist else throw 400 bad request
if (!customer?.metadata?.wishlist) { if (!customer?.metadata?.wishlist) {
throw new MedusaError(Medusa.Types.INVALID_DATA, "invalid data", 400) throw new MedusaError(
Medusa.Types.INVALID_DATA,
"Invalid data - Customer doesn't have a wishlist"
)
} }
const token = await jwt.sign( const token = jwt.sign(
{ {
customer_id: customer.id, customer_id: customer.id,
}, },