fix: join address to the customer get by admin
This commit is contained in:
@@ -5,7 +5,6 @@ import { TokensService } from "./tokens.service";
|
||||
import { AuthMessage, UserMessage } from "../../../common/enums/message.enum";
|
||||
import { NotificationsService } from "../../notifications/providers/notifications.service";
|
||||
import { Role } from "../../users/entities/role.entity";
|
||||
import { User } from "../../users/entities/user.entity";
|
||||
import { UsersService } from "../../users/providers/users.service";
|
||||
import { OTPService } from "../../utils/providers/otp.service";
|
||||
import { PasswordService } from "../../utils/providers/password.service";
|
||||
@@ -69,7 +68,7 @@ export class AuthService {
|
||||
const hashedPassword = await this.passwordService.hashPassword(completeRegistrationDto.password);
|
||||
const user = await this.usersService.createUser(completeRegistrationDto, hashedPassword, queryRunner);
|
||||
|
||||
const tokens = this.generateAccessAndRefreshToken(user);
|
||||
const tokens = await this.tokensService.generateTokens(user);
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
|
||||
@@ -93,7 +92,7 @@ export class AuthService {
|
||||
|
||||
if (!user.roles.some((role) => !role.isAdmin)) throw new BadRequestException(AuthMessage.ADMIN_CAN_NOT_LOGIN);
|
||||
|
||||
const tokens = this.generateAccessAndRefreshToken(user);
|
||||
const tokens = await this.tokensService.generateTokens(user);
|
||||
|
||||
await this.notificationService.createLoginNotification(user.id, { userPhone: user.phone });
|
||||
|
||||
@@ -113,7 +112,7 @@ export class AuthService {
|
||||
const isAdmin = this.checkUserIsAdmin(user.roles);
|
||||
if (!isAdmin) throw new BadRequestException(AuthMessage.NOT_ADMIN);
|
||||
|
||||
const tokens = this.generateAccessAndRefreshToken(user);
|
||||
const tokens = await this.tokensService.generateTokens(user);
|
||||
|
||||
return {
|
||||
message: AuthMessage.PASSWORD_LOGIN_SUCCESS,
|
||||
@@ -174,7 +173,7 @@ export class AuthService {
|
||||
if (!user.roles.some((role) => !role.isAdmin)) throw new BadRequestException(AuthMessage.ADMIN_CAN_NOT_LOGIN);
|
||||
// if (user.roles.some((role) => role.isAdmin)) throw new BadRequestException(AuthMessage.ADMIN_CAN_NOT_LOGIN);
|
||||
|
||||
const tokens = this.generateAccessAndRefreshToken(user);
|
||||
const tokens = await this.tokensService.generateTokens(user);
|
||||
|
||||
await this.notificationService.createLoginNotification(user.id, { userPhone: user.phone });
|
||||
return {
|
||||
@@ -183,7 +182,6 @@ export class AuthService {
|
||||
};
|
||||
}
|
||||
|
||||
//****************** */
|
||||
//****************** */
|
||||
|
||||
async adminVerifyLoginOtp(verifyOtpDto: VerifyOtpDto) {
|
||||
@@ -195,7 +193,7 @@ export class AuthService {
|
||||
|
||||
if (!isUserAdmin) throw new BadRequestException(AuthMessage.NOT_ADMIN);
|
||||
|
||||
const tokens = this.generateAccessAndRefreshToken(user);
|
||||
const tokens = await this.tokensService.generateTokens(user);
|
||||
|
||||
return {
|
||||
message: AuthMessage.LOGIN_SUCCESS,
|
||||
@@ -219,6 +217,19 @@ export class AuthService {
|
||||
message: AuthMessage.PASSWORD_CHANGED_SUCCESSFULLY,
|
||||
};
|
||||
}
|
||||
//****************** */
|
||||
|
||||
async refreshToken(oldRefreshToken: string) {
|
||||
return this.tokensService.refreshToken(oldRefreshToken);
|
||||
}
|
||||
//****************** */
|
||||
|
||||
async logout(refreshToken: string) {
|
||||
await this.tokensService.invalidateRefreshToken(refreshToken);
|
||||
return {
|
||||
message: AuthMessage.LOGOUT_SUCCESS,
|
||||
};
|
||||
}
|
||||
|
||||
//****************** */
|
||||
|
||||
@@ -245,17 +256,6 @@ export class AuthService {
|
||||
|
||||
return user;
|
||||
}
|
||||
//****************** */
|
||||
//****************** */
|
||||
private generateAccessAndRefreshToken(user: User) {
|
||||
return this.tokensService.generateAccessAndRefreshToken({
|
||||
id: user.id,
|
||||
isAdmin: user.roles.some((r) => r.isAdmin),
|
||||
permissions: user.roles.flatMap((r) => (r?.permissions?.length ? r.permissions.map((p) => p.name) : [])),
|
||||
});
|
||||
}
|
||||
//****************** */
|
||||
//****************** */
|
||||
// private checkUserPerm(user: User, perm: PermissionEnum) {
|
||||
// return user.roles.some((role) => role?.permissions?.some((p) => p.name === perm));
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user