Skip to content

Instantly share code, notes, and snippets.

@hzburki
Created July 14, 2019 15:14
Show Gist options
  • Save hzburki/449a1e19afbe97105dcb17d3e1251158 to your computer and use it in GitHub Desktop.
Save hzburki/449a1e19afbe97105dcb17d3e1251158 to your computer and use it in GitHub Desktop.
Contains code with database interactions - NestJS SequelizeJS
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