Expected Behavior
Allow use of UnitOfWork
in cloud code.
Actual Behavior
get error: TypeError: Backendless.UnitOfWork is not a constructor
Reproducible Test Case
Package.json:
"backendless": "6.3.7"
Code:
console.log(Backendless.UnitOfWork);
const workUnit = new Backendless.UnitOfWork();
I suspect this is some export error caused by src/unit-of-work.js
doing export default function UnitOfWorkService(app)
and not exporting the UnitOfWork
class but thats just my guess.
Could you please show the complete listing of your API service?
/**
* @param {Object} req The request object contains information about the request
* @param {Object} req.context The execution context contains an information about application, current user and event
* @param {Object} req.args
*
* @returns {Object|Promise.<Object>|void} The event caller will receive this value
*/
"use strict";
Backendless.ServerCode.customEvent('acceptFriendRequest', async function (req) {
if (req.context.userId === undefined || req.context.userToken === undefined) {
return { short: true }
}
const fromUser = req.args.from;
const toUser = req.args.to;
console.log(Backendless.UnitOfWork)
const uof = new Backendless.UnitOfWork();
uof.addToRelation('Users', fromUser.objectId, 'friends', [toUser.objectId])
uof.addToRelation('Users', toUser.objectId, 'friends', [fromUser.objectId])
uof.delete('friendRequests', req.args.objectId)
return uof.execute()
});
ive tried with and without the “use strict”
Hello @mudasar-javed
Could you provide us with your appId, please?
And save a simple demo in your app, please
Regards,
Viktor
App ID: 2A0EB9A5-1BF6-5C77-FF0C-566B648F7600
Event: Custom - acceptFriendRequest
Hello @mudasar-javed!
At the moment I do not see any errors in your code. To help me understand your problem in more detail, please create a simple demo Event Handler, that uses UnitOfWork, but without affecting the core functionality of your application. This is necessary for safe testing.
Regards,
Alexander
Hey @Alexander_Pavelko,
AFAIK my code is fine, I’ve used UnitOfWork successfully in my type script react native app but it doesnt seem to be set up in a way to work in the context of cloud code. Just trigger my custom event with a signed in user and you’ll see the error, the code doesn’t go past the const uof = new Backendless.UnitOfWork();
line and i get the error TypeError: Backendless.UnitOfWork is not a constructor
.
Thanks,
Mudasar.
Please describe the steps so that I can reproduce this issue.
And I will need test credentials.
Regards,
Alexander
username: test
password: TestPassword.123
In the client call: Backendless.Events.dispatch('acceptFriendRequest')
and observe the error.
I saw it while i had coderunner debugging so im not sure if the actual response contains the error or if its logged but you could spin up your own event in your own app then debug with coderunner and you should also get the same error just by invoking const uof = new Backendless.UnitOfWork();
.
Can you please tell me what version of backendless-coderunner
you have?
Regards,
Alexander
I think this issue is caused by the fact that you are using an outdated version.
Please try updating backendless-coderunner
.
If the problem persists, we will continue to look for a solution and will definitely help you.
Regards,
Alexander
yep youre right, updating code runner got it past that line, i had updated the backendless package but didnt think it couldve been code runner. Thanks!
2 Likes