Moralis Cloud Function Job find and write error

Hi

I try find and write data from a class to another class. Because I make practice on Moralis Cloud Functions.

I dont know why give me this error.


2022-02-18T07:49:23.413Z - SyntaxError: Unexpected identifier
at customUserPlugin (/moralis-server/cloud/main.js:158:26)
at /moralis-server/lib/cloud-code/plugins/index.js:154:15
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Object.initialize (/moralis-server/lib/cloud-code/plugins/index.js:143:3)
2022-02-18T07:49:23.412Z - CLOUD FUNCTION ERROR PLEASE CHECK YOUR CLOUD FUNCTION CODE
2022-02-18T07:49:22.537Z - Initialized Function plugin loadPlugins


function async saveCode(){
     const League = Moralis.Object.extend("league");
    const leagueQuery = new Moralis.Query(League);
    leagueQuery.equalTo("active", true);
    const lresult = await leagueQuery.find({useMasterKey:true});
    const league = lresult[0];
    const week = league.attributes.week;

    const Matches = Moralis.Object.extend("matches");
    const matchesQuery = new Moralis.Query(Matches);
    matchesQuery.equalTo("league", league);
    matchesQuery.equalTo("week", week);
    const matchesResults = await matchesQuery.find({useMasterKey:true});
    matchesResults.forEach(match => {
        //deneme başlangıç
        const Deneme = Moralis.Object.extend("deneme");
        const deneme = new Deneme();
        deneme.set("away_name", match.attributes.away_name);
        deneme.set("home_name", match.attributes.home_name);
        deneme.save();
        //deneme bitiş
    });
}

Moralis.Cloud.job("updateWalletBalance", request => {
    return saveCode();
});

it could be a syntax error somewhere, you could try to comment parts of the code to see when it starts working

I tried the codes in client. It works healthily. But it doesn’t work in cloud.

what is the server url?

why did you ask server url?

to see if there is more in the logs than what you pasted

it seems that there is a syntax error, you also have some non ascii chars there
error: SyntaxError: Unexpected identifier

1 Like