I tried to make api request twice and the first one work, but the second fails with below error.
{
"name": "GeneralError",
"message": "this.app.service(...).create(...) is not a function",
"code": 500,
"className": "general-error",
"data": {},
"errors": {}
}
result.class.js
/* eslint-disable no-unused-vars */
const errors = require('@feathersjs/errors');
exports.Submission = class Submission {
constructor (options, app) {
this.app = app;
}
async create (data, params) {
if (Array.isArray(data)) {
return Promise.all(data.map(current => this.create(current, params)));
}
let result = await this.app.service('result').create({ //<------------- It works
sectionId: data.sectionId,
})
console.log(result) // <------------------------------------ able to show the value
(data.sub_sections).map(async sub_section =>{
(sub_section.questions).map(async question =>{
let payload = {
answerId: question.questionId
}
await this.app.service('result').create(payload) //<------------- It results in error
})
})
return data;
}
};