chore: add new route to get users of services
This commit is contained in:
@@ -116,6 +116,14 @@ export class DanakServicesController {
|
||||
return this.danakServicesService.getDanakServiceByIdWithSubs(paramDto.id, isAdmin, userId);
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: "get service users" })
|
||||
@AuthGuards()
|
||||
@PermissionsDec(PermissionEnum.SERVICES)
|
||||
@Get(":id/users")
|
||||
getServiceUsers(@Param() paramDto: ParamDto) {
|
||||
return this.danakServicesService.getServiceUsers(paramDto.id);
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: "add review to danak service ==> user route" })
|
||||
@AuthGuards()
|
||||
@Post(":id/reviews")
|
||||
|
||||
@@ -244,6 +244,31 @@ export class DanakServicesService {
|
||||
}
|
||||
/******************************************** */
|
||||
|
||||
async getServiceUsers(serviceId: string) {
|
||||
await this.findServiceById(serviceId);
|
||||
|
||||
const users = await this.danakServicesRepository
|
||||
.createQueryBuilder("service")
|
||||
.innerJoin("service.subscriptionPlans", "subscriptionPlans")
|
||||
.innerJoin("subscriptionPlans.userSubscriptions", "userSubscriptions")
|
||||
.innerJoin("user", "user", "userSubscriptions.userId = user.id")
|
||||
.select([
|
||||
"DISTINCT user.id AS id",
|
||||
"user.firstName AS firstName",
|
||||
"user.lastName AS lastName",
|
||||
"user.email AS email",
|
||||
"user.profilePic AS profilePic",
|
||||
])
|
||||
.where("service.id = :serviceId", { serviceId })
|
||||
.andWhere("userSubscriptions.status = :status", { status: SubscriptionStatus.ACTIVE })
|
||||
.andWhere("userSubscriptions.endDate > NOW()")
|
||||
.getRawMany();
|
||||
|
||||
return { users };
|
||||
}
|
||||
|
||||
/******************************************** */
|
||||
|
||||
async getDanakServiceReviews(queryDto: DanakServiceReviewQueryDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// eslint-disable-next-line import/no-named-as-default
|
||||
import Decimal from "decimal.js";
|
||||
import { Column, Entity, Index, ManyToOne } from "typeorm";
|
||||
import { Column, Entity, Index, ManyToOne, OneToMany } from "typeorm";
|
||||
|
||||
import { UserSubscription } from "./user-subscription.entity";
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { DecimalTransformer } from "../../../common/transformers/decimal.transformer";
|
||||
import { DanakService } from "../../danak-services/entities/danak-service.entity";
|
||||
@@ -25,6 +26,9 @@ export class SubscriptionPlan extends BaseEntity {
|
||||
@ManyToOne(() => DanakService, (danakService) => danakService.subscriptionPlans, { nullable: false, onDelete: "CASCADE" })
|
||||
service: DanakService;
|
||||
|
||||
@OneToMany(() => UserSubscription, (userSubscription) => userSubscription.plan)
|
||||
userSubscriptions: UserSubscription[];
|
||||
|
||||
// @ManyToMany(() => Discount, (discount) => discount.subscriptionPlans)
|
||||
// discounts: Discount[];
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export class UserSubscription extends BaseEntity {
|
||||
@ManyToOne(() => User, (user) => user.subscriptions, { nullable: false, onDelete: "CASCADE" })
|
||||
user: User;
|
||||
|
||||
@ManyToOne(() => SubscriptionPlan, { nullable: false, onDelete: "CASCADE" })
|
||||
@ManyToOne(() => SubscriptionPlan, (plan) => plan.userSubscriptions, { nullable: false, onDelete: "CASCADE" })
|
||||
plan: SubscriptionPlan;
|
||||
|
||||
@Column({ type: "timestamp", nullable: false })
|
||||
|
||||
Reference in New Issue
Block a user