chore: get all admnins
This commit is contained in:
@@ -5,9 +5,12 @@ import { In, Not, QueryRunner } from "typeorm";
|
||||
import { CommonMessage, FinancialMessage, UserMessage } from "../../../common/enums/message.enum";
|
||||
import { CompleteRegistrationDto } from "../../auth/DTO/complete-register.dto";
|
||||
import { UserSettingsService } from "../../settings/providers/user-settings.service";
|
||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
import { WalletsService } from "../../wallets/providers/wallets.service";
|
||||
import { CheckValidityDTO } from "../DTO/check-validity.dto";
|
||||
import { CreateFinancialDto } from "../DTO/create-user-financial.dto";
|
||||
import { SearchAdminsDto } from "../DTO/search-admins.dto";
|
||||
import { SearchCustomersDto } from "../DTO/search-customers.dto";
|
||||
import { UpdateProfileDto } from "../DTO/update-profile.dto";
|
||||
import { CreateUserGroupDto } from "../DTO/user-group.dto";
|
||||
import { Role } from "../entities/role.entity";
|
||||
@@ -204,9 +207,60 @@ export class UsersService {
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async findAllCustomers() {
|
||||
const customers = await this.userRepository.find({
|
||||
async findAllAdmins(queryDto: SearchAdminsDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
const queryBuilder = this.userRepository
|
||||
.createQueryBuilder("user")
|
||||
.leftJoin("user.role", "role")
|
||||
.where("role.name = :roleName", { roleName: RoleEnum.ADMIN })
|
||||
.leftJoin("user.groups", "groups")
|
||||
.addSelect(["groups.id", "groups.name"]);
|
||||
|
||||
if (queryDto.q) {
|
||||
queryBuilder
|
||||
.orWhere("user.firstName ILIKE :search", { search: `%${queryDto.q}%` })
|
||||
.orWhere("user.lastName ILIKE :search", { search: `%${queryDto.q}%` })
|
||||
.orWhere("user.userName ILIKE :search", { search: `%${queryDto.q}%` });
|
||||
}
|
||||
|
||||
const [admins, count] = await queryBuilder.skip(skip).take(limit).getManyAndCount();
|
||||
|
||||
return { admins, count };
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async findAllCustomers(queryDto: SearchCustomersDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
const queryBuilder = this.userRepository
|
||||
.createQueryBuilder("user")
|
||||
.leftJoin("user.role", "role")
|
||||
.where("role.name = :roleName", { roleName: RoleEnum.USER })
|
||||
.leftJoin("user.groups", "groups")
|
||||
.addSelect(["groups.id", "groups.name"])
|
||||
.leftJoinAndSelect("user.invoices", "invoices")
|
||||
.leftJoinAndSelect("user.subscriptions", "subscriptions")
|
||||
.leftJoinAndSelect("user.tickets", "tickets");
|
||||
|
||||
if (queryDto.q) {
|
||||
queryBuilder
|
||||
.orWhere("user.firstName ILIKE :search", { search: `%${queryDto.q}%` })
|
||||
.orWhere("user.lastName ILIKE :search", { search: `%${queryDto.q}%` });
|
||||
}
|
||||
|
||||
const [customers, count] = await queryBuilder.skip(skip).take(limit).getManyAndCount();
|
||||
|
||||
return { customers, count };
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async findOneCustomer(userId: string) {
|
||||
const customer = await this.userRepository.findOne({
|
||||
where: {
|
||||
id: userId,
|
||||
role: {
|
||||
name: RoleEnum.USER,
|
||||
},
|
||||
@@ -214,7 +268,7 @@ export class UsersService {
|
||||
relations: ["tickets", "subscriptions", "invoices"],
|
||||
});
|
||||
|
||||
return { customers };
|
||||
return { customer };
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
@@ -248,6 +302,32 @@ export class UsersService {
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async updateUserFinancial(updateDto: CreateFinancialDto, user: User, userFinancialId: string) {
|
||||
const userExist = await this.userRepository.findOneBy({
|
||||
id: user.role.name === RoleEnum.USER ? user.id : updateDto.userId,
|
||||
});
|
||||
|
||||
if (!userExist) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
|
||||
const existingFinancial = await this.userFinancialRepository.findOne({
|
||||
where: { id: userFinancialId, user: { id: userExist.id }, type: updateDto.type },
|
||||
});
|
||||
|
||||
if (!existingFinancial) throw new BadRequestException(FinancialMessage.FINANCIAL_INFO_NOT_FOUND);
|
||||
|
||||
await this.userFinancialRepository.save({
|
||||
...existingFinancial,
|
||||
updateDto,
|
||||
});
|
||||
|
||||
return {
|
||||
message: CommonMessage.UPDATE_SUCCESS,
|
||||
userFinancial: existingFinancial,
|
||||
};
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async getUserFinancial(userId: string) {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user