To run the project on a local environment with a local backend server, use the following URL: http://localhost:5000/
- To run the project on a local environment with a local backend server:
npm start
The entry point for the backend is index.ts
.
This project uses Postgres as its database.
To get started, follow these steps:
- Install the project dependencies using:
npm install
- one-to-one relationship
- Each User can be associated with at most one Customer, and each Customer can be associated with at most one User. The relationship is bidirectional, meaning you can navigate from a User to its associated Customer and vice versa. The @JoinColumn() decorator specifies the foreign key column in the User entity that links to the Customer entity. The eager: true option indicates that the related Customer entity should be loaded eagerly when querying for a User.
- so in user entity
- @OneToOne(() => Customer, (customer) => customer.user, { eager: true }) @JoinColumn() Customer_ID!: Customer;
- & in order entity
- @OneToOne((type) => User, (user: any) => user.Customer_ID) user!: User;
- one-to-many & many-to-one relationship
- Order that has a one-to-many relationship with the User entity. Each User can have multiple orders, and each order belongs to only one user.
- so in user entity
- @OneToMany(() => Order, (order) => order.user, { eager: true }) Order_ID!: Order[];
- & in order entity
- @ManyToOne(() => User, (user:any) => user.Order_ID) user!: User;
- many-to-many relationship
- A user can have multiple permissions, and a permission can be associated with multiple users.
- so in user entity
- @ManyToMany(() => Permission, (permission) => permission.users) @JoinTable() permissions!: Permission[];
- & in permission entity
- @ManyToMany(() => User, (user) => user.permissions) users!: User[];
- Incase of entity errors at runtime
- error: error: relation "tb_orders" does not exist
- QueryFailedError: relation "tb_orders" does not exist
- run this command to create and apply migrations-> npm run typeorm migration:run