-
Notifications
You must be signed in to change notification settings - Fork 2
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
BatuhanIlhan
committed
Nov 18, 2023
1 parent
ca1f4e5
commit bf4dedf
Showing
8 changed files
with
122 additions
and
2 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,61 @@ | ||
import * as bcrypt from 'bcrypt'; | ||
import { Poll } from '../../poll/entities/poll.entity'; | ||
import { | ||
Entity, | ||
Column, | ||
PrimaryGeneratedColumn, | ||
BeforeInsert, | ||
BeforeUpdate, | ||
OneToMany, | ||
Relation, | ||
JoinTable, | ||
ManyToMany, | ||
} from 'typeorm'; | ||
|
||
const SALT_ROUNDS = 10; | ||
|
||
@Entity('moderators') | ||
export class User { | ||
@PrimaryGeneratedColumn('uuid') | ||
id: string; | ||
|
||
@Column({ nullable: false, unique: true }) | ||
email: string; | ||
|
||
@Column({ unique: true, nullable: true, default: null }) | ||
username: string; | ||
|
||
@Column({ nullable: false, default: false }) | ||
isVerified: boolean; | ||
|
||
@Column({ nullable: true }) | ||
password: string; | ||
|
||
@Column({ nullable: true }) | ||
verification_code: number; | ||
|
||
@Column({ nullable: true }) | ||
reset_password_token: number; | ||
|
||
@BeforeInsert() | ||
async hashPasswordBeforeInsert() { | ||
if (this.password) { | ||
this.password = await this.getEncryptedPassword(this.password); | ||
} | ||
} | ||
|
||
@BeforeUpdate() | ||
async hashPasswordBeforeUpdate() { | ||
if (this.password) { | ||
this.password = await this.getEncryptedPassword(this.password); | ||
} | ||
} | ||
|
||
async getEncryptedPassword(password: string): Promise<string> { | ||
return bcrypt.hash(password, SALT_ROUNDS); | ||
} | ||
|
||
async compareEncryptedPassword(password: string): Promise<boolean> { | ||
return bcrypt.compare(password, this.password); | ||
} | ||
} |
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,20 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { ModeratorController } from './moderator.controller'; | ||
import { ModeratorService } from './moderator.service'; | ||
|
||
describe('ModeratorController', () => { | ||
let controller: ModeratorController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [ModeratorController], | ||
providers: [ModeratorService], | ||
}).compile(); | ||
|
||
controller = module.get<ModeratorController>(ModeratorController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
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 { Controller } from '@nestjs/common'; | ||
import { ModeratorService } from './moderator.service'; | ||
|
||
@Controller('moderator') | ||
export class ModeratorController { | ||
constructor(private readonly moderatorService: ModeratorService) {} | ||
} |
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,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ModeratorService } from './moderator.service'; | ||
import { ModeratorController } from './moderator.controller'; | ||
|
||
@Module({ | ||
controllers: [ModeratorController], | ||
providers: [ModeratorService], | ||
}) | ||
export class ModeratorModule {} |
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,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { ModeratorService } from './moderator.service'; | ||
|
||
describe('ModeratorService', () => { | ||
let service: ModeratorService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ModeratorService], | ||
}).compile(); | ||
|
||
service = module.get<ModeratorService>(ModeratorService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
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,4 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class ModeratorService {} |