get subscription in admin
This commit is contained in:
@@ -65,6 +65,15 @@ export class SalonSubscriptionsController {
|
||||
return this.salonSubscriptionsService.purchaseSmsPackage(dto, user);
|
||||
}
|
||||
|
||||
@Roles(UserRole.ADMIN, UserRole.SALON)
|
||||
@Permissions(PermissionCode.SUBSCRIPTIONS_READ)
|
||||
@AllowWithoutSubscription()
|
||||
@ApiStandardOkResponse(SalonSubscription, { isArray: true })
|
||||
@Get()
|
||||
findAll(@CurrentUser() user: AuthUser) {
|
||||
return this.salonSubscriptionsService.findAll(user);
|
||||
}
|
||||
|
||||
@Roles(UserRole.ADMIN, UserRole.SALON)
|
||||
@Permissions(PermissionCode.SUBSCRIPTIONS_READ)
|
||||
@AllowWithoutSubscription()
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Repository } from 'typeorm';
|
||||
import { AuthUser } from '../auth/interfaces/auth-user.interface';
|
||||
import { SubscriptionPolicy } from '../authorization/policies/subscription.policy';
|
||||
import { SalonsService } from '../salons/salons.service';
|
||||
import { UserRole } from '../users/enums/user-role.enum';
|
||||
import { SMS_ROLLOVER_GRACE_DAYS } from './constants/subscription.constants';
|
||||
import { PurchaseSmsPackageDto } from './dto/purchase-sms-package.dto';
|
||||
import { SalonSmsPurchase } from './entities/salon-sms-purchase.entity';
|
||||
@@ -126,6 +127,23 @@ export class SalonSubscriptionsService {
|
||||
});
|
||||
}
|
||||
|
||||
async findAll(user: AuthUser): Promise<SalonSubscription[]> {
|
||||
if (user.role === UserRole.SALON) {
|
||||
return this.subscriptionsRepository
|
||||
.createQueryBuilder('subscription')
|
||||
.innerJoinAndSelect('subscription.salon', 'salon')
|
||||
.innerJoinAndSelect('subscription.plan', 'plan')
|
||||
.where('salon.ownerId = :ownerId', { ownerId: user.id })
|
||||
.orderBy('subscription.createdAt', 'DESC')
|
||||
.getMany();
|
||||
}
|
||||
|
||||
return this.subscriptionsRepository.find({
|
||||
relations: { plan: true, salon: true },
|
||||
order: { createdAt: 'DESC' },
|
||||
});
|
||||
}
|
||||
|
||||
async findActiveForSalon(
|
||||
salonId: string,
|
||||
user: AuthUser,
|
||||
@@ -138,7 +156,10 @@ export class SalonSubscriptionsService {
|
||||
return this.findActiveSubscription(salonId);
|
||||
}
|
||||
|
||||
async getSmsBalance(salonId: string, user: AuthUser): Promise<SalonSmsBalance> {
|
||||
async getSmsBalance(
|
||||
salonId: string,
|
||||
user: AuthUser,
|
||||
): Promise<SalonSmsBalance> {
|
||||
const salon = await this.salonsService.findOne(salonId);
|
||||
if (!this.subscriptionPolicy.canRead(user, salon)) {
|
||||
throw new ForbiddenException();
|
||||
@@ -206,7 +227,9 @@ export class SalonSubscriptionsService {
|
||||
|
||||
const hasActive = await this.hasActiveSubscription(salonId);
|
||||
if (!hasActive) {
|
||||
throw new BadRequestException('Salon does not have an active subscription');
|
||||
throw new BadRequestException(
|
||||
'Salon does not have an active subscription',
|
||||
);
|
||||
}
|
||||
|
||||
let remaining = count;
|
||||
@@ -303,7 +326,10 @@ export class SalonSubscriptionsService {
|
||||
order: { endDate: 'DESC' },
|
||||
});
|
||||
|
||||
if (!lastSubscription || lastSubscription.status === SalonSubscriptionStatus.ACTIVE) {
|
||||
if (
|
||||
!lastSubscription ||
|
||||
lastSubscription.status === SalonSubscriptionStatus.ACTIVE
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CreateSmsPackageDto } from './dto/create-sms-package.dto';
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CreateSubscriptionPlanDto } from './dto/create-subscription-plan.dto';
|
||||
@@ -56,7 +53,8 @@ export class SubscriptionPlansService {
|
||||
}
|
||||
if (dto.name !== undefined) plan.name = dto.name;
|
||||
if (dto.code !== undefined) plan.code = dto.code;
|
||||
if (dto.durationMonths !== undefined) plan.durationMonths = dto.durationMonths;
|
||||
if (dto.durationMonths !== undefined)
|
||||
plan.durationMonths = dto.durationMonths;
|
||||
if (dto.freeSmsCount !== undefined) plan.freeSmsCount = dto.freeSmsCount;
|
||||
if (dto.isActive !== undefined) plan.isActive = dto.isActive;
|
||||
return this.plansRepository.save(plan);
|
||||
|
||||
Reference in New Issue
Block a user