Created
September 20, 2019 03:44
-
-
Save viniciusvelasco/a50b1c324b1d711ec8ef36a031c893e1 to your computer and use it in GitHub Desktop.
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
@Entity('tblBook') | |
export class Book { | |
@PrimaryColumn({ name: 'ID_BOOK', type: 'uniqueidentifier' }) | |
id: string; | |
@Column({ name: 'DS_TITLE', type: 'nvarchar' }) | |
title: string; | |
@Column({ name: 'DS_SUBTITILE', type: 'nvarchar' }) | |
subtitle: string; | |
@ManyToOne(() => Category, m => m.books) | |
@JoinColumn({ name: 'ID_CATEGORY' }) | |
category: Category; | |
} |
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
import { Injectable } from '@nestjs/common'; | |
import { InjectRepository } from '@nestjs/typeorm'; | |
import { Repository, MoreThanOrEqual, Equal } from 'typeorm'; | |
import { Category } from './category.entity'; | |
@Injectable() | |
export class ForragemPastoService { | |
constructor( | |
@InjectRepository(Category) | |
private readonly repository: Repository<Category>, | |
) {} | |
async save(category: Category): Promise<Category> { | |
await this.repository.save(category); | |
const data = await this.repository.findOne(category.id, { | |
relations: ['books'], | |
}); | |
return data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment