Feat: Delete customer group (#1102)

This commit is contained in:
Philip Korsholm
2022-02-24 14:20:58 +01:00
committed by olivermrbl
parent a9f516ead2
commit 44fb9531d2
6 changed files with 191 additions and 1 deletions

View File

@@ -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,
})
}

View File

@@ -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
}

View File

@@ -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.
*