chore: add new route to get user of support plan
This commit is contained in:
@@ -40,7 +40,6 @@ import { TicketsModule } from "./modules/tickets/tickets.module";
|
||||
import { UploaderModule } from "./modules/uploader/uploader.module";
|
||||
import { UsersModule } from "./modules/users/users.module";
|
||||
import { WalletsModule } from "./modules/wallets/wallets.module";
|
||||
import { MonitoringModule } from "./monitoring/monitoring.module";
|
||||
@Module({
|
||||
imports: [
|
||||
// TelegrafModule.forRootAsync(telegrafConfig()),
|
||||
@@ -60,7 +59,6 @@ import { MonitoringModule } from "./monitoring/monitoring.module";
|
||||
parts: 10,
|
||||
},
|
||||
}),
|
||||
MonitoringModule,
|
||||
AuthModule,
|
||||
UsersModule,
|
||||
TicketsModule,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsString } from "class-validator";
|
||||
import { IsOptional } from "class-validator";
|
||||
|
||||
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
import { CommonMessage } from "../../../common/enums/message.enum";
|
||||
|
||||
export class SearchSupportPlanUsersQueryDto extends PaginationDto {
|
||||
@IsOptional()
|
||||
@IsString({ message: CommonMessage.SEARCH_QUERY_STRING })
|
||||
@ApiPropertyOptional({ description: "Search query", example: "search query" })
|
||||
q?: string;
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { InvoicesService } from "../../invoices/providers/invoices.service";
|
||||
import { UsersService } from "../../users/providers/users.service";
|
||||
import { CreateSupportPlanDto } from "../DTO/create-support-plan.dto";
|
||||
import { GetSupportPlanListQueryDto } from "../DTO/get-support-plan-list-query.dto";
|
||||
import { SearchSupportPlanUsersQueryDto } from "../DTO/search-support-plan-users-query.dto";
|
||||
import { UpdateSupportPlanDto } from "../DTO/update-support-plan-feature.dto";
|
||||
import { UserSupportPlanStatus } from "../enums/user-support-plan-status.enum";
|
||||
import { SupportPlanFeatureRepository } from "../repositories/support-plan-feature.repository";
|
||||
@@ -181,12 +182,9 @@ export class SupportPlansService {
|
||||
}
|
||||
|
||||
//***************************************** */
|
||||
async getUsersOfSupportPlan(supportPlanId: string) {
|
||||
const users = await this.userSupportPlanRepo.find({
|
||||
where: { supportPlan: { id: supportPlanId }, status: UserSupportPlanStatus.ACTIVE },
|
||||
relations: { user: true, supportPlan: true },
|
||||
});
|
||||
return users;
|
||||
async getSupportPlanUsers(supportPlanId: string, queryDto: SearchSupportPlanUsersQueryDto) {
|
||||
const [users, count] = await this.userSupportPlanRepo.getSupportPlanUsers(supportPlanId, queryDto);
|
||||
return { users, count, paginate: true };
|
||||
}
|
||||
//***************************************** */
|
||||
async upgradeSupportPlan(newPlanId: string, userId: string) {
|
||||
|
||||
@@ -2,6 +2,8 @@ import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
import { SearchSupportPlanUsersQueryDto } from "../DTO/search-support-plan-users-query.dto";
|
||||
import { UserSupportPlan } from "../entities/user-support-plan.entity";
|
||||
import { UserSupportPlanStatus } from "../enums/user-support-plan-status.enum";
|
||||
@Injectable()
|
||||
@@ -16,4 +18,15 @@ export class UserSupportPlanRepository extends Repository<UserSupportPlan> {
|
||||
});
|
||||
return userSupportPlan;
|
||||
}
|
||||
|
||||
async getSupportPlanUsers(supportPlanId: string, queryDto: SearchSupportPlanUsersQueryDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
return this.findAndCount({
|
||||
where: { supportPlan: { id: supportPlanId }, status: UserSupportPlanStatus.ACTIVE },
|
||||
relations: { user: true, supportPlan: true },
|
||||
take: limit,
|
||||
skip,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ApiOperation } from "@nestjs/swagger";
|
||||
|
||||
import { CreateSupportPlanDto } from "./DTO/create-support-plan.dto";
|
||||
import { GetSupportPlanListQueryDto } from "./DTO/get-support-plan-list-query.dto";
|
||||
import { SearchSupportPlanUsersQueryDto } from "./DTO/search-support-plan-users-query.dto";
|
||||
import { UpdateSupportPlanDto } from "./DTO/update-support-plan-feature.dto";
|
||||
import { SupportPlansService } from "./providers/support-plans.service";
|
||||
import { AdminRoute } from "../../common/decorators/admin.decorator";
|
||||
@@ -69,6 +70,14 @@ export class SupportPlansController {
|
||||
return this.supportPlansService.subscribeToSupportPlan(paramDto.id, userId);
|
||||
}
|
||||
|
||||
@AdminRoute()
|
||||
@PermissionsDec(PermissionEnum.SUPPORT_PLAN)
|
||||
@ApiOperation({ summary: "Get support plan users (admin)" })
|
||||
@Get(":id/users")
|
||||
getSupportPlanUsers(@Param() paramDto: ParamDto, @Query() queryDto: SearchSupportPlanUsersQueryDto) {
|
||||
return this.supportPlansService.getSupportPlanUsers(paramDto.id, queryDto);
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: "Get user support plan of user" })
|
||||
@Get("user")
|
||||
getUserSupportPlanOfUser(@UserDec("id") userId: string) {
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { PrometheusModule } from "@willsoto/nestjs-prometheus";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
PrometheusModule.register({
|
||||
defaultMetrics: {
|
||||
enabled: true,
|
||||
},
|
||||
defaultLabels: {
|
||||
application: "danak_dsc_api",
|
||||
},
|
||||
}),
|
||||
],
|
||||
})
|
||||
export class MonitoringModule {}
|
||||
Reference in New Issue
Block a user