Skip to content

Instantly share code, notes, and snippets.

@chnirt
Last active June 19, 2019 03:49
Show Gist options
  • Save chnirt/994b0e9351a6dbbce21813cc701d4f5c to your computer and use it in GitHub Desktop.
Save chnirt/994b0e9351a6dbbce21813cc701d4f5c to your computer and use it in GitHub Desktop.
NestJs
import { Injectable } from '@nestjs/common';
import { UserInput } from './user.input';
import { InjectRepository } from '@nestjs/typeorm';
import { User } from './user.entity';
import { MongoRepository } from 'typeorm';
import * as uuid from 'uuid';
@Injectable()
export class UserService {
constructor(
@InjectRepository(User)
private readonly userRepository: MongoRepository<User>,
) {}
async findAll(): Promise<User[]> {
return this.userRepository.find();
}
async create(input: UserInput): Promise<User> {
const user = new User();
user._id = uuid.v4();
user.username = input.username;
user.password = input.password;
return this.userRepository.save(user);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment