update sub
This commit is contained in:
@@ -3,6 +3,7 @@ import { RestaurantsService } from '../providers/restaurants.service';
|
|||||||
import { CreateRestaurantDto } from '../dto/create-restaurant.dto';
|
import { CreateRestaurantDto } from '../dto/create-restaurant.dto';
|
||||||
import { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
|
import { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
|
||||||
import { UpgradeSubscriptionDto } from '../dto/upgrade-subscription.dto';
|
import { UpgradeSubscriptionDto } from '../dto/upgrade-subscription.dto';
|
||||||
|
import { UpdateSubscriptionDto } from '../dto/update-subscription.dto';
|
||||||
import { FindRestaurantsDto } from '../dto/find-restaurants.dto';
|
import { FindRestaurantsDto } from '../dto/find-restaurants.dto';
|
||||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||||
import {
|
import {
|
||||||
@@ -122,4 +123,17 @@ export class RestaurantsController {
|
|||||||
return this.restaurantsService.upgradeSubscription(subscriptionId, upgradeSubscriptionDto);
|
return this.restaurantsService.upgradeSubscription(subscriptionId, upgradeSubscriptionDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(SuperAdminAuthGuard)
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@ApiOperation({ summary: 'Update subscription for a restaurant' })
|
||||||
|
@ApiParam({ name: 'restaurantId', required: true, description: 'Restaurant ID' })
|
||||||
|
@ApiBody({ type: UpdateSubscriptionDto })
|
||||||
|
@Patch('super-admin/restaurants/:restaurantId/subscription')
|
||||||
|
updateSubscription(
|
||||||
|
@Param('restaurantId') restaurantId: string,
|
||||||
|
@Body() updateSubscriptionDto: UpdateSubscriptionDto
|
||||||
|
) {
|
||||||
|
return this.restaurantsService.updateSubscription(restaurantId, updateSubscriptionDto);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { IsString, IsDate } from 'class-validator';
|
||||||
|
import { Type } from 'class-transformer';
|
||||||
|
|
||||||
|
export class UpdateSubscriptionDto {
|
||||||
|
@ApiProperty({ example: 'sub_1234567890', description: 'Subscription ID' })
|
||||||
|
@IsString()
|
||||||
|
subscriptionId!: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: '2025-12-31', description: 'New subscription end date' })
|
||||||
|
@Type(() => Date)
|
||||||
|
@IsDate()
|
||||||
|
subscriptionEndDate!: Date;
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import { BadRequestException, Injectable, NotFoundException } from '@nestjs/comm
|
|||||||
import { CreateRestaurantDto } from '../dto/create-restaurant.dto';
|
import { CreateRestaurantDto } from '../dto/create-restaurant.dto';
|
||||||
import { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
|
import { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
|
||||||
import { UpgradeSubscriptionDto } from '../dto/upgrade-subscription.dto';
|
import { UpgradeSubscriptionDto } from '../dto/upgrade-subscription.dto';
|
||||||
|
import { UpdateSubscriptionDto } from '../dto/update-subscription.dto';
|
||||||
import { Restaurant } from '../entities/restaurant.entity';
|
import { Restaurant } from '../entities/restaurant.entity';
|
||||||
import { EntityManager } from '@mikro-orm/postgresql';
|
import { EntityManager } from '@mikro-orm/postgresql';
|
||||||
import { RestRepository } from '../repositories/rest.repository';
|
import { RestRepository } from '../repositories/rest.repository';
|
||||||
@@ -177,4 +178,19 @@ export class RestaurantsService {
|
|||||||
|
|
||||||
return restaurant;
|
return restaurant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateSubscription(restaurantId: string, dto: UpdateSubscriptionDto): Promise<Restaurant> {
|
||||||
|
const restaurant = await this.restRepository.findOne({ id: restaurantId });
|
||||||
|
|
||||||
|
if (!restaurant) {
|
||||||
|
throw new NotFoundException(RestMessage.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
restaurant.subscriptionId = dto.subscriptionId;
|
||||||
|
restaurant.subscriptionEndDate = dto.subscriptionEndDate;
|
||||||
|
|
||||||
|
await this.em.persistAndFlush(restaurant);
|
||||||
|
|
||||||
|
return restaurant;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user