refactor: the discount servicer

This commit is contained in:
mahyargdz
2025-04-22 15:02:26 +03:30
parent 3e87de6eae
commit 5883890e7f
5 changed files with 49 additions and 60 deletions
@@ -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);