feat: add extend param for customer groups

This commit is contained in:
fPolic
2022-02-21 15:24:52 +01:00
committed by olivermrbl
parent 93d8e8036e
commit bf3e04f41a
3 changed files with 45 additions and 1 deletions
@@ -1,4 +1,7 @@
import { CustomerGroupService } from "../../../../services"
import { FindParams } from "../../../../types/common"
import { validator } from "../../../../utils/validator"
import { defaultAdminCustomerGroupsRelations } from "."
/**
* @oas [get] /customer-group/{id}
@@ -22,11 +25,25 @@ import { CustomerGroupService } from "../../../../services"
*/
export default async (req, res) => {
const { id } = req.params
const validated = await validator(FindParams, req.query)
const customerGroupService: CustomerGroupService = req.scope.resolve(
"customerGroupService"
)
const customerGroup = await customerGroupService.retrieve(id)
let expandFields: string[] = []
if (validated.expand) {
expandFields = validated.expand.split(",")
}
const findConfig = {
relations: expandFields.length
? expandFields
: defaultAdminCustomerGroupsRelations,
}
const customerGroup = await customerGroupService.retrieve(id, findConfig)
res.json({ customerGroup })
}
@@ -23,4 +23,6 @@ export type AdminCustomerGroupsListRes = PaginatedResponse & {
customer_groups: CustomerGroup[]
}
export const defaultAdminCustomerGroupsRelations = []
export * from "./create-customer-group"