nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.04k stars 533 forks source link

Cannot read property 'options' of undefined #719

Open zellkon opened 3 years ago

zellkon commented 3 years ago

Here my code, im using userService.CreateOne for create new user from Auth.Service

  async signUp(user: User) {
    console.log(user);
    let req: CrudRequest;
    const emailConfirmToken = uuidv4();
    const record = await this.userService.createOne(req, user);
    try {
      await this.emailService.sendUserConfirmation(user, emailConfirmToken);
    } catch (error) {
      return throwError(new Error(error));
    }
    return record;
  }

please help me! Thank All!

alwex commented 3 years ago

you have to directly access the repository from the service. One way to do so is to make your repository public inside your service class, then access it from your other service like so:

@Injectable()
export class ApplicationsService extends TypeOrmCrudService<Application> {
  constructor(
    @InjectRepository(Application)
    public readonly repo: Repository<Application>, // make the repository public
  ) {
    super(repo)
  }
}

and from another service, you can use it this way:

await this.applicationsService.repo.update(app.id, app) // access the repository directly
gino8080 commented 3 years ago

you have to directly access the repository from the service. One way to do so is to make your repository public inside your service class, then access it from your other service like so:

@Injectable()
export class ApplicationsService extends TypeOrmCrudService<Application> {
  constructor(
    @InjectRepository(Application)
    public readonly repo: Repository<Application>, // make the repository public
  ) {
    super(repo)
  }
}

and from another service, you can use it this way:

await this.applicationsService.repo.update(app.id, app) // access the repository directly

finally a solution for most of my problems!! ❤️

hakimassouane2 commented 8 months ago

you have to directly access the repository from the service. One way to do so is to make your repository public inside your service class, then access it from your other service like so:

@Injectable()
export class ApplicationsService extends TypeOrmCrudService<Application> {
  constructor(
    @InjectRepository(Application)
    public readonly repo: Repository<Application>, // make the repository public
  ) {
    super(repo)
  }
}

and from another service, you can use it this way:

await this.applicationsService.repo.update(app.id, app) // access the repository directly

I never comment on GitHub but this saved my life, thank you so much 🎉

I kept using

 await this.applicationsService.getOne(req)

And mess around trying to make it work by modifying what's inside the req and kept thinking that this was dumb, now it all makes sense, still wondering why this is not indicated at all in the documentation ?