fix: change the role refrence in database
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { BaseEntity, Column, Entity } from "typeorm";
|
||||
import { Column, Entity } from "typeorm";
|
||||
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { RoleEnum } from "../enums/role.enum";
|
||||
|
||||
@Entity()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Column, Entity, OneToOne } from "typeorm";
|
||||
import { Column, Entity, JoinColumn, OneToOne } from "typeorm";
|
||||
|
||||
import { Role } from "./role.entity";
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
@@ -26,6 +26,7 @@ export class User extends BaseEntity {
|
||||
@Column({ type: "varchar", length: 100 })
|
||||
nationalCode: string;
|
||||
|
||||
@OneToOne(() => Role, { eager: true, cascade: true, onDelete: "SET NULL" })
|
||||
@JoinColumn()
|
||||
@OneToOne(() => Role, { eager: true, cascade: true, onDelete: "RESTRICT", nullable: false })
|
||||
role: Role;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Controller } from "@nestjs/common";
|
||||
import { ApiTags } from "@nestjs/swagger";
|
||||
|
||||
@Controller("users")
|
||||
@ApiTags("users")
|
||||
export class UsersController {}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
|
||||
import { Role } from "./entities/role.entity";
|
||||
import { User } from "./entities/user.entity";
|
||||
import { UserRepository } from "./providers/users.repository";
|
||||
import { UsersService } from "./providers/users.service";
|
||||
import { UsersController } from "./users.controller";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([User])],
|
||||
imports: [TypeOrmModule.forFeature([User, Role])],
|
||||
providers: [UsersService, UserRepository],
|
||||
controllers: [UsersController],
|
||||
exports: [UsersService, TypeOrmModule],
|
||||
|
||||
Reference in New Issue
Block a user