Add orders to account

This commit is contained in:
Sebastian Rindom
2020-07-13 10:58:03 +02:00
parent 518bc95f70
commit eeae2a056c
3 changed files with 14 additions and 14 deletions
@@ -35,14 +35,11 @@ export default async (req, res) => {
} }
) )
const data = await customerService.decorate(result.customer, [ const data = await customerService.decorate(
"_id", result.customer,
"email", ["_id", "email", "orders", "shipping_addresses", "first_name", "last_name"],
"orders", ["orders"]
"shipping_addresses", )
"first_name",
"last_name",
])
res.json({ customer: data }) res.json({ customer: data })
} }
@@ -3,11 +3,11 @@ export default async (req, res) => {
try { try {
const customerService = req.scope.resolve("customerService") const customerService = req.scope.resolve("customerService")
let customer = await customerService.retrieve(id) let customer = await customerService.retrieve(id)
customer = customerService.decorate(customer._id, [ customer = customerService.decorate(
"email", customer._id,
"first_name", ["email", "first_name", "last_name", "shipping_addresses"],
"last_name", ["orders"]
]) )
res.json({ customer }) res.json({ customer })
} catch (err) { } catch (err) {
throw err throw err
+4 -1
View File
@@ -288,7 +288,10 @@ class CustomerService extends BaseService {
if (expandFields.includes("orders")) { if (expandFields.includes("orders")) {
decorated.orders = await Promise.all( 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)
})
) )
} }