loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.96k stars 1.07k forks source link

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

Closed bijarniya closed 5 years ago

bijarniya commented 5 years ago

@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 commented 5 years ago

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 https://github.com/strongloop/loopback-next/issues/1919 for more details.

pookdeveloper commented 4 years ago

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