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

Mongoose plugin registration not working #220

Closed
Josuto opened this issue Apr 20, 2024 · 1 comment · Fixed by #221
Closed

Mongoose plugin registration not working #220

Josuto opened this issue Apr 20, 2024 · 1 comment · Fixed by #221
Assignees
Labels
bug Something isn't working

Comments

@Josuto
Copy link
Owner

Josuto commented Apr 20, 2024

We realize that the plugin uniqueValidator is not executed:

import { SUPPORTED_LANGUAGES } from '@config/supported-languages';
import uniqueValidator from 'mongoose-unique-validator';
import { BaseSchema, extendSchema } from 'monguito';

export const SomeSchema = extendSchema(
  BaseSchema,
  {
    title: Object.fromEntries(
      SUPPORTED_LANGUAGES.map((langData) => [langData.id, { type: String, required: false }])
    ),
    externalId: { 
      type: String, 
      required: true,
      // This is not working 
      unique: true
    },
  },
  { timestamps: true }
);

// This is not working
SomeSchema.plugin(uniqueValidator);

When calling the save function of Monguito it is saved even if the externalId already exists. I do not know if it is a problem when using the extendSchema no longer allows plugins like mongoose-unique-validator or if it is something else the problem. Any idea?

Originally posted by @aralroca in #219

@Josuto
Copy link
Owner Author

Josuto commented Apr 20, 2024

That's a bug 🐛. I will fix it by including a new property plugins in the options parameter of the extendSchema utility function. This new property will enable monguito developers to specify an array of plugins they want to register in the schema resulting from the execution of the function. New release coming soon! 🎁

@Josuto Josuto self-assigned this Apr 20, 2024
@Josuto Josuto added the bug Something isn't working label Apr 20, 2024
@Josuto Josuto linked a pull request Apr 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant