/services/stats

  • module
services/stats

{function()}

 

GET /services/stats

Gets stats from the database.

GET /services/stats?
    where[gameId]=5&
    withRelated[]=player
    sortBy=time

Parameters

  1. where {Object}Optional

    Clause used to filter which stats are returned.

  2. withRelated {Array}Optional

    Clause used to add related data.

  3. sortBy {String}Optional

    Clause used to sort the returned stats.

Returns

{JSON}

An object that contains the stats:

{data: [{
  id: Int,
  gameId: Int,     // Related game
  playerId: Int,   // Related player
  type: String,    // "1P", "1PA", etc
  time: Int,       // time of stat in seconds
  value: Int,      // Not currently used, but available.
}, ...]}

POST /services/stats

Creates a stat in the database. Only admins are allowed to create stats.

POST /services/stats
     {
       "gameId": 6,
       "playerId": 15,
       "type": "1P",
       "time": 60
     }

Parameters

  1. JSONBody {JSON}

    The raw JSON properties of a stat object.

Returns

{JSON}

Returns JSON with all the properties of the newly created object, including its id.

{
  "id": 9
  "gameId": 6,
  "playerId": 15,
  "type": "1P",
  "time": 60
}

GET /services/stats/:id

Gets a stat by id from the database.

GET /services/stats/5?
    withRelated[]=player

Parameters

  1. withRelated {Array}Optional

    Clause used to add related data.

Returns

{JSON}

An object that contains the stats:

{
  id: Int,
  gameId: Int,     // Related game
  playerId: Int,   // Related player
  type: String,    // "1P", "1PA", etc
  time: Int,       // time of stat in seconds
  value: Int,      // Not currently used, but available.
}

PUT /services/stats/:id

Updates a stat in the database. Only admins are allowed to update stats.

PUT /services/stats/9
    {
      "gameId": 6,
      "playerId": 15,
      "type": "1P",
      "time": 120
    }

Parameters

  1. JSONBody {JSON}

    The updated properties of the stat object.

Returns

{JSON}

Returns JSON with all the properties of the updated object, including its id.

{
  "id": 9
  "gameId": 6,
  "playerId": 15,
  "type": "1P",
  "time": 60
}

DELETE /services/stats/:id

Deletes a stat in the database. Only admins are allowed to delete stats.

DELETE /services/stats/9

Returns

{JSON}

Returns an empty JSON object.

 {}