Created
September 29, 2020 13:29
-
-
Save talesmgodois/1fb2b532b614df3b86acea6ce5e7d711 to your computer and use it in GitHub Desktop.
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 characters
import { Model } from 'mongoose'; | |
import { Injectable } from '@nestjs/common'; | |
import { InjectModel } from '@nestjs/mongoose'; | |
import { Cat, CatDocument } from './schemas/cat.schema'; | |
import { CreateCatDto } from './dto/create-cat.dto'; | |
@Injectable() | |
export class CatsService { | |
constructor(@InjectModel(Cat.name) private catModel: Model<CatDocument>) {} | |
async create(createCatDto: CreateCatDto): Promise<Cat> { | |
const createdCat = new this.catModel(createCatDto); | |
return createdCat.save(); | |
} | |
async findAll(): Promise<Cat[]> { | |
return this.catModel.find().exec(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment