Last active
August 8, 2025 06:36
-
-
Save victorcrbt/d6f376635bfb65484936d75e7e6959ac to your computer and use it in GitHub Desktop.
Revisions
-
victorcrbt revised this gist
May 13, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export default class Client { @PrimaryGeneratedColumn() id: number; @Column() name: string; @Column() -
victorcrbt created this gist
May 13, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable } from 'typeorm'; import Company from './Company'; @Entity('clients') export default class Client { @PrimaryGeneratedColumn() id: number; @Colum() name: string; @Column() email: string; @Column() document: string; @Column() password: string; @ManyToMany(() => Company, company => company.clients) @JoinTable({ name: 'clients_companies_relation', joinColumn: { name: 'client_id', referencedColumnName: 'id', }, inverseJoinColumn: { name: 'company_id', referencedColumnName: 'id', } }) companies: Company[]; } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ import { getRepository, Repository } from 'typeorm'; import Client from '../entities/Client'; interface IClientsRepository { findById(id: number): Promise<Client>; } export default class ClientsRepositoryimplements IClientsRepository { private ormRepository: Repository<Client>; constructor() { this.ormRepository = getRepository(Client); } public async findById (id: number): Promise<Client> { const client = await this.ormRepository.findOne(id, { relations: ['companies'] }); return client; } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ import { Entity, PrimaryGeneratedColumn, Column, ManyToMany } from 'typeorm'; import Client from './Client'; @Entity('companies') export default class Company { @PrimaryGeneratedColumn() id: number; @Colum() company_name: string; @Column() document: string; @Column() phone: string; @ManyToMany(() => Client, client => client.companies) clients: Client[]; }