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 6 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
9 changes: 8 additions & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@
"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",
<<<<<<< HEAD
Copy link
Member

Choose a reason for hiding this comment

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

Please resolve the merge conflict (just delete all between <<< and >>> 76...43).

"nestjs": "^0.0.1",
=======
>>>>>>> 76a675af0de806347ba6c27372be1633ba014b43
"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', 'category', 'ownerGroupId', 'ownerUserId']) {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would say we need everything upon creation, but maybe I'm wrong.

52 changes: 44 additions & 8 deletions apps/backend/src/event/entities/event.entity.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,71 @@
import { Category, Group, Priority, Status, User } from '@prisma/client';
import { IsDate, IsInt, IsNotEmpty, IsString } from 'class-validator';
import { Priority, Status } from '@prisma/client';
import { IsDate, IsDateString, IsEnum, IsInt, IsNotEmpty, IsOptional, IsString } from 'class-validator';

export class Category {
@IsInt()
id: number;

@IsString()
name: string;
balintking marked this conversation as resolved.
Show resolved Hide resolved

@IsString()
@IsOptional()
color: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

when optional we could declare as color?: string, so that it is nullable


@IsString()
@IsOptional()
description: string;
}
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()
@IsOptional()
Copy link
Collaborator

Choose a reason for hiding this comment

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

start date is not optional

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you mixed this up with the default values. But this is the entity, this should perfectly mirror what's in the database schema. The default values come handy creating an object and not telling those values. Thats what create dto is for.

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()
@IsOptional()
categoryId: number;

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()
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

ownerUser: User;

@IsInt()
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

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