upgrade sub
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateRestaurantDto } from '../dto/create-restaurant.dto';
|
||||
import { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
|
||||
import { UpgradeSubscriptionDto } from '../dto/upgrade-subscription.dto';
|
||||
import { Restaurant } from '../entities/restaurant.entity';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { RestRepository } from '../repositories/rest.repository';
|
||||
@@ -53,7 +54,7 @@ export class RestaurantsService {
|
||||
throw new BadRequestException(`Role not found for plan: ${dto.plan}`);
|
||||
}
|
||||
|
||||
const normalizedPhone = normalizePhone(dto.phone);
|
||||
const normalizedPhone = normalizePhone(dto.phone);
|
||||
let admin = await em.findOne(Admin, { phone: normalizedPhone });
|
||||
if (!admin) {
|
||||
admin = em.create(Admin, {
|
||||
@@ -150,4 +151,19 @@ const normalizedPhone = normalizePhone(dto.phone);
|
||||
|
||||
return restaurant;
|
||||
}
|
||||
|
||||
async upgradeSubscription(subscriptionId: string, dto: UpgradeSubscriptionDto): Promise<Restaurant> {
|
||||
const restaurant = await this.restRepository.findOne({ subscriptionId });
|
||||
|
||||
if (!restaurant) {
|
||||
throw new NotFoundException(RestMessage.NOT_FOUND);
|
||||
}
|
||||
|
||||
restaurant.plan = dto.newPlan;
|
||||
restaurant.subscriptionEndDate = dto.subscriptionEndDate;
|
||||
|
||||
await this.em.persistAndFlush(restaurant);
|
||||
|
||||
return restaurant;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user