-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
97 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { UserService } from 'src/user/user.service' | ||
import { BadRequestException, Body, Controller, NotFoundException, Post } from '@nestjs/common' | ||
import { ApiBadRequestResponse, ApiNotFoundResponse, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger' | ||
import { RegisNewUserDto } from './dto/regis-new-user.dto' | ||
import { RegisNewUserResponseDo } from './dto/regis-new-user-res.dto' | ||
import { ApiService } from 'src/api/api.service' | ||
import { UserDocument } from 'src/schema/User.schema' | ||
import { OTPService } from 'src/api/otp.service' | ||
import { LocationService } from 'src/location/location.service' | ||
|
||
@Controller('auth') | ||
@ApiTags('Authentication') | ||
export class AuthController { | ||
constructor( | ||
private userService: UserService, | ||
private apiService: ApiService, | ||
private otpService: OTPService, | ||
private locationService: LocationService | ||
) {} | ||
|
||
@Post('regis') | ||
@ApiOperation({ summary: 'Register new user' }) | ||
@ApiResponse({ status: 201, type: RegisNewUserResponseDo }) | ||
@ApiBadRequestResponse({ description: 'LaserID and/or natioalID is/are in wrong format' }) | ||
@ApiNotFoundResponse({ description: 'Not found in national external API' }) | ||
async registerNewUser(@Body() { laserID, nationalID, phoneNumber, preferedLocation }: RegisNewUserDto) { | ||
const personData = await this.apiService.searchByNationalID(nationalID, laserID) | ||
const existingUser = await this.userService.findByNationalID(nationalID) | ||
if (existingUser && existingUser.isPhoneVerify) throw new BadRequestException('User already register') | ||
|
||
const preferedLocationDoc = await this.locationService.findById(preferedLocation) | ||
if (!preferedLocation) throw new NotFoundException('Prefered location is not found') | ||
|
||
let user: UserDocument | ||
if (!existingUser) { | ||
user = await this.userService.createUser(personData, phoneNumber, preferedLocationDoc) | ||
} else { | ||
existingUser.phoneNumber = phoneNumber | ||
existingUser.preferedLocation = preferedLocationDoc | ||
user = await existingUser.save() | ||
} | ||
// const refCode = await this.otpService.generatedAndSentOTP(user.id, phoneNumber) | ||
// return { refCode } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from '@nestjs/common' | ||
import { UserModule } from 'src/user/user.module' | ||
import { AuthService } from './auth.service' | ||
import { AuthController } from './auth.controller' | ||
import { LocationModule } from 'src/location/location.module' | ||
import { ApiModule } from 'src/api/api.module' | ||
|
||
@Module({ | ||
imports: [UserModule, LocationModule, ApiModule], | ||
providers: [AuthService], | ||
controllers: [AuthController], | ||
}) | ||
export class AuthModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Injectable } from '@nestjs/common' | ||
import { UserService } from 'src/user/user.service' | ||
|
||
@Injectable() | ||
export class AuthService { | ||
constructor(private userService: UserService) {} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters