chore: new feture for quato
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { EntityManager, FilterQuery } from "@mikro-orm/postgresql";
|
||||
import { EntityManager } from "@mikro-orm/postgresql";
|
||||
import { BadRequestException, Injectable, Logger, NotFoundException } from "@nestjs/common";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
@@ -17,6 +17,7 @@ import { DomainsService } from "../../domains/services/domains.service";
|
||||
import { MailServerService } from "../../mail-server/services/mail-server.service";
|
||||
import { PasswordService } from "../../utils/services/password.service";
|
||||
import { CreateEmailUserDto } from "../DTO/create-email-user.dto";
|
||||
import { UserListQueryDto } from "../DTO/user-list-query.dto";
|
||||
import { Role } from "../entities/role.entity";
|
||||
import { User } from "../entities/user.entity";
|
||||
import { RoleEnum } from "../enums/role.enum";
|
||||
@@ -103,7 +104,7 @@ export class UsersService {
|
||||
emailAddress,
|
||||
emailEnabled: true,
|
||||
emailQuota: quota || 1073741824,
|
||||
emailAccountId: mailServerUser.id,
|
||||
wildduckUserId: mailServerUser.id,
|
||||
displayName: displayName || username,
|
||||
isActive: true,
|
||||
business,
|
||||
@@ -135,7 +136,7 @@ export class UsersService {
|
||||
id: user.id,
|
||||
emailAddress: user.emailAddress!,
|
||||
displayName: user.displayName!,
|
||||
emailAccountId: user.emailAccountId!,
|
||||
wildduckUserId: user.wildduckUserId!,
|
||||
emailQuota: user.emailQuota!,
|
||||
emailEnabled: user.emailEnabled,
|
||||
domain: domain.name,
|
||||
@@ -164,21 +165,10 @@ export class UsersService {
|
||||
}
|
||||
|
||||
/*******************************/
|
||||
async getEmailUsers(businessId: string, domainId?: string) {
|
||||
const whereClause: FilterQuery<User> = {
|
||||
business: { id: businessId },
|
||||
emailEnabled: true,
|
||||
deletedAt: null,
|
||||
};
|
||||
async getEmailUsers(businessId: string, queryDto: UserListQueryDto) {
|
||||
const [users, count] = await this.userRepository.getUserListForAdmin(businessId, queryDto);
|
||||
|
||||
if (domainId) whereClause.domain = { id: domainId };
|
||||
|
||||
const users = await this.userRepository.find(whereClause, {
|
||||
populate: ["domain", "business"],
|
||||
orderBy: { createdAt: "DESC" },
|
||||
});
|
||||
|
||||
return { users };
|
||||
return { users, count, paginate: true };
|
||||
}
|
||||
|
||||
/*******************************/
|
||||
@@ -192,8 +182,8 @@ export class UsersService {
|
||||
if (!user) throw new NotFoundException(UserMessage.EMAIL_USER_NOT_FOUND);
|
||||
|
||||
try {
|
||||
if (user.emailAccountId) {
|
||||
await firstValueFrom(this.mailServerService.users.deleteUser(user.emailAccountId));
|
||||
if (user.wildduckUserId) {
|
||||
await firstValueFrom(this.mailServerService.users.deleteUser(user.wildduckUserId));
|
||||
}
|
||||
|
||||
user.deletedAt = new Date();
|
||||
@@ -224,9 +214,9 @@ export class UsersService {
|
||||
if (!user) throw new NotFoundException(UserMessage.EMAIL_USER_NOT_FOUND);
|
||||
|
||||
try {
|
||||
if (user.emailAccountId) {
|
||||
if (user.wildduckUserId) {
|
||||
await firstValueFrom(
|
||||
this.mailServerService.users.updateUser(user.emailAccountId, {
|
||||
this.mailServerService.users.updateUser(user.wildduckUserId, {
|
||||
quota: newQuota,
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user