add : toggle business activeness

This commit is contained in:
2026-03-16 16:40:12 +03:30
parent ba9aa004fe
commit f1d25b895a
6 changed files with 33 additions and 3 deletions
+1
View File
@@ -0,0 +1 @@
registry=https://mirror-npm.runflare.com
+1
View File
@@ -62,6 +62,7 @@ export const enum AuthMessage {
TOKEN_EXPIRED_OR_INVALID = "توکن منقضی شده یا نامعتبر است",
ACCESS_DENIED = "دسترسی شما محدود شده است",
USER_ACCOUNT_INACTIVE = "حساب کاربری شما غیر فعال است",
BUSINESS_ACCOUNT_INACTIVE = "حساب کاربری اصلی شما غیر فعال است",
TOKEN_MISSED_OR_EXPIRED = "توکن مفقود یا منقضی شده است",
OLD_PASSWORD_REQUIRED = "رمز عبور قبلی الزامی است",
PASSWORD_CHANGE_FAILED = "تغییر رمز عبور با مشکل روبرد شد",
+7 -3
View File
@@ -24,7 +24,7 @@ export class AuthService {
private readonly twoFactorService: TwoFactorService,
private readonly mailServerService: MailServerService,
private readonly em: EntityManager,
) {}
) { }
//==============================================
//==============================================
@@ -33,7 +33,11 @@ export class AuthService {
const user = await this.checkUserLoginCredentialWithEmail(email, password);
if (!user.isActive) throw new BadRequestException(AuthMessage.USER_ACCOUNT_INACTIVE);
if(!user.business.isActive){
throw new BadRequestException(AuthMessage.BUSINESS_ACCOUNT_INACTIVE);
}
if (!user.isActive) throw new BadRequestException(AuthMessage.USER_ACCOUNT_INACTIVE);
if (user.is2FAEnabled) {
if (!twoFactorToken) {
@@ -113,7 +117,7 @@ export class AuthService {
//==============================================
private async checkUserLoginCredentialWithEmail(email: string, password: string) {
const user = await this.userRepository.findOne({ emailAddress: email, isActive: true });
const user = await this.userRepository.findOne({ emailAddress: email }, { populate: ['business'] });
if (!user) throw new BadRequestException(AuthMessage.INVALID_PASSWORD);
const passCompare = await this.passwordService.comparePasswords(password, user.password);
@@ -68,4 +68,12 @@ export class BusinessesController {
getPaginatedList(@Query() query: FindBusinessesDto) {
return this.businessesService.findBusinesses(query)
}
@Patch(":id/active/toggle")
@AuthGuards()
@SuperAdminRoute()
@ApiOperation({ summary: "Active/Deactive a businesse" })
toggleActiveness(@Param('id') id: string) {
return this.businessesService.businessToggleActive(id)
}
}
@@ -31,6 +31,9 @@ export class Business extends BaseEntity {
@Property({ type: "bigint", default: 10_737_418_240 })
remainingQuota!: number & Opt;
@Property({ default: true, nullable: false })
isActive: boolean & Opt;
//=========================
@OneToOne(() => Domain, (domain) => domain.business, { nullable: true, cascade: [Cascade.ALL] })
@@ -164,7 +164,20 @@ export class BusinessesService {
return this.quotaPurchaseService.purchaseQuota(business, purchaseDto);
}
//********************************************* */
async findBusinesses(query: FindBusinessesDto) {
return this.businessRepository.findAllPaginated(query)
}
//********************************************* */
async businessToggleActive(businessId: string) {
const business = await this.getBusinessById(businessId)
business.isActive=!business.isActive
await this.em.flush()
return business
}
}