add : toggle business activeness
This commit is contained in:
@@ -62,6 +62,7 @@ export const enum AuthMessage {
|
|||||||
TOKEN_EXPIRED_OR_INVALID = "توکن منقضی شده یا نامعتبر است",
|
TOKEN_EXPIRED_OR_INVALID = "توکن منقضی شده یا نامعتبر است",
|
||||||
ACCESS_DENIED = "دسترسی شما محدود شده است",
|
ACCESS_DENIED = "دسترسی شما محدود شده است",
|
||||||
USER_ACCOUNT_INACTIVE = "حساب کاربری شما غیر فعال است",
|
USER_ACCOUNT_INACTIVE = "حساب کاربری شما غیر فعال است",
|
||||||
|
BUSINESS_ACCOUNT_INACTIVE = "حساب کاربری اصلی شما غیر فعال است",
|
||||||
TOKEN_MISSED_OR_EXPIRED = "توکن مفقود یا منقضی شده است",
|
TOKEN_MISSED_OR_EXPIRED = "توکن مفقود یا منقضی شده است",
|
||||||
OLD_PASSWORD_REQUIRED = "رمز عبور قبلی الزامی است",
|
OLD_PASSWORD_REQUIRED = "رمز عبور قبلی الزامی است",
|
||||||
PASSWORD_CHANGE_FAILED = "تغییر رمز عبور با مشکل روبرد شد",
|
PASSWORD_CHANGE_FAILED = "تغییر رمز عبور با مشکل روبرد شد",
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export class AuthService {
|
|||||||
private readonly twoFactorService: TwoFactorService,
|
private readonly twoFactorService: TwoFactorService,
|
||||||
private readonly mailServerService: MailServerService,
|
private readonly mailServerService: MailServerService,
|
||||||
private readonly em: EntityManager,
|
private readonly em: EntityManager,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
//==============================================
|
//==============================================
|
||||||
//==============================================
|
//==============================================
|
||||||
@@ -33,6 +33,10 @@ export class AuthService {
|
|||||||
|
|
||||||
const user = await this.checkUserLoginCredentialWithEmail(email, password);
|
const user = await this.checkUserLoginCredentialWithEmail(email, password);
|
||||||
|
|
||||||
|
if(!user.business.isActive){
|
||||||
|
throw new BadRequestException(AuthMessage.BUSINESS_ACCOUNT_INACTIVE);
|
||||||
|
}
|
||||||
|
|
||||||
if (!user.isActive) throw new BadRequestException(AuthMessage.USER_ACCOUNT_INACTIVE);
|
if (!user.isActive) throw new BadRequestException(AuthMessage.USER_ACCOUNT_INACTIVE);
|
||||||
|
|
||||||
if (user.is2FAEnabled) {
|
if (user.is2FAEnabled) {
|
||||||
@@ -113,7 +117,7 @@ export class AuthService {
|
|||||||
//==============================================
|
//==============================================
|
||||||
|
|
||||||
private async checkUserLoginCredentialWithEmail(email: string, password: string) {
|
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);
|
if (!user) throw new BadRequestException(AuthMessage.INVALID_PASSWORD);
|
||||||
|
|
||||||
const passCompare = await this.passwordService.comparePasswords(password, user.password);
|
const passCompare = await this.passwordService.comparePasswords(password, user.password);
|
||||||
|
|||||||
@@ -68,4 +68,12 @@ export class BusinessesController {
|
|||||||
getPaginatedList(@Query() query: FindBusinessesDto) {
|
getPaginatedList(@Query() query: FindBusinessesDto) {
|
||||||
return this.businessesService.findBusinesses(query)
|
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 })
|
@Property({ type: "bigint", default: 10_737_418_240 })
|
||||||
remainingQuota!: number & Opt;
|
remainingQuota!: number & Opt;
|
||||||
|
|
||||||
|
@Property({ default: true, nullable: false })
|
||||||
|
isActive: boolean & Opt;
|
||||||
|
|
||||||
//=========================
|
//=========================
|
||||||
|
|
||||||
@OneToOne(() => Domain, (domain) => domain.business, { nullable: true, cascade: [Cascade.ALL] })
|
@OneToOne(() => Domain, (domain) => domain.business, { nullable: true, cascade: [Cascade.ALL] })
|
||||||
|
|||||||
@@ -164,7 +164,20 @@ export class BusinessesService {
|
|||||||
return this.quotaPurchaseService.purchaseQuota(business, purchaseDto);
|
return this.quotaPurchaseService.purchaseQuota(business, purchaseDto);
|
||||||
}
|
}
|
||||||
//********************************************* */
|
//********************************************* */
|
||||||
|
|
||||||
async findBusinesses(query: FindBusinessesDto) {
|
async findBusinesses(query: FindBusinessesDto) {
|
||||||
return this.businessRepository.findAllPaginated(query)
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user