added categories resource
This commit is contained in:
parent
c90276982f
commit
50e2b6e2b7
8 changed files with 166 additions and 2 deletions
35
src/categories/categories.service.ts
Normal file
35
src/categories/categories.service.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateCategoryDto } from './dto/create-category.dto';
|
||||
import { UpdateCategoryDto } from './dto/update-category.dto';
|
||||
import { CategoryDataService } from './category-data.service';
|
||||
import { Category } from './entities/category.entity';
|
||||
|
||||
@Injectable()
|
||||
export class CategoriesService {
|
||||
public constructor(private categoryDataService: CategoryDataService) { }
|
||||
|
||||
public async findAll(): Promise<Category[]> {
|
||||
return await this.categoryDataService.getAll();
|
||||
}
|
||||
|
||||
public async findById(id: string): Promise<Category> {
|
||||
const category = await this.categoryDataService.getById(id);
|
||||
if (!category) {
|
||||
throw new Error('No category found');
|
||||
}
|
||||
|
||||
return category;
|
||||
}
|
||||
|
||||
public async create(category: CreateCategoryDto): Promise<Category> {
|
||||
return await this.categoryDataService.create(category.name);
|
||||
}
|
||||
|
||||
public async update(category: UpdateCategoryDto): Promise<Category> {
|
||||
return await this.categoryDataService.update(category);
|
||||
}
|
||||
|
||||
public async remove(id: string): Promise<void> {
|
||||
await this.categoryDataService.delete(id);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue