Skip to content

Commit

Permalink
feat: add create user with provider service
Browse files Browse the repository at this point in the history
  • Loading branch information
LhonRafaat committed Oct 11, 2024
1 parent 3a9338b commit d3daec4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/modules/auth/dto/register.payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class RegisterPayload {
@IsString()
avatar: string;

// remove isAdmin in production, this is for testing purposes
@ApiProperty()
@IsOptional()
isAdmin?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/auth/strategies/google.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EnvConfig } from '../../../config.type';

@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
constructor(private configService: ConfigService<EnvConfig>) {
constructor(readonly configService: ConfigService<EnvConfig>) {
super({
clientID: configService.get('GOOGLE_CLIENT_ID'),
clientSecret: configService.get('GOOGLE_CLIENT_SECRET'),
Expand Down
8 changes: 7 additions & 1 deletion src/modules/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TUser } from './user.model';
import { RegisterPayload } from '../auth/dto/register.payload';
import * as bcrypt from 'bcrypt';
import { IRequest, TResponse } from '../../common/helper/common-types';
import { OAuthRegisterPayload } from '../auth/dto/oauth-register-payload';

@Injectable()
export class UsersService {
Expand Down Expand Up @@ -44,6 +45,12 @@ export class UsersService {
});
}

async createWithProvider(payload: OAuthRegisterPayload) {
return await this.userModel.create({
...payload,
});
}

async update(id: string, payload: UpdateUserDto): Promise<TUser> {
await this.findOne(id);
return await this.userModel.findByIdAndUpdate(id, payload, {
Expand Down Expand Up @@ -71,7 +78,6 @@ export class UsersService {

async findByEmail(email: string): Promise<TUser> {
const user = await this.userModel.findOne({ email }).select('+password');
if (!user) throw new BadRequestException('User not found');
return user;
}

Expand Down

0 comments on commit d3daec4

Please sign in to comment.