update: commit for the new file
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// eslint-disable-next-line import/no-named-as-default
|
||||
import Decimal from "decimal.js";
|
||||
import { Column, Entity, Index, ManyToOne, OneToMany } from "typeorm";
|
||||
import { Column, DeleteDateColumn, Entity, Index, ManyToOne, OneToMany } from "typeorm";
|
||||
|
||||
import { UserSubscription } from "./user-subscription.entity";
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
@@ -31,4 +31,7 @@ export class SubscriptionPlan extends BaseEntity {
|
||||
|
||||
@ManyToOne(() => DirectDiscount, (directDiscount) => directDiscount.subscriptionPlans, { nullable: true })
|
||||
directDiscount?: DirectDiscount;
|
||||
|
||||
@DeleteDateColumn({ nullable: true })
|
||||
deletedAt?: Date;
|
||||
}
|
||||
|
||||
Regular → Executable
@@ -144,7 +144,7 @@ export class SubscriptionsService {
|
||||
}
|
||||
//************************************ */
|
||||
|
||||
async getServiceSubscriptions(serviceId: string, queryDto: ServiceSubsQueryDto) {
|
||||
async All(serviceId: string, queryDto: ServiceSubsQueryDto) {
|
||||
const service = await this.danakServices.findServiceById(serviceId);
|
||||
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
@@ -237,6 +237,45 @@ export class SubscriptionsService {
|
||||
}
|
||||
}
|
||||
//************************************ */
|
||||
async getServiceSubscriptions(serviceId: string, queryDto: ServiceSubsQueryDto) {
|
||||
const service = await this.danakServices.findServiceById(serviceId);
|
||||
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
const queryBuilder = this.subscriptionsPlanRepository
|
||||
.createQueryBuilder("subscription")
|
||||
.leftJoin("subscription.service", "service")
|
||||
.addSelect(["service.id"])
|
||||
// .leftJoin("subscription.discounts", "discount")
|
||||
// .addSelect(["discount.calculationType", "discount.amount", "discount.startDate", "discount.endDate", "discount.isActive"])
|
||||
.where("service.id = :serviceId", { serviceId });
|
||||
|
||||
if (queryDto.q) {
|
||||
queryBuilder.andWhere("subscription.name ILIKE :query", { query: `%${queryDto.q}%` });
|
||||
}
|
||||
|
||||
if (queryDto.isActive !== undefined) {
|
||||
queryBuilder.andWhere("subscription.isActive = :isActive", { isActive: queryDto.isActive === 1 });
|
||||
}
|
||||
|
||||
const [subscriptions, count] = await queryBuilder.skip(skip).take(limit).getManyAndCount();
|
||||
|
||||
return {
|
||||
service,
|
||||
subscriptions,
|
||||
count,
|
||||
pagination: true,
|
||||
};
|
||||
}
|
||||
//************************************ */
|
||||
|
||||
async getAllServiceSubscriptions(serviceIds: string[]) {
|
||||
const subscriptions = await this.subscriptionsPlanRepository.find({
|
||||
where: { service: { id: In(serviceIds) }, isActive: true },
|
||||
});
|
||||
return subscriptions;
|
||||
}
|
||||
//************************************ */
|
||||
|
||||
async countUserSubscriptions(userId: string) {
|
||||
const subscriptionCount = await this.userSubscriptionsRepository.count({
|
||||
@@ -335,8 +374,6 @@ export class SubscriptionsService {
|
||||
const startOfWeek = dayjs().startOf("week").toDate();
|
||||
const endOfWeek = dayjs().endOf("week").toDate();
|
||||
|
||||
console.log(startOfWeek, endOfWeek);
|
||||
|
||||
const sales = await this.userSubscriptionsRepository
|
||||
.createQueryBuilder("userSubscription")
|
||||
.select("DATE(userSubscription.startDate)", "date")
|
||||
|
||||
Regular → Executable
Regular → Executable
@@ -31,6 +31,6 @@ import { UserQuickAccessRepository } from "./repositories/users-quick-access.rep
|
||||
UserQuickAccessService,
|
||||
],
|
||||
controllers: [SubscriptionsController],
|
||||
exports: [SubscriptionsService, TypeOrmModule, SubscriptionsPlanRepository, UserSubscriptionsRepository],
|
||||
exports: [SubscriptionsService, SubscriptionsPlanRepository, UserSubscriptionsRepository],
|
||||
})
|
||||
export class SubscriptionsModule {}
|
||||
|
||||
Reference in New Issue
Block a user