(feat): Adds phone number to Customer

This commit is contained in:
Oliver Windall Juhl
2020-09-09 16:55:34 +02:00
committed by GitHub
parent f0b602faf0
commit e3d8eea3cd
11 changed files with 125 additions and 19 deletions
@@ -8,6 +8,7 @@ export default async (req, res) => {
first_name: Validator.string().required(),
last_name: Validator.string().required(),
password: Validator.string().required(),
phone: Validator.string().optional(),
})
const { value, error } = schema.validate(req.body)
@@ -5,7 +5,13 @@ export default async (req, res) => {
let customer = await customerService.retrieve(id)
customer = await customerService.decorate(
customer,
["email", "payment_methods", "has_account", "shipping_addresses"],
[
"email",
"payment_methods",
"has_account",
"shipping_addresses",
"phone",
],
["orders"]
)
@@ -4,9 +4,10 @@ export default async (req, res) => {
const { id } = req.params
const schema = Validator.object().keys({
first_name: Validator.string(),
last_name: Validator.string(),
password: Validator.string(),
first_name: Validator.string().optional(),
last_name: Validator.string().optional(),
password: Validator.string().optional(),
phone: Validator.string().optional(),
})
const { value, error } = schema.validate(req.body)
@@ -10,6 +10,7 @@ export default async (req, res) => {
first_name: Validator.string().required(),
last_name: Validator.string().required(),
password: Validator.string().required(),
phone: Validator.string().optional(),
})
const { value, error } = schema.validate(req.body)
@@ -36,6 +37,7 @@ export default async (req, res) => {
"shipping_addresses",
"first_name",
"last_name",
"phone",
])
res.status(201).json({ customer: data })
} catch (err) {
@@ -5,7 +5,7 @@ export default async (req, res) => {
let customer = await customerService.retrieve(id)
customer = customerService.decorate(
customer,
["email", "first_name", "last_name", "shipping_addresses"],
["email", "first_name", "last_name", "shipping_addresses", "phone"],
["orders"]
)
res.json({ customer })
@@ -4,9 +4,10 @@ export default async (req, res) => {
const { id } = req.params
const schema = Validator.object().keys({
first_name: Validator.string(),
last_name: Validator.string(),
password: Validator.string(),
first_name: Validator.string().optional(),
last_name: Validator.string().optional(),
password: Validator.string().optional(),
phone: Validator.string().optional(),
})
const { value, error } = schema.validate(req.body)
@@ -19,7 +20,7 @@ export default async (req, res) => {
const customer = await customerService.update(id, value)
const data = await customerService.decorate(
customer,
["email", "first_name", "last_name", "shipping_addresses"],
["email", "first_name", "last_name", "shipping_addresses", "phone"],
["orders"]
)
res.status(200).json({ customer: data })