Skip to content
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
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
"dependencies": {
"@nestjs/common": "^10.3.8",
"@nestjs/core": "^10.3.8",
"@nestjs/mapped-types": "*",
"@nestjs/mapped-types": "2.0.5",
"@nestjs/platform-express": "^10.3.8",
"@nestjs/swagger": "^7.3.1",
"@prisma/client": "^5.13.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"nestjs-prisma": "^0.23.0",
"reflect-metadata": "^0.2.2",
"rimraf": "^5.0.5",
Expand Down
10 changes: 1 addition & 9 deletions apps/backend/src/event/dto/create-event.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,4 @@ import { OmitType } from '@nestjs/swagger';

import { Event } from '../entities/event.entity';

export class CreateEventDto extends OmitType(Event, [
'id',
'categoryId',
'category',
'ownerUserId',
'ownerUser',
'ownerGroupId',
'ownerGroup',
]) {}
export class CreateEventDto extends OmitType(Event, ['id', 'categoryId', 'ownerUserId', 'ownerGroupId']) {}
39 changes: 34 additions & 5 deletions apps/backend/src/event/entities/event.entity.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,64 @@
import { Category, Group, Priority, Status, User } from '@prisma/client';
import { IsDate, IsInt, IsNotEmpty, IsString } from 'class-validator';
import { IsDate, IsDateString, IsEnum, IsInt, IsNotEmpty, IsOptional, IsString } from 'class-validator';

export class Event {
@IsInt()
@IsOptional()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id should not be optional as I see

id: number;

@IsString()
@IsNotEmpty()
name: string;

@IsString()
@IsNotEmpty()
@IsOptional()
description: string;

@IsString()
@IsNotEmpty()
@IsOptional()
location: string;

@IsDate()
startDate: Date;

@IsDate()
@IsOptional()
endDate: Date;
@IsDate()

@IsDateString()
@IsOptional()
startTime: Date;
@IsDate()

@IsDateString()
@IsOptional()
endTime: Date;

@IsEnum(Priority)
@IsOptional()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

priority is also not optional according to the schema

priority: Priority;

@IsEnum(Priority)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is incorrect

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be @IsEnum(Status)

@IsOptional()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not optional

status: Status;

@IsInt()
@IsNotEmpty()
categoryId: number;

@IsNotEmpty()
category: Category;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need category


@IsInt()
@IsOptional()
ownerUserId: number;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional


@IsOptional()
ownerUser: User;

@IsInt()
@IsOptional()
ownerGroupId: number;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional


@IsOptional()
ownerGroup: Group;
}
17 changes: 8 additions & 9 deletions apps/backend/src/event/event.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';

//import { Prisma } from '@prisma/client';
import { CreateEventDto } from './dto/create-event.dto';
import { UpdateEventDto } from './dto/update-event.dto';
import { EventService } from './event.service';
Expand All @@ -15,22 +14,22 @@ export class EventController {
}

@Get()
async findAll() {
return await this.eventService.findAll();
findAll() {
return this.eventService.findAll();
}

@Get(':id')
async findOne(@Param('id') id: string) {
return await this.eventService.findOne(Number(id));
findOne(@Param('id') id: string) {
return this.eventService.findOne(Number(id));
}

@Patch(':id')
async update(@Param('id') id: string, @Body() data: UpdateEventDto) {
return await this.eventService.update(Number(id), data);
update(@Param('id') id: string, @Body() data: UpdateEventDto) {
return this.eventService.update(Number(id), data);
}

@Delete(':id')
async remove(@Param('id') id: string) {
return await this.eventService.remove(Number(id));
remove(@Param('id') id: string) {
return this.eventService.remove(Number(id));
}
}
Loading