/me
This commit is contained in:
@@ -154,25 +154,34 @@ export class SalonSubscriptionsService {
|
||||
}
|
||||
|
||||
async hasActiveSubscriptionForOwner(ownerId: string): Promise<boolean> {
|
||||
const subscription = await this.findActiveSubscriptionForOwner(ownerId);
|
||||
return subscription !== null;
|
||||
}
|
||||
|
||||
async findActiveSubscriptionForOwner(
|
||||
ownerId: string,
|
||||
): Promise<SalonSubscription | null> {
|
||||
const subscriptions = await this.subscriptionsRepository
|
||||
.createQueryBuilder('subscription')
|
||||
.innerJoin('subscription.salon', 'salon')
|
||||
.innerJoinAndSelect('subscription.salon', 'salon')
|
||||
.innerJoinAndSelect('subscription.plan', 'plan')
|
||||
.where('salon.ownerId = :ownerId', { ownerId })
|
||||
.andWhere('subscription.status = :status', {
|
||||
status: SalonSubscriptionStatus.ACTIVE,
|
||||
})
|
||||
.orderBy('subscription.createdAt', 'DESC')
|
||||
.getMany();
|
||||
|
||||
const now = new Date();
|
||||
for (const subscription of subscriptions) {
|
||||
if (subscription.endDate > now) {
|
||||
return true;
|
||||
return subscription;
|
||||
}
|
||||
subscription.status = SalonSubscriptionStatus.EXPIRED;
|
||||
await this.subscriptionsRepository.save(subscription);
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
async consumeSms(salonId: string, count = 1): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user