Support Topics Documentation Slack YouTube Blog

Unexpected identifier for function

Following the tutorial I’m trying to make a JS service.
I’m running into the following problems, see JS code bellow:

  1. When declaring getGameEvents as ‘function’ I’m getting the following error: Unexpected identifier

  2. When declaring getGameEvents as an API compilation is good and running calling getGameEvents from the API Service works ok. but when running ‘calcGameScore’ that uses ‘getGameEvents’ the response is: “getGameEvents is not defined”

How can I call getGameEvents form calcGameScore?
Thank’s for your help :slight_smile:

class Statistics {

/**

  • @param {String} gameId

  • @description load all events of a specific game

  • */
    async function getGameEvents(gameId){
    const gamesStore = Backendless.Data.of(‘Games’)

    const query = Backendless.Data.QueryBuilder.create()
    .setWhereClause(objectId = '${gameId}')
    .setRelated(“events”)

    const games = await gamesStore.find(query);

    return games[0].events
    }

/**

  • @param {String} gameId

  • */
    async calcGameScore(gameId) {

    const events = getGameEvents(gameId)

    /* do something with events */

    return events
    }

}

Backendless.ServerCode.addService(Statistics);

Hello @oren_heimlich

Please provide with us a link to the tutorial you are using.

You are trying to use getGameEvents as a function instead of the service’s method,
just replace the line with the following one:

const events = await this.getGameEvents(gameId)

Regards, Vlad