Feat: Delete customer group (#1102)
This commit is contained in:
committed by
olivermrbl
parent
a9f516ead2
commit
44fb9531d2
@@ -0,0 +1,44 @@
|
||||
import { CustomerGroupService } from "../../../../services"
|
||||
|
||||
/**
|
||||
* @oas [delete] /customer-groups/{id}
|
||||
* operationId: "DeleteCustomerGroupsCustomerGroup"
|
||||
* summary: "Delete a CustomerGroup"
|
||||
* description: "Deletes a CustomerGroup."
|
||||
* x-authenticated: true
|
||||
* parameters:
|
||||
* - (path) id=* {string} The id of the Customer Group
|
||||
* tags:
|
||||
* - CustomerGroup
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* properties:
|
||||
* id:
|
||||
* type: string
|
||||
* description: The id of the deleted customer group.
|
||||
* object:
|
||||
* type: string
|
||||
* description: The type of the object that was deleted.
|
||||
* deleted:
|
||||
* type: boolean
|
||||
*/
|
||||
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const customerGroupService: CustomerGroupService = req.scope.resolve(
|
||||
"customerGroupService"
|
||||
)
|
||||
|
||||
await customerGroupService.delete(id)
|
||||
|
||||
res.json({
|
||||
id: id,
|
||||
object: "customer_group",
|
||||
deleted: true,
|
||||
})
|
||||
}
|
||||
@@ -10,6 +10,10 @@ export default (app) => {
|
||||
|
||||
route.get("/:id", middlewares.wrap(require("./get-customer-group").default))
|
||||
route.post("/", middlewares.wrap(require("./create-customer-group").default))
|
||||
route.delete(
|
||||
"/:id",
|
||||
middlewares.wrap(require("./delete-customer-group").default)
|
||||
)
|
||||
return app
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,28 @@ class CustomerGroupService extends BaseService {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove customer group
|
||||
*
|
||||
* @param {string} groupId id of the customer group to delete
|
||||
* @return {Promise} a promise
|
||||
*/
|
||||
async delete(groupId: string): Promise<void> {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
const cgRepo: CustomerGroupRepository = manager.getCustomRepository(
|
||||
this.customerGroupRepository_
|
||||
)
|
||||
|
||||
const customerGroup = await cgRepo.findOne({ where: { id: groupId } })
|
||||
|
||||
if (customerGroup) {
|
||||
await cgRepo.remove(customerGroup)
|
||||
}
|
||||
|
||||
return Promise.resolve()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* List customer groups.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user