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 { CreateCategoryDto } from './dto/create-category.dto';
import { UpdateCategoryDto } from './dto/update-category.dto';
......@@ -8,20 +16,20 @@ export class CategoriesController {
constructor(private readonly categoriesService: CategoriesService) {}
@Post()
create(@Body() createCategoryDto: CreateCategoryDto) {
return this.categoriesService.create(createCategoryDto);
async create(@Body() createCategoryDto: CreateCategoryDto) {
return await this.categoriesService.create(createCategoryDto);
}
@Get()
findAll() {
return this.categoriesService.findAll();
async findAll() {
return await this.categoriesService.findAll();
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.categoriesService.findOne(id);
async findOne(@Param('id') id: string) {
return await this.categoriesService.findOne(id);
}
/*
/*
@Patch(':id')
update(@Param('id') id: string, @Body() updateCategoryDto: UpdateCategoryDto) {
return this.categoriesService.update(id, updateCategoryDto);
......
......@@ -9,7 +9,7 @@ export class CategoriesService {
create(createCategoryDto: CreateCategoryDto) {
return this.prisma.category.create({
data: createCategoryDto
data: createCategoryDto,
});
}
......@@ -18,32 +18,32 @@ export class CategoriesService {
}
findOne(id: string) {
return this.prisma.category.findUnique({
return this.prisma.category.findUnique({
where: {
id
}
id,
},
});
}
update(id: string, updateCategoryDto: UpdateCategoryDto) {
return this.prisma.category.update({
where: {
id
id,
},
data: {
...updateCategoryDto
}
...updateCategoryDto,
},
});
}
remove(id: string) {
return this.prisma.category.update({
where: {
id
id,
},
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