crud icon indicating copy to clipboard operation
crud copied to clipboard

Cannot read property 'options' of undefined

Open zellkon opened this issue 2 years ago • 3 comments

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!

zellkon avatar Jul 21 '21 03:07 zellkon

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

alwex avatar Jul 27 '21 05:07 alwex

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!! ❤️

gino8080 avatar Aug 25 '21 10:08 gino8080

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 ?

hakimassouane2 avatar Jan 17 '24 06:01 hakimassouane2