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

Options param in SequelizeRepository create methods issue #10278

Open
Akanksha13-dev opened this issue Dec 28, 2023 · 2 comments
Open

Options param in SequelizeRepository create methods issue #10278

Akanksha13-dev opened this issue Dec 28, 2023 · 2 comments

Comments

@Akanksha13-dev
Copy link

Describe the bug

options = {
fields: {
privateKey: false,
publicKey: false,
},
};

const result = await this.certificatesRepository.create(
certificate,
this.options,
);
when we pass this.option param in create method getting error options.attributes.map is not a function. But working for findById.

Logs

[2023-12-28T08:09:29.630Z] error :: App_Log -> Request POST /tenants/f5408ba4-521f-4f96-fe87-bf0e6092ea16/certificates/ errored out. Error :: {} TypeError: options.attributes.map is not a function
Request POST /tenants/f5408ba4-521f-4f96-fe87-bf0e6092ea16/certificates/ failed with status code 500. TypeError: options.attributes.map is not a function
    at new Model (/Users/akanksha.singh/Desktop/telescope/telescope-health-backend-api/node_modules/sequelize/src/model.js:117:47)
    at new certificates (/Users/akanksha.singh/Desktop/telescope/telescope-health-backend-api/node_modules/sequelize/src/sequelize.js:466:19)
    at Function.build (/Users/akanksha.singh/Desktop/telescope/telescope-health-backend-api/node_modules/sequelize/src/model.js:2255:12)
    at Function.create (/Users/akanksha.singh/Desktop/telescope/telescope-health-backend-api/node_modules/sequelize/src/model.js:2305:23)
    at CertificatesRepository.create (/Users/akanksha.singh/Desktop/telescope/telescope-health-backend-api/node_modules/@loopback/sequelize/src/sequelize/sequelize.repository.base.ts:151:44)
    at CertificatesRepository.create (/Users/akanksha.singh/Desktop/telescope/telescope-health-backend-api/node_modules/@sourceloop/core/src/repositories/sequelize/sequelize-user-modify-crud.repository.base.ts:41:18)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at CommonHelperService.createCertificate (/Users/akanksha.singh/Desktop/telescope/telescope-health-backend-api/services/cbi-service/src/services/common-helper.service.ts:112:20)
    at ServiceSequence.handle (/Users/akanksha.singh/Desktop/telescope/telescope-health-backend-api/node_modules/@sourceloop/core/src/service-sequence.ts:113:22)
    at HttpHandler._handleRequest (/Users/akanksha.singh/Desktop/telescope/telescope-health-backend-api/node_modules/@loopback/rest/src/http-handler.ts:115:5)
[2023-12-28T08:09:29.652Z] info :: App_Log -> Request POST /tenants/f5408ba4-521f-4f96-fe87-bf0e6092ea16/certificates/ Completed in 1895ms

Additional information

No response

Reproduction

provided information is enough to understand the problem.

@KalleV
Copy link
Contributor

KalleV commented Jan 3, 2024

I tested this one and it looks like you can pass an array of strings for the field names:

const result = await this.certificatesRepository.create(
certificate,
  {
    fields: [ "a", "b", "c" ]
  }
);

The loopback-style syntax would require the "fields" to be remapped here:

async create(entity: DataObject<T>, options?: AnyObject): Promise<T> {
const data = await this.sequelizeModel.create(
entity as MakeNullishOptional<T>,
options,
);
return new this.entityClass(data.toJSON()) as T;
}

For example (note that the existing buildSequelizeAttributeFilter has a Typescript interface conflict with the create parameters):

  async create(entity: DataObject<T>, options?: AnyObject): Promise<T> {
    const data = await this.sequelizeModel.create(
      entity as MakeNullishOptional<T>,
      {
        ...options,
        fields: this.buildSequelizeAttributeFilter(options?.fields),
      },
    );
    return new this.entityClass(data.toJSON()) as T;
  }

@major-winter
Copy link

I believe that fields is a preserved word for the option and it's of type array. You may try to use another word instead of fields.

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

No branches or pull requests

4 participants