style: apply standard ESLint & Prettier formatting across backend
Deploy Canina / deploy (push) Successful in 4m58s
Deploy Canina / deploy (push) Successful in 4m58s
This commit is contained in:
1 parent
ae636c8b03
commit
62bd8811fa
66 files changed
+1398
-607
No files matched your search
@@ -33,20 +33,28 @@ export class AuthService {
|
||||
const savedCode = await this.redisService.get(`otp:${phoneNumber}`);
|
||||
|
||||
if (!savedCode) {
|
||||
throw new BadRequestException({ message: 'کد تایید منقضی شده است', error: 'OTP_EXPIRED' });
|
||||
throw new BadRequestException({
|
||||
message: 'کد تایید منقضی شده است',
|
||||
error: 'OTP_EXPIRED',
|
||||
});
|
||||
}
|
||||
|
||||
if (savedCode !== code) {
|
||||
throw new BadRequestException({ message: 'کد تایید اشتباه است', error: 'OTP_INVALID' });
|
||||
throw new BadRequestException({
|
||||
message: 'کد تایید اشتباه است',
|
||||
error: 'OTP_INVALID',
|
||||
});
|
||||
}
|
||||
|
||||
await this.redisService.del(`otp:${phoneNumber}`);
|
||||
|
||||
let user = await this.prisma.user.findUnique({ where: { mobile: phoneNumber } });
|
||||
let user = await this.prisma.user.findUnique({
|
||||
where: { mobile: phoneNumber },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
user = await this.prisma.user.create({
|
||||
data: {
|
||||
data: {
|
||||
mobile: phoneNumber,
|
||||
firstName: 'کاربر',
|
||||
lastName: 'جدید',
|
||||
@@ -70,15 +78,25 @@ export class AuthService {
|
||||
async register(registerDto: any) {
|
||||
const { firstName, lastName, email, mobile, password } = registerDto;
|
||||
|
||||
const existingUser = await this.prisma.user.findUnique({ where: { mobile } });
|
||||
const existingUser = await this.prisma.user.findUnique({
|
||||
where: { mobile },
|
||||
});
|
||||
if (existingUser) {
|
||||
throw new BadRequestException({ message: 'کاربری با این شماره موبایل قبلا ثبت نام کرده است', error: 'MOBILE_EXISTS' });
|
||||
throw new BadRequestException({
|
||||
message: 'کاربری با این شماره موبایل قبلا ثبت نام کرده است',
|
||||
error: 'MOBILE_EXISTS',
|
||||
});
|
||||
}
|
||||
|
||||
if (email) {
|
||||
const existingEmail = await this.prisma.user.findUnique({ where: { email } });
|
||||
const existingEmail = await this.prisma.user.findUnique({
|
||||
where: { email },
|
||||
});
|
||||
if (existingEmail) {
|
||||
throw new BadRequestException({ message: 'کاربری با این ایمیل قبلا ثبت نام کرده است', error: 'EMAIL_EXISTS' });
|
||||
throw new BadRequestException({
|
||||
message: 'کاربری با این ایمیل قبلا ثبت نام کرده است',
|
||||
error: 'EMAIL_EXISTS',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,16 +129,25 @@ export class AuthService {
|
||||
|
||||
const user = await this.prisma.user.findUnique({ where: { mobile } });
|
||||
if (!user) {
|
||||
throw new BadRequestException({ message: 'نام کاربری یا رمز عبور اشتباه است', error: 'INVALID_CREDENTIALS' });
|
||||
throw new BadRequestException({
|
||||
message: 'نام کاربری یا رمز عبور اشتباه است',
|
||||
error: 'INVALID_CREDENTIALS',
|
||||
});
|
||||
}
|
||||
|
||||
if (!user.password) {
|
||||
throw new BadRequestException({ message: 'شما با رمز عبور ثبت نام نکردهاید. لطفاً با موبایل وارد شوید', error: 'NO_PASSWORD' });
|
||||
throw new BadRequestException({
|
||||
message: 'شما با رمز عبور ثبت نام نکردهاید. لطفاً با موبایل وارد شوید',
|
||||
error: 'NO_PASSWORD',
|
||||
});
|
||||
}
|
||||
|
||||
const isMatch = await bcrypt.compare(password, user.password);
|
||||
if (!isMatch) {
|
||||
throw new BadRequestException({ message: 'نام کاربری یا رمز عبور اشتباه است', error: 'INVALID_CREDENTIALS' });
|
||||
throw new BadRequestException({
|
||||
message: 'نام کاربری یا رمز عبور اشتباه است',
|
||||
error: 'INVALID_CREDENTIALS',
|
||||
});
|
||||
}
|
||||
|
||||
const payload = { sub: user.id, phoneNumber: user.mobile };
|
||||
@@ -136,16 +163,30 @@ export class AuthService {
|
||||
}
|
||||
|
||||
async adminLogin(body: any) {
|
||||
if (body.email === 'admin@canino-iran.com' && body.password === 'admin123') {
|
||||
const payload = { sub: '12345678-1234-1234-1234-123456789012', email: body.email, role: 'Admin' };
|
||||
if (
|
||||
body.email === 'admin@canino-iran.com' &&
|
||||
body.password === 'admin123'
|
||||
) {
|
||||
const payload = {
|
||||
sub: '12345678-1234-1234-1234-123456789012',
|
||||
email: body.email,
|
||||
role: 'Admin',
|
||||
};
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
user: { id: '12345678-1234-1234-1234-123456789012', email: body.email, role: 'Admin' },
|
||||
user: {
|
||||
id: '12345678-1234-1234-1234-123456789012',
|
||||
email: body.email,
|
||||
role: 'Admin',
|
||||
},
|
||||
accessToken: this.jwtService.sign(payload),
|
||||
},
|
||||
};
|
||||
}
|
||||
throw new BadRequestException({ message: 'ایمیل یا رمز عبور اشتباه است', error: 'INVALID_CREDENTIALS' });
|
||||
throw new BadRequestException({
|
||||
message: 'ایمیل یا رمز عبور اشتباه است',
|
||||
error: 'INVALID_CREDENTIALS',
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user