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

SchemaFactory trigger an error when a schema doesn't have the @Schema decorator #1697

Closed
1 task done
DanielSuhett opened this issue Mar 8, 2023 · 6 comments
Closed
1 task done
Labels

Comments

@DanielSuhett
Copy link

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

Instead of declaring my @Schema decorator in the class that I passed to SchemaFactory.createForClass, I accidentally declared this decorator in another class in my file. Although it was my mistake, I believe that if there had been a error exposed I would have had greater visibility into what I did wrong.

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';

@Schema({
  collection: 'collection',
})
class ObjectClass {
  @Prop({
    required: true,
  })
  id: string;
}

export class Entity {
  @Prop()
  object: ObjectClass;

  @Prop()
  name: string;
}

export const Schema = SchemaFactory.createForClass(Entity);

Until I realized that this @Schema was out of place, I couldn't use updateOne, although I was able to use findOne.

Describe the solution you'd like

Trigger an error if my schema is not successful.

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

As mentioned, I spent quite some time looking for solutions related to Mongoose or MongoDB, only to realize that the issue was simply a declaration error in the schema. I understand that it was my mistake, however, this can help people avoid going through the same debugging process if they accidentally have a wrong declaration in the schema.

@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@DanielSuhett
Copy link
Author

I really want to help, but I've never made a contribution to the Nest project. Do you think this issue would be a good starting point? I don't know what size it can be. @kamilmysliwiec

@kamilmysliwiec
Copy link
Member

I think this one should be fairly simple so if you have some time, feel free to give it a shot :)

@DanielSuhett
Copy link
Author

I will try!

@DanielSuhett
Copy link
Author

@kamilmysliwiec Hi, I opened the PR!

@kamilmysliwiec
Copy link
Member

Let's track this here #1703

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants