25 lines
666 B
TypeScript
25 lines
666 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { Repository } from 'typeorm';
|
|
import { NewItemInput } from './dto/new-item.input';
|
|
import { Item } from './items.entity';
|
|
|
|
@Injectable()
|
|
export class ItemsService {
|
|
constructor(
|
|
@InjectRepository(Item)
|
|
private itemRepository: Repository<Item>,
|
|
) {}
|
|
|
|
async getItem(id: string): Promise<Item | undefined> {
|
|
return this.itemRepository.findOne(id);
|
|
}
|
|
|
|
async createItem(input: NewItemInput): Promise<Item> {
|
|
const item = new Item();
|
|
item.name = input.name;
|
|
item.notes = input.notes;
|
|
return this.itemRepository.save(item);
|
|
}
|
|
}
|