Вызов метода напрямую работает, но вызов его по шаблону стратегии не - PullRequest
1 голос
/ 21 января 2020

Когда Sequelize init init у меня есть методы 'getBlocks' и 'getSkills', мне нужно принять шаблон стратегии, чтобы знать, какой метод мне нужно вызывать

  const resourceTypes = instance => ({
    Block: instance.getBlocks,
    Skill: instance.getSkills
  });

  return resourceTypes(this)[this.dataValues.type]();

Но этот вызов возвращает мне это throw

TypeError: instance.get is not a function
    at BelongsToMany.get (/home/fparol4/Desktop/work/repositories/assessment-api/node_modules/sequelize/lib/associations/belongs-to-many.js:434:48)
    at Object.obj.<computed> [as Block] (/home/fparol4/Desktop/work/repositories/assessment-api/node_modules/sequelize/lib/associations/helpers.js:64:39)
    at Question.findResource (/home/fparol4/Desktop/work/repositories/assessment-api/src/api/v1/models/Question.js:29:51)
    at QuestionService.findByPk (/home/fparol4/Desktop/work/repositories/assessment-api/src/api/v1/services/QuestionService.js:183:35)
    at async show (/home/fparol4/Desktop/work/repositories/assessment-api/src/api/v1/controllers/QuestionController.js:100:22)

Вызов метода напрямую, например:

return this.getBlocks ()

Бросок не выброшен

...