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

How to use typeorm methodology in loopback 4 schema? #2286

Closed
bijarniya opened this issue Jan 25, 2019 · 2 comments
Closed

How to use typeorm methodology in loopback 4 schema? #2286

bijarniya opened this issue Jan 25, 2019 · 2 comments
Assignees

Comments

@bijarniya
Copy link

bijarniya commented Jan 25, 2019

@bajtos

How do I use @BeforeInsert TYPEORM in the schema?

import {Entity, model, property} from '@loopback/repository';

const crypto = require('crypto');

@model()
export class User extends Entity{    

  [...]

  @property({
    type: 'string',
    required: false
  })
  private hashedPassword: string;

  @property({
    type: 'string'
  })
  private salt: string;

  set password(password: string){
    if(!this.salt || !this.salt.length){
      this.salt = crypto.randomBytes(32).toString('hex');
    }
    this.hashedPassword = this.encryptPassword(password);
  }

  private encryptPassword(password: string) {
    return crypto.pbkdf2Sync(password, this.salt, 10000, 512, 'sha512').toString('hex');
  };

  public checkPassword(password: string) {
    return this.encryptPassword(password) === this.hashedPassword;
  };
}

Is loopback4 support TYPEORM?.

@AfterLoad
@BeforeInsert
@AfterInsert
@BeforeUpdate
@AfterUpdate
@BeforeRemove
@AfterRemove

@bajtos
Copy link
Member

bajtos commented Jan 25, 2019

I am not sure what exactly are you asking for.

Is loopback4 support TYPEORM?.

LoopBack 4 can be used together with TypeORM, see https://github.com/raymondfeng/loopback4-extension-repository-typeorm

How do I use @BeforeInsert TYPEORM in the schema?

Our persistence layer @loopback/repository does not support before/after hooks yet, see the discussion in #1919 for more details.

@bajtos bajtos closed this as completed Jan 25, 2019
@bajtos bajtos self-assigned this Jan 25, 2019
@pookdeveloper
Copy link

pookdeveloper commented Jan 8, 2020

Any example with loopback3 and typeorm?
I write this example, but i dont if is the correct.way.
https://medium.com/@davidgarciasantes/typeorm-with-loopback-3-68b195cbe6de

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

No branches or pull requests

3 participants