refactor: the discount servicer
This commit is contained in:
@@ -104,18 +104,15 @@ export class SubscriptionsService {
|
||||
}
|
||||
//************************************ */
|
||||
async updateSubscriptionPlan(id: string, updateDto: UpdateSubscriptionPlanDto) {
|
||||
// Find the existing subscription plan
|
||||
const subscription = await this.subscriptionsPlanRepository.findOne({ where: { id }, relations: { service: true } });
|
||||
if (!subscription) throw new BadRequestException(SubscriptionMessage.NOT_FOUND);
|
||||
|
||||
// Check if service exists when trying to update it
|
||||
if (updateDto.serviceId) {
|
||||
const danakService = await this.danakServices.findServiceById(updateDto.serviceId);
|
||||
if (!danakService) throw new BadRequestException(ServiceMessage.SERVICE_NOT_FOUND_BY_ID);
|
||||
subscription.service = danakService;
|
||||
}
|
||||
|
||||
// Check for name uniqueness if updating name
|
||||
if (updateDto.name) {
|
||||
const existSubscription = await this.subscriptionsPlanRepository.findOneBy({
|
||||
name: updateDto.name,
|
||||
|
||||
@@ -65,7 +65,6 @@ export class SubscriptionsController {
|
||||
|
||||
@ApiOperation({ summary: "update a subscription plan by id" })
|
||||
@Patch(":id")
|
||||
//TODO:fix this if needed
|
||||
@PermissionsDec(PermissionEnum.SERVICES)
|
||||
updateSubscription(@Param() paramDto: ParamDto, @Body() updateDto: UpdateSubscriptionPlanDto) {
|
||||
return this.subscriptionService.updateSubscriptionPlan(paramDto.id, updateDto);
|
||||
|
||||
Reference in New Issue
Block a user