How to use typegoose - 2 common examples

To help you get started, we’ve selected a few typegoose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scopsy / node-typescript-starter / src / dal / User.ts View on Github external
@JsonProperty()
    lastName: string;

    @prop()
    @JsonProperty()
    password?: string;

    @prop()
    @JsonProperty()
    picture?: string;

    // Providers data
    @prop() facebook?: string;
    @arrayProp({ items: AuthToken }) tokens?: AuthToken[];

    @prop()
    @JsonProperty({
        use: String
    })
    get fullName() {
        return `${this.firstName} ${this.lastName}`;
    }

    @instanceMethod
    matchPassword(candidatePassword: string) {
        return new Promise((resolve) => {
            bcrypt.compare(String(candidatePassword), this.password, (err, isMatch) => {
                if (err || !isMatch) return resolve(false);

                resolve(true);
            });
        });
github nartc / nest-mean / server / src / user / models / user.model.ts View on Github external
@Expose()
    password: string;

    @prop()
    @Expose()
    firstName?: string;

    @prop()
    @Expose()
    lastName?: string;

    @prop({ enum: UserRole, default: UserRole.User })
    @Expose()
    role?: UserRole;

    @prop()
    @Expose()
    get fullName(): string {
        return `${this.firstName} ${this.lastName}`;
    }

    static get model(): ModelType {
        return new User().getModelForClass(User, { schemaOptions });
    }

    static get modelName(): string {
        return this.model.modelName;
    }

    static createModel(): InstanceType {
        return new this.model();
    }

typegoose

Define Mongoose models using TypeScript classes.

MIT
Latest version published 5 years ago

Package Health Score

51 / 100
Full package analysis

Popular typegoose functions