Add orders to account
This commit is contained in:
@@ -35,14 +35,11 @@ export default async (req, res) => {
|
||||
}
|
||||
)
|
||||
|
||||
const data = await customerService.decorate(result.customer, [
|
||||
"_id",
|
||||
"email",
|
||||
"orders",
|
||||
"shipping_addresses",
|
||||
"first_name",
|
||||
"last_name",
|
||||
])
|
||||
const data = await customerService.decorate(
|
||||
result.customer,
|
||||
["_id", "email", "orders", "shipping_addresses", "first_name", "last_name"],
|
||||
["orders"]
|
||||
)
|
||||
|
||||
res.json({ customer: data })
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ export default async (req, res) => {
|
||||
try {
|
||||
const customerService = req.scope.resolve("customerService")
|
||||
let customer = await customerService.retrieve(id)
|
||||
customer = customerService.decorate(customer._id, [
|
||||
"email",
|
||||
"first_name",
|
||||
"last_name",
|
||||
])
|
||||
customer = customerService.decorate(
|
||||
customer._id,
|
||||
["email", "first_name", "last_name", "shipping_addresses"],
|
||||
["orders"]
|
||||
)
|
||||
res.json({ customer })
|
||||
} catch (err) {
|
||||
throw err
|
||||
|
||||
@@ -288,7 +288,10 @@ class CustomerService extends BaseService {
|
||||
|
||||
if (expandFields.includes("orders")) {
|
||||
decorated.orders = await Promise.all(
|
||||
customer.orders.map(async o => this.orderService_.retrieve(o))
|
||||
customer.orders.map(async o => {
|
||||
const order = await this.orderService_.retrieve(o)
|
||||
return this.orderService_.decorate(order)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user