Skip to content
Snippets Groups Projects
Commit f52e59ca authored by Martin Korec's avatar Martin Korec
Browse files

fix: updated category CRUD

parent 4300d54d
No related branches found
No related tags found
No related merge requests found
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Delete,
} from '@nestjs/common';
import { CategoriesService } from './categories.service'; import { CategoriesService } from './categories.service';
import { CreateCategoryDto } from './dto/create-category.dto'; import { CreateCategoryDto } from './dto/create-category.dto';
import { UpdateCategoryDto } from './dto/update-category.dto'; import { UpdateCategoryDto } from './dto/update-category.dto';
...@@ -8,20 +16,20 @@ export class CategoriesController { ...@@ -8,20 +16,20 @@ export class CategoriesController {
constructor(private readonly categoriesService: CategoriesService) {} constructor(private readonly categoriesService: CategoriesService) {}
@Post() @Post()
create(@Body() createCategoryDto: CreateCategoryDto) { async create(@Body() createCategoryDto: CreateCategoryDto) {
return this.categoriesService.create(createCategoryDto); return await this.categoriesService.create(createCategoryDto);
} }
@Get() @Get()
findAll() { async findAll() {
return this.categoriesService.findAll(); return await this.categoriesService.findAll();
} }
@Get(':id') @Get(':id')
findOne(@Param('id') id: string) { async findOne(@Param('id') id: string) {
return this.categoriesService.findOne(id); return await this.categoriesService.findOne(id);
} }
/* /*
@Patch(':id') @Patch(':id')
update(@Param('id') id: string, @Body() updateCategoryDto: UpdateCategoryDto) { update(@Param('id') id: string, @Body() updateCategoryDto: UpdateCategoryDto) {
return this.categoriesService.update(id, updateCategoryDto); return this.categoriesService.update(id, updateCategoryDto);
......
...@@ -9,7 +9,7 @@ export class CategoriesService { ...@@ -9,7 +9,7 @@ export class CategoriesService {
create(createCategoryDto: CreateCategoryDto) { create(createCategoryDto: CreateCategoryDto) {
return this.prisma.category.create({ return this.prisma.category.create({
data: createCategoryDto data: createCategoryDto,
}); });
} }
...@@ -18,32 +18,32 @@ export class CategoriesService { ...@@ -18,32 +18,32 @@ export class CategoriesService {
} }
findOne(id: string) { findOne(id: string) {
return this.prisma.category.findUnique({ return this.prisma.category.findUnique({
where: { where: {
id id,
} },
}); });
} }
update(id: string, updateCategoryDto: UpdateCategoryDto) { update(id: string, updateCategoryDto: UpdateCategoryDto) {
return this.prisma.category.update({ return this.prisma.category.update({
where: { where: {
id id,
}, },
data: { data: {
...updateCategoryDto ...updateCategoryDto,
} },
}); });
} }
remove(id: string) { remove(id: string) {
return this.prisma.category.update({ return this.prisma.category.update({
where: { where: {
id id,
}, },
data: { data: {
deletedAt: new Date() deletedAt: new Date(),
} },
}); });
} }
} }
export class Category {} import { Category } from '@prisma/client';
export class CategoryEntity implements Category {
id: string;
createdAt: Date;
updatedAt: Date;
deletedAt: Date;
name: string;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment