Created
July 14, 2019 15:14
-
-
Save hzburki/449a1e19afbe97105dcb17d3e1251158 to your computer and use it in GitHub Desktop.
Contains code with database interactions - NestJS SequelizeJS
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, Inject } from '@nestjs/common'; | |
import { USER_REPOSITORY } from '../utils/constants'; | |
import { User } from './user.entity'; | |
import { CreateUserDto } from './dto/index'; | |
@Injectable() | |
export class UserService { | |
constructor( | |
@Inject(USER_REPOSITORY) private readonly userRepository: typeof User, | |
) {} | |
async getAllUsers(): Promise<User[]> { | |
return await this.userRepository.findAll<User>(); | |
} | |
async createUser(createUser: CreateUserDto): Promise<User> { | |
return await this.userRepository.create<User>(createUser); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment