generated from kir-dev/next-nest-template
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/event validation #19
Open
DankaMarci
wants to merge
10
commits into
main
Choose a base branch
from
feature/event-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
34b4677
Data validation
DankaMarci b3e83aa
Validation fixes
DankaMarci 76a675a
Adds required packages
csiszaralex 39098df
dto and entity fixes
DankaMarci d3b6244
rand fix
DankaMarci 3102e7a
Merge branch 'feature/event-validation' of https://github.com/kir-dev…
DankaMarci 9c5ce14
Conflict and event entity fixes
DankaMarci 4f05111
rquested changes on the Event dto
DankaMarci ef883f1
Requested fixes on the Event DTO
DankaMarci 59eadf9
Merge branch 'main' into feature/event-validation
DankaMarci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
apps/backend/prisma/migrations/20240927093415_optional_category/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- DropForeignKey | ||
ALTER TABLE "Event" DROP CONSTRAINT "Event_categoryId_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Event" ALTER COLUMN "categoryId" DROP NOT NULL; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Event" ADD CONSTRAINT "Event_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Category"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { OmitType } from '@nestjs/swagger'; | ||
|
||
import { Event } from '../entities/event.entity'; | ||
|
||
export class CreateEventDto extends OmitType(Event, ['id']) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { PartialType } from '@nestjs/swagger'; | ||
|
||
import { CreateEventDto } from './create-event.dto'; | ||
|
||
export class UpdateEventDto extends PartialType(CreateEventDto) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Priority, Status } from '@prisma/client'; | ||
import { IsDate, IsDateString, IsEnum, IsInt, IsNotEmpty, IsOptional, IsString } from 'class-validator'; | ||
|
||
export class Event { | ||
@IsInt() | ||
id: number; | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
name: string; | ||
|
||
@IsString() | ||
@IsOptional() | ||
description: string; | ||
|
||
@IsString() | ||
@IsOptional() | ||
location: string; | ||
|
||
@IsDate() | ||
startDate: Date; | ||
|
||
@IsDate() | ||
@IsOptional() | ||
endDate: Date; | ||
|
||
@IsDateString() | ||
@IsOptional() | ||
startTime: Date; | ||
|
||
@IsDateString() | ||
@IsOptional() | ||
endTime: Date; | ||
|
||
@IsEnum(Priority) | ||
priority: Priority; | ||
|
||
@IsEnum(Status) | ||
status: Status; | ||
|
||
@IsInt() | ||
@IsOptional() | ||
categoryId: number; | ||
|
||
@IsInt() | ||
@IsOptional() | ||
ownerUserId: number; | ||
|
||
@IsInt() | ||
@IsOptional() | ||
ownerGroupId: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. optional |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'; | ||
|
||
import { CreateEventDto } from './dto/create-event.dto'; | ||
import { UpdateEventDto } from './dto/update-event.dto'; | ||
import { EventService } from './event.service'; | ||
|
||
@Controller('event') | ||
export class EventController { | ||
constructor(private readonly eventService: EventService) {} | ||
|
||
@Post() | ||
create(@Body() data: CreateEventDto) { | ||
return this.eventService.create(data); | ||
} | ||
|
||
@Get() | ||
findAll() { | ||
return this.eventService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
findOne(@Param('id') id: string) { | ||
return this.eventService.findOne(Number(id)); | ||
} | ||
|
||
@Patch(':id') | ||
update(@Param('id') id: string, @Body() data: UpdateEventDto) { | ||
return this.eventService.update(Number(id), data); | ||
} | ||
|
||
@Delete(':id') | ||
remove(@Param('id') id: string) { | ||
return this.eventService.remove(Number(id)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Injectable, NotFoundException } from '@nestjs/common'; | ||
import { PrismaService } from 'nestjs-prisma'; | ||
|
||
import { CreateEventDto } from './dto/create-event.dto'; | ||
import { UpdateEventDto } from './dto/update-event.dto'; | ||
import { Event } from './entities/event.entity'; | ||
|
||
@Injectable() | ||
export class EventService { | ||
constructor(private readonly prisma: PrismaService) {} | ||
|
||
async create(data: CreateEventDto): Promise<Event> { | ||
return await this.prisma.event.create({ data }); | ||
} | ||
|
||
async findAll(): Promise<Event[]> { | ||
try { | ||
const res = await this.prisma.event.findMany(); | ||
if (!res) throw new Error(); | ||
return res; | ||
} catch (error) { | ||
throw new NotFoundException('Events not found'); | ||
} | ||
} | ||
|
||
async findOne(id: number): Promise<Event> { | ||
try { | ||
const res = await this.prisma.event.findUnique({ where: { id: id } }); | ||
if (!res) throw new Error(); | ||
return res; | ||
} catch (e) { | ||
throw new NotFoundException(`Event with ID ${id} not found`); | ||
} | ||
} | ||
|
||
async update(id: number, data: UpdateEventDto): Promise<Event> { | ||
try { | ||
return await this.prisma.event.update({ where: { id: id }, data }); | ||
} catch (e) { | ||
throw new NotFoundException(`Event with ID ${id} not found`); | ||
} | ||
} | ||
|
||
async remove(id: number): Promise<Event> { | ||
try { | ||
return await this.prisma.event.delete({ where: { id: id } }); | ||
} catch (e) { | ||
throw new NotFoundException(`Event with ID ${id} not found`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1268,6 +1268,11 @@ ansi-styles@^4.0.0, ansi-styles@^4.1.0: | |
dependencies: | ||
color-convert "^2.0.1" | ||
|
||
ansi-styles@^6.1.0: | ||
version "6.2.1" | ||
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-6.2.1.tgz#0e62320cf99c21afff3b3012192546aacbfb05c5" | ||
integrity sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug== | ||
|
||
any-promise@^1.0.0: | ||
version "1.3.0" | ||
resolved "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz" | ||
|
@@ -1668,12 +1673,12 @@ chrome-trace-event@^1.0.2: | |
|
||
class-transformer@^0.5.1: | ||
version "0.5.1" | ||
resolved "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz" | ||
resolved "https://registry.yarnpkg.com/class-transformer/-/class-transformer-0.5.1.tgz#24147d5dffd2a6cea930a3250a677addf96ab336" | ||
integrity sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw== | ||
|
||
class-validator@^0.14.1: | ||
version "0.14.1" | ||
resolved "https://registry.npmjs.org/class-validator/-/class-validator-0.14.1.tgz" | ||
resolved "https://registry.yarnpkg.com/class-validator/-/class-validator-0.14.1.tgz#ff2411ed8134e9d76acfeb14872884448be98110" | ||
integrity sha512-2VEG9JICxIqTpoK1eMzZqaV+u/EiwEJkMGzTrZf6sU/fwsnOITVgYJ8yojSy6CaXtO9V0Cc6ZQZ8h8m4UBuLwQ== | ||
dependencies: | ||
"@types/validator" "^13.11.8" | ||
|
@@ -2044,6 +2049,11 @@ doctrine@^3.0.0: | |
dependencies: | ||
esutils "^2.0.2" | ||
|
||
eastasianwidth@^0.2.0: | ||
version "0.2.0" | ||
resolved "https://registry.yarnpkg.com/eastasianwidth/-/eastasianwidth-0.2.0.tgz#696ce2ec0aa0e6ea93a397ffcf24aa7840c827cb" | ||
integrity sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA== | ||
|
||
[email protected]: | ||
version "1.1.1" | ||
resolved "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz" | ||
|
@@ -3565,7 +3575,7 @@ levn@^0.4.1: | |
|
||
libphonenumber-js@^1.10.53: | ||
version "1.11.2" | ||
resolved "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.11.2.tgz" | ||
resolved "https://registry.yarnpkg.com/libphonenumber-js/-/libphonenumber-js-1.11.2.tgz#9ddd7d1a1e1be0e7c596c7e09487c362b4f1210c" | ||
integrity sha512-V9mGLlaXN1WETzqQvSu6qf6XVAr3nFuJvWsHcuzCCCo6xUKawwSxOPTpan5CGOSKTn5w/bQuCZcLPJkyysgC3w== | ||
|
||
lilconfig@^2.1.0: | ||
|
@@ -3872,6 +3882,11 @@ nestjs-prisma@^0.23.0: | |
"@angular-devkit/schematics" "^13.3.0" | ||
"@schematics/angular" "~13.3.0" | ||
|
||
nestjs@^0.0.1: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/nestjs/-/nestjs-0.0.1.tgz#e4b3b82fbbd0bbf993a7c7a137b3ad59ccecf6b6" | ||
integrity sha512-LJTf2zDRtWE69B6R2DUW6/LCftgVOq3kp3aqxPsB0eei8OX+lW2RFjzREZWRL1GUD/jGdBSMhM3Q5YWLC2uHNg== | ||
|
||
[email protected]: | ||
version "14.2.10" | ||
resolved "https://registry.yarnpkg.com/next/-/next-14.2.10.tgz#331981a4fecb1ae8af1817d4db98fc9687ee1cb6" | ||
|
@@ -4890,7 +4905,7 @@ streamsearch@^1.1.0: | |
is-fullwidth-code-point "^3.0.0" | ||
strip-ansi "^6.0.1" | ||
|
||
string-width@4.1.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3, string-width@^5.1.2: | ||
string-width@^4.1.0: | ||
version "4.1.0" | ||
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.1.0.tgz#ba846d1daa97c3c596155308063e075ed1c99aff" | ||
integrity sha512-NrX+1dVVh+6Y9dnQ19pR0pP4FiEIlUvdTGn8pw6CKTNq5sgib2nIhmUNT5TAmhWmvKr3WcxBcP3E8nWezuipuQ== | ||
|
@@ -4899,6 +4914,24 @@ [email protected], string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2. | |
is-fullwidth-code-point "^3.0.0" | ||
strip-ansi "^5.2.0" | ||
|
||
string-width@^4.2.0, string-width@^4.2.3: | ||
version "4.2.3" | ||
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" | ||
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== | ||
dependencies: | ||
emoji-regex "^8.0.0" | ||
is-fullwidth-code-point "^3.0.0" | ||
strip-ansi "^6.0.1" | ||
|
||
string-width@^5.0.1, string-width@^5.1.2: | ||
version "5.1.2" | ||
resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794" | ||
integrity sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA== | ||
dependencies: | ||
eastasianwidth "^0.2.0" | ||
emoji-regex "^9.2.2" | ||
strip-ansi "^7.0.1" | ||
|
||
string.prototype.matchall@^4.0.10: | ||
version "4.0.11" | ||
resolved "https://registry.npmjs.org/string.prototype.matchall/-/string.prototype.matchall-4.0.11.tgz" | ||
|
@@ -5449,7 +5482,7 @@ v8-compile-cache-lib@^3.0.1: | |
|
||
validator@^13.9.0: | ||
version "13.12.0" | ||
resolved "https://registry.npmjs.org/validator/-/validator-13.12.0.tgz" | ||
resolved "https://registry.yarnpkg.com/validator/-/validator-13.12.0.tgz#7d78e76ba85504da3fee4fd1922b385914d4b35f" | ||
integrity sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg== | ||
|
||
vary@^1, vary@~1.1.2: | ||
|
@@ -5598,15 +5631,24 @@ which@^2.0.1: | |
string-width "^4.1.0" | ||
strip-ansi "^6.0.0" | ||
|
||
wrap-ansi@7.0.0, wrap-ansi@^6.0.1, wrap-ansi@^6.2.0, wrap-ansi@^8.1.0: | ||
version "7.0.0" | ||
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" | ||
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== | ||
wrap-ansi@^6.0.1, wrap-ansi@^6.2.0: | ||
version "6.2.0" | ||
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53" | ||
integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA== | ||
dependencies: | ||
ansi-styles "^4.0.0" | ||
string-width "^4.1.0" | ||
strip-ansi "^6.0.0" | ||
|
||
wrap-ansi@^8.1.0: | ||
version "8.1.0" | ||
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" | ||
integrity sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ== | ||
dependencies: | ||
ansi-styles "^6.1.0" | ||
string-width "^5.0.1" | ||
strip-ansi "^7.0.1" | ||
|
||
wrappy@1: | ||
version "1.0.2" | ||
resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional