mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-10-24 21:17:57 +00:00
feat: handle google login
This commit is contained in:
@@ -22,10 +22,10 @@ export class User extends BaseEntity {
|
||||
@Column('varchar', { length: 255, nullable: true, name: 'email' })
|
||||
email!: string;
|
||||
|
||||
@Column('varchar', { length: 255, name: 'phone_number' })
|
||||
@Column('varchar', { length: 255, name: 'phone_number', nullable: true })
|
||||
phoneNumber!: string;
|
||||
|
||||
@Column('varchar', { length: 10, name: 'country_code' })
|
||||
@Column('varchar', { length: 10, name: 'country_code', nullable: true })
|
||||
countryCode!: string;
|
||||
|
||||
@Column('varchar', { length: 255, name: 'password', nullable: true })
|
||||
@@ -40,6 +40,12 @@ export class User extends BaseEntity {
|
||||
@Column('varchar', { length: 255, nullable: true, name: 'apple_id' })
|
||||
appleId!: string;
|
||||
|
||||
@Column('boolean', { default: false, name: 'is_phone_verified' })
|
||||
isPhoneVerified!: boolean;
|
||||
|
||||
@Column('boolean', { default: false, name: 'is_email_verified' })
|
||||
isEmailVerified!: boolean;
|
||||
|
||||
@Column('boolean', { default: false, name: 'is_profile_completed' })
|
||||
isProfileCompleted!: boolean;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { BadRequestException, forwardRef, Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import { FindOptionsWhere } from 'typeorm';
|
||||
import { Transactional } from 'typeorm-transactional';
|
||||
import { CustomerNotificationSettings } from '~/customer/entities/customer-notification-settings.entity';
|
||||
import { CustomerService } from '~/customer/services';
|
||||
import { Guardian } from '~/guardian/entities/guradian.entity';
|
||||
@@ -75,8 +76,36 @@ export class UserService {
|
||||
return this.userRepository.update(userId, { password: passcode, salt, isProfileCompleted: true });
|
||||
}
|
||||
|
||||
setPhoneNumber(userId: string, phoneNumber: string, countryCode: string) {
|
||||
this.logger.log(`Setting phone number ${phoneNumber} for user ${userId}`);
|
||||
return this.userRepository.update(userId, { phoneNumber, countryCode });
|
||||
}
|
||||
|
||||
verifyPhoneNumber(userId: string) {
|
||||
this.logger.log(`Verifying phone number for user ${userId}`);
|
||||
return this.userRepository.update(userId, { isPhoneVerified: true });
|
||||
}
|
||||
|
||||
@Transactional()
|
||||
async createGoogleUser(googleId: string, email: string) {
|
||||
this.logger.log(`Creating google user with googleId ${googleId} and email ${email}`);
|
||||
const user = await this.userRepository.createUser({ googleId, email, roles: [Roles.GUARDIAN] });
|
||||
|
||||
await this.customerService.createCustomer(
|
||||
{
|
||||
guardian: Guardian.create({ id: user.id }),
|
||||
notificationSettings: new CustomerNotificationSettings(),
|
||||
},
|
||||
user,
|
||||
);
|
||||
|
||||
return this.findUserOrThrow({ id: user.id });
|
||||
}
|
||||
|
||||
@Transactional()
|
||||
async verifyUserAndCreateCustomer(user: User) {
|
||||
this.logger.log(`Verifying user ${user.id} and creating customer`);
|
||||
await this.userRepository.update(user.id, { isPhoneVerified: true });
|
||||
await this.customerService.createCustomer(
|
||||
{
|
||||
guardian: Guardian.create({ id: user.id }),
|
||||
|
||||
Reference in New Issue
Block a user