1
votes

I have a collection called 'user' and 1 document in it:

{
  "username": "test1",
  "password": "pw1",
  "id": "1"
}

I created a Foxx app and trying to follow the documentation (using 2.6.0a3). This is my controller:

var Foxx = require('org/arangodb/foxx'),
    usersCollection = applicationContext.collection("user");

var usersRepo = Foxx.Repository.extend({
    getAll: Foxx.createQuery(
        'FOR u IN user RETURN u'
    )
});

var controller = new Foxx.Controller(applicationContext);

controller.get('/', function (req, res) {
    res.json(usersRepo.getAll());
});

I am getting: {"error":"undefined is not a function"} instead of the record list.

What am I missing?

1
Did you find that above code somewhere in the docs? If yes, could you post the documentation URL so the example can be fixed? Thanks!stj
It's not as above, I was copy pasting one part from the Details on FoxxRepository section into the My first Foxx App example, but it was my mistake I didn't instantiate the class. Thanks for noticing!rollingBalls

1 Answers

3
votes

As far as I can see the call to Foxx.Repository.extend() does not instanciate a usable Repository object but a "prototype":

var UsersRepo = Foxx.Repository.extend({
    getAll: Foxx.createQuery(
        'FOR u IN user RETURN u'
    )
});    

What seems to be missing is a concrete object instance:

var usersRepo = new UsersRepo("user");

The instance then can be used to call the predefined functions:

controller.get('/', function (req, res) {
    res.json(usersRepo.getAll());
});

In the above code, I have the prototype in a variable named UsersRepo (upper-case U) and the repository object instance in a variable usersRepo (lower-case u).