Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
feat: finish register
Browse files Browse the repository at this point in the history
  • Loading branch information
YanceyOfficial committed Jan 29, 2020
1 parent 05671d8 commit d0b8c60
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
21 changes: 21 additions & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,27 @@ type LiveTourModel {
updatedAt: String!
}

input LoginInput {
email: String!
password: String!
}

type LoginModel {
_id: ID!
authorization: String!
username: String!
email: String!
password: String!
role: Float!
avaterUrl: String!
phoneNumber: String!
isTOTP: Boolean!
createdAt: String!
updatedAt: String!
}

type Mutation {
register(input: LoginInput!): LoginModel!
createAnnouncement(input: CreateAnnouncementInput!): AnnouncementModel!
updateAnnouncementById(input: UpdateAnnouncementInput!): AnnouncementModel!
deleteAnnouncementById(id: ID!): AnnouncementModel!
Expand Down Expand Up @@ -137,6 +157,7 @@ type PlayerModel {
}

type Query {
login(input: LoginInput!): LoginModel!
getAnnouncements: [AnnouncementModel!]!
getAnnouncementById(id: ID!): AnnouncementModel!
getAllSMS: [SMSModel!]!
Expand Down
5 changes: 2 additions & 3 deletions src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common'
import { JwtModule } from '@nestjs/jwt'
import { PassportModule } from '@nestjs/passport'
import { AuthController } from './auth.controller'
import { AuthResolver } from './auth.resolver'
import { AuthService } from './auth.service'
import { UsersModule } from '../users/users.module'
import { JwtStrategy } from './jwt.strategy'
Expand All @@ -26,8 +26,7 @@ const PassPortModule = PassportModule.register({
inject: [ConfigService],
}),
],
controllers: [AuthController],
providers: [AuthService, JwtStrategy],
providers: [AuthResolver, AuthService, JwtStrategy],
exports: [AuthService, PassPortModule],
})
export class AuthModule {}
5 changes: 5 additions & 0 deletions src/auth/auth.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ export class AuthResolver {
public async login(@Args('input') input: LoginInput) {
return this.authService.login(input)
}

@Mutation(() => LoginModel)
public async register(@Args('input') input: LoginInput) {
return this.authService.register(input)
}
}
7 changes: 3 additions & 4 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Injectable, ConflictException, UnauthorizedException } from '@nestjs/co
import { JwtService } from '@nestjs/jwt'
import { UsersService } from '../users/users.service'
import { Roles } from '../users/interfaces/user.interface'
import { CreateUserDto } from '../users/dtos/createUser.dto'
import { LoginInput } from './dtos/login.input'

@Injectable()
Expand All @@ -26,14 +25,14 @@ export class AuthService {
throw new UnauthorizedException()
}

public async register(createUserDto: CreateUserDto) {
const curUser = await this.usersService.findOneByEmail(createUserDto.email)
public async register(registerInput: LoginInput) {
const curUser = await this.usersService.findOneByEmail(registerInput.email)

if (curUser) {
throw new ConflictException()
} else {
const count = await this.usersService.getUserCount()
const params = count === 0 ? { ...createUserDto, role: Roles.SUPERUSER } : createUserDto
const params = count === 0 ? { ...registerInput, role: Roles.SUPERUSER } : registerInput
this.usersService.create(params)
}
}
Expand Down

0 comments on commit d0b8c60

Please sign in to comment.