Skip to content
This repository was archived by the owner on Jun 29, 2021. It is now read-only.

plugin options #85

Closed
norbert-tasi opened this issue Dec 17, 2017 · 4 comments
Closed

plugin options #85

norbert-tasi opened this issue Dec 17, 2017 · 4 comments

Comments

@norbert-tasi
Copy link

Hello,

Can you help me how to define plugin related options? The prop seems very strict to me.

Thank you!

@snaquaye
Copy link

@plugin(pluginName, options)
class User extends Typegoose {}

@ssi-hu-tasi-norbert
Copy link

I mean for fields. eg. for mongoose-intl I have to set intl:true for fields one by one, but I can't because @prop is way too strict and does not let me do.

Thanks

@neilime
Copy link

neilime commented Nov 5, 2018

I've found a way to deals with mongoose-intl :

  1. Override @prop :
import { PropOptionsWithValidate, prop } from 'typegoose';

export const property = (options: PropertyOptionsWithValidate & { intl?: boolean } = {}) => (target: any, key: string) => {
    if(options.intl){
        Reflect.defineMetadata('design:type', String, target, key);
    }
    prop(options)(target, key);
};
  1. Declare IntlString type:
export declare type IntlString = String | string | {
    [key: string]: String;
};
  1. Use it in schema
import { Typegoose } from 'typegoose';

export class TestSchema extends Typegoose {
  @property({ intl: true })
  name: IntlString;
}

But this solutions does not work very well, the issue is that mongoose-intl does not provide an IntlString class (or interface) and wants the type to be String : https://github.com/alexsk/mongoose-intl/blob/master/lib/mongoose-intl.js#L35

@hasezoey
Copy link
Contributor

@Ben305 this can be closed as "fixed" & "stale"

@Ben305 Ben305 closed this as completed Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants