fix: add default relations to variants to include prices (#394)
This commit is contained in:
committed by
GitHub
parent
167a9f45c7
commit
d477ca9842
@@ -1,3 +1,5 @@
|
||||
import { defaultRelations } from "."
|
||||
|
||||
/**
|
||||
* @oas [get] /variants/{variant_id}
|
||||
* operationId: GetVariantsVariant
|
||||
@@ -22,7 +24,10 @@ export default async (req, res) => {
|
||||
|
||||
try {
|
||||
const variantService = req.scope.resolve("productVariantService")
|
||||
let variant = await variantService.retrieve(id, { relations: ["prices"] })
|
||||
let variant = await variantService.retrieve(id, {
|
||||
relations: defaultRelations,
|
||||
})
|
||||
|
||||
res.json({ variant })
|
||||
} catch (error) {
|
||||
throw error
|
||||
|
||||
@@ -11,3 +11,5 @@ export default app => {
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
export const defaultRelations = ["prices"]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { defaultRelations } from "."
|
||||
|
||||
/**
|
||||
* @oas [get] /variants
|
||||
* operationId: GetVariants
|
||||
@@ -23,10 +25,14 @@ export default async (req, res) => {
|
||||
const limit = parseInt(req.query.limit) || 100
|
||||
const offset = parseInt(req.query.offset) || 0
|
||||
|
||||
let selector = {}
|
||||
let expandFields = []
|
||||
if ("expand" in req.query) {
|
||||
expandFields = req.query.expand.split(",")
|
||||
}
|
||||
|
||||
let selector = {}
|
||||
const listConfig = {
|
||||
relations: [],
|
||||
relations: expandFields.length ? expandFields : defaultRelations,
|
||||
skip: offset,
|
||||
take: limit,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user