-
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
base: main
Are you sure you want to change the base?
Conversation
The build is not works, please check it |
Yeah we talked bout it, but didn't have time to to check the problem in detail. There's something with the CreateEventDto. |
There are multiple problems:
|
I resolved the first problem 😉 |
@IsOptional() | ||
priority: Priority; | ||
|
||
@IsEnum(Priority) |
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.
I assume this is incorrect
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.
Yes, it should be @IsEnum(Status)
@IsInt() | ||
@IsNotEmpty() | ||
categoryId: number; | ||
|
||
@IsNotEmpty() | ||
category: Category; | ||
|
||
@IsInt() | ||
@IsOptional() | ||
ownerUserId: number; | ||
|
||
@IsOptional() | ||
ownerUser: User; | ||
|
||
@IsInt() | ||
@IsOptional() | ||
ownerGroupId: number; | ||
|
||
@IsOptional() | ||
ownerGroup: Group; |
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.
Do not create a field for relations in the entity schema. This class should represent one record in the database. Prisma hides this from you, but there are no ownerGroup, ownerUser or category fields on the Event table (only categoryId, ownerUserId and ownerGroupId), so you should remove those from this class. When an event is created, the user, group and category likely already exists, and prisma will be able to link the new event record to those records with the id (foreign key) fields
…/collage-schedule-planner into feature/event-validation
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.
I marked some problems, please fix them and it will be perfect 😃
apps/backend/package.json
Outdated
"@prisma/client": "^5.13.0", | ||
"class-transformer": "^0.5.1", | ||
"class-validator": "^0.14.1", | ||
<<<<<<< HEAD |
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.
Please resolve the merge conflict (just delete all between <<< and >>> 76...43).
@IsOptional() | ||
priority: Priority; | ||
|
||
@IsEnum(Priority) |
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.
Yes, it should be @IsEnum(Status)
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.
My observations..
@IsOptional() | ||
categoryId: number; | ||
|
||
category: Category; |
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.
Don't need category
} | ||
export class Event { | ||
@IsInt() | ||
@IsOptional() |
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.
id should not be optional as I see
|
||
@IsString() | ||
@IsOptional() | ||
color: string; |
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.
when optional we could declare as color?: string
, so that it is nullable
|
||
import { Event } from '../entities/event.entity'; | ||
|
||
export class CreateEventDto extends OmitType(Event, ['id', 'category', 'ownerGroupId', 'ownerUserId']) {} |
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.
I would say we need everything upon creation, but maybe I'm wrong.
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.
Hi, sorry for the little late. Reviewed your code, please resolve those changes quickly and we can merge this branch. I tried to explain what you might misunderstood about the optional fields, but if it's still not clear, hit me up.
Yeah, and one more thing: why is the class category even in the event entity file?
name: string; | ||
|
||
@IsString() | ||
@IsOptional() |
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.
@IsOptional() should stay as well, sorry if I wasn't clear
location: string; | ||
|
||
@IsDate() | ||
@IsOptional() |
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.
start date is not optional
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.
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.
endTime: Date; | ||
|
||
@IsEnum(Priority) | ||
@IsOptional() |
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.
priority is also not optional according to the schema
priority: Priority; | ||
|
||
@IsEnum(Status) | ||
@IsOptional() |
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.
not optional
categoryId: number; | ||
|
||
@IsInt() | ||
ownerUserId: number; |
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
ownerUserId: number; | ||
|
||
@IsInt() | ||
ownerGroupId: number; |
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
|
||
import { Event } from '../entities/event.entity'; | ||
|
||
export class CreateEventDto extends OmitType(Event, ['ownerGroupId', 'ownerUserId']) {} |
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.
Omit only id, because that's the only information the database comes up with alone. The owner we should specify.
I altered the event_has_only_one_owner constraint in the prisma migrations. As I see an event's ownership is optional in the prisma schema therefore (if I'm right) it should be optional in the migration as well. I also made the events' category field optional. I don't think it's a must for an event to have a category. |
It's nearly done, but I just can't seem to figure it out how to make the prisma compatible with the dtos.