feat: customer group update (#1098)
This commit is contained in:
@@ -20,8 +20,8 @@ import { validator } from "../../../../utils/validator"
|
||||
* application/json:
|
||||
* schema:
|
||||
* properties:
|
||||
* customerGroup:
|
||||
* $ref: "#/components/schemas/customergroup"
|
||||
* customer_group:
|
||||
* $ref: "#/components/schemas/customer_group"
|
||||
*/
|
||||
|
||||
export default async (req, res) => {
|
||||
@@ -32,7 +32,7 @@ export default async (req, res) => {
|
||||
)
|
||||
|
||||
const customerGroup = await customerGroupService.create(validated)
|
||||
res.status(200).json({ customerGroup })
|
||||
res.status(200).json({ customer_group: customerGroup })
|
||||
}
|
||||
|
||||
export class AdminPostCustomerGroupsReq {
|
||||
|
||||
@@ -20,13 +20,16 @@ import { defaultAdminCustomerGroupsRelations } from "."
|
||||
* application/json:
|
||||
* schema:
|
||||
* properties:
|
||||
* customerGroup:
|
||||
* $ref: "#/components/schemas/customer-group"
|
||||
* customer_group:
|
||||
* $ref: "#/components/schemas/customer_group"
|
||||
*/
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const validated = await validator(AdminGetCustomerGroupsGroupParams, req.query)
|
||||
const validated = await validator(
|
||||
AdminGetCustomerGroupsGroupParams,
|
||||
req.query
|
||||
)
|
||||
|
||||
const customerGroupService: CustomerGroupService = req.scope.resolve(
|
||||
"customerGroupService"
|
||||
@@ -45,7 +48,7 @@ export default async (req, res) => {
|
||||
|
||||
const customerGroup = await customerGroupService.retrieve(id, findConfig)
|
||||
|
||||
res.json({ customerGroup })
|
||||
res.json({ customer_group: customerGroup })
|
||||
}
|
||||
|
||||
export class AdminGetCustomerGroupsGroupParams extends FindParams {}
|
||||
|
||||
@@ -14,6 +14,11 @@ export default (app) => {
|
||||
"/:id",
|
||||
middlewares.wrap(require("./delete-customer-group").default)
|
||||
)
|
||||
route.post(
|
||||
"/:id",
|
||||
middlewares.wrap(require("./update-customer-group").default)
|
||||
)
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { IsObject, IsOptional, IsString } from "class-validator"
|
||||
import { defaultAdminCustomerGroupsRelations } from "."
|
||||
|
||||
import { CustomerGroupService } from "../../../../services"
|
||||
import { FindParams } from "../../../../types/common"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
|
||||
/**
|
||||
* @oas [post] /customer-groups/{id}
|
||||
* operationId: "PostCustomerGroupsGroup"
|
||||
* summary: "Update a CustomerGroup"
|
||||
* description: "Update a CustomerGroup."
|
||||
* x-authenticated: true
|
||||
* parameters:
|
||||
* - (path) id=* {string} The id of the customer group.
|
||||
* - (body) name=* {string} Name of the customer group
|
||||
* - (body) metadata {object} Metadata for the customer.
|
||||
* tags:
|
||||
* - CustomerGroup
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* properties:
|
||||
* customer_group:
|
||||
* $ref: "#/components/schemas/customer_group"
|
||||
*/
|
||||
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const validatedBody = await validator(
|
||||
AdminPostCustomerGroupsGroupReq,
|
||||
req.body
|
||||
)
|
||||
const validatedQuery = await validator(FindParams, req.query)
|
||||
|
||||
const customerGroupService: CustomerGroupService = req.scope.resolve(
|
||||
"customerGroupService"
|
||||
)
|
||||
|
||||
await customerGroupService.update(id, validatedBody)
|
||||
|
||||
let expandFields: string[] = []
|
||||
if (validatedQuery.expand) {
|
||||
expandFields = validatedQuery.expand.split(",")
|
||||
}
|
||||
|
||||
const findConfig = {
|
||||
relations: expandFields.length
|
||||
? expandFields
|
||||
: defaultAdminCustomerGroupsRelations,
|
||||
}
|
||||
|
||||
const customerGroup = await customerGroupService.retrieve(id, findConfig)
|
||||
|
||||
res.json({ customer_group: customerGroup })
|
||||
}
|
||||
|
||||
export class AdminPostCustomerGroupsGroupReq {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
name?: string
|
||||
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
metadata?: object
|
||||
}
|
||||
Reference in New Issue
Block a user