fix: change the role refrence in database

This commit is contained in:
mahyargdz
2025-01-19 11:55:52 +03:30
parent 58c9bfa912
commit f88ccec546
10 changed files with 119 additions and 14 deletions
+2 -2
View File
@@ -3,8 +3,8 @@ import { ConfigModule } from "@nestjs/config";
import { TypeOrmModule } from "@nestjs/typeorm";
import { DatabaseConfigs } from "./configs/typeorm.config";
import { UsersModule } from './modules/users/users.module';
import { TicketsModule } from './modules/tickets/tickets.module';
import { TicketsModule } from "./modules/tickets/tickets.module";
import { UsersModule } from "./modules/users/users.module";
@Module({
imports: [
+1 -1
View File
@@ -12,11 +12,11 @@ export function DatabaseConfigs(): TypeOrmModuleAsyncOptions {
database: configService.getOrThrow<string>("DB_NAME"),
username: configService.getOrThrow<string>("DB_USER"),
password: configService.getOrThrow<string>("DB_PASS"),
autoLoadEntities: true,
synchronize: true,
logging: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true,
migrationsTableName: "typeorm_migrations",
migrationsRun: false,
autoLoadEntities: true,
};
},
};
+1 -1
View File
@@ -14,7 +14,7 @@ async function bootstrap() {
getSwaggerDocument(app);
const PORT = configService.getOrThrow<number>("PORT");
await app.listen(PORT, () => {
await app.listen(PORT, "0.0.0.0", () => {
logger.log(`Server running on http://localhost:${PORT}`);
logger.log(`Swagger running on http://localhost:${PORT}/api-docs`);
});
+4 -2
View File
@@ -1,4 +1,6 @@
import { Controller } from '@nestjs/common';
import { Controller } from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
@Controller('tickets')
@Controller("tickets")
@ApiTags("users")
export class TicketsController {}
+2 -1
View File
@@ -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()
+3 -2
View File
@@ -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;
}
+2
View File
@@ -1,4 +1,6 @@
import { Controller } from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
@Controller("users")
@ApiTags("users")
export class UsersController {}
+2 -1
View File
@@ -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],