on 2023 Dec 02 6:33 PM
Good evening,
I'm developing a Node.js CAP application that exposes a service (TicketsService) composed of two entities:
Reports uses the cuid aspect, so the ID field is auto-generated when a new Report is created.
Without implementing custom handlers, I can succesfully execute CRUD operations on the Reports entity by taking advantage of the generic providers served by CAP.
I then implemented the TicketsService custom handlers to manage Tickets readings (which work fine), as well as the READ handler on the Reports entity.
Then, it was time for the CREATE handler, that I simply defined as follows:
this.on("CREATE", Reports, async (req, next) => {
return await cds.run(req.query);
})<br>
since I don't have to manage custom logic for the Reports creation.
The problem occurs when I try to send a POST request to create a new Report:
[cds] - ❗️Uncaught TypeError: Cannot read properties of undefined (reading 'ID')
at UriHelper.buildEntityKeys (/home/user/projects/reg-reports/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/utils/UriHelper.js:85:22)
at ResponseHeaderSetter.setLocationHeader (/home/user/projects/reg-reports/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/core/ResponseHeaderSetter.js:102:17)
at SetResponseHeadersCommand.execute (/home/user/projects/reg-reports/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/SetResponseHeadersCommand.js:66:30)
at CommandExecutor._execute (/home/user/projects/reg-reports/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:71:17)
at /home/user/projects/reg-reports/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:81:18
at ConditionalRequestControlCommand.execute (/home/user/projects/reg-reports/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/ConditionalRequestControlCommand.js:48:5)
at CommandExecutor._execute (/home/user/projects/reg-reports/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:71:17)
at /home/user/projects/reg-reports/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:81:18
at /home/user/projects/reg-reports/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/DispatcherCommand.js:88:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {<br>
I then refactored the CREATE handler delegating the operation to the generic providers (or at least that's what I thought since I read that generic providers are executed after all custom ones):
this.on("CREATE", Reports, async (req, next) => {
return next();
})<br>
But the error is the same.
Here are my doubts:
Thank you in advance for the help.
Federico
I managed to solve the issue. The problem was the instruction:
return await super.init();
not being called in the on.init() method inside the handler.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
79 | |
10 | |
10 | |
10 | |
10 | |
9 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.