Last active
October 23, 2019 00:18
-
-
Save adsonrocha/b7239958c37166d75f685c943ce2574f to your computer and use it in GitHub Desktop.
User service with mongoose model injected
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 { Injectable } from '@nestjs/common'; | |
import { InjectModel } from '@nestjs/mongoose'; | |
import { User } from './user.model'; | |
import { Model } from 'mongoose'; | |
@Injectable() | |
export class UserService { | |
constructor( | |
@InjectModel('User') private readonly userModel: Model<User>, | |
) { | |
} | |
async create(doc: User) { | |
const result = await new this.userModel(doc).save(); | |
return result.id; | |
} | |
async findById(id: number) { | |
// ... | |
} | |
async update(user: User) { | |
// ... | |
} | |
async remove(user: User) { | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment