gamedesigner
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
|
||||
const collection = 'games';
|
||||
/**
|
||||
* Games manager class
|
||||
*/
|
||||
class GamesManager{
|
||||
name = 'games';
|
||||
name = 'game';
|
||||
|
||||
/**
|
||||
* Class initializer, инициализация на плъгин
|
||||
@@ -18,7 +19,9 @@ class GamesManager{
|
||||
* @param {Game} data the game description, дефиниция на играта
|
||||
*/
|
||||
this.create = async function(ctx, data){
|
||||
|
||||
data.id = (await db.getLastId(collection)) + 1;
|
||||
await db.create(collection, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,7 +30,8 @@ class GamesManager{
|
||||
* @returns {Game} the game, игрова дефиниция
|
||||
*/
|
||||
this.read = async function(id){
|
||||
|
||||
id = parseInt(id);
|
||||
return await db.get(collection, {id});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +40,11 @@ class GamesManager{
|
||||
* @param {Game} data the game description, игрова дефиниция
|
||||
*/
|
||||
this.update = async function(ctx, data){
|
||||
|
||||
data.id = parseInt(data.id);
|
||||
let object = await this.read(data.id);
|
||||
data = Object.assign(object, data);
|
||||
await db.update(collection, {id: data.id}, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +52,8 @@ class GamesManager{
|
||||
* @param {Number} id game definition ID, идентификатор на игровата дефиниция
|
||||
*/
|
||||
this.remove = async function(id){
|
||||
|
||||
id = parseInt(id);
|
||||
await db.remove(collection, {id});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +62,10 @@ class GamesManager{
|
||||
* @returns {Game[]} Array of games, масив от игрови дефиниции
|
||||
*/
|
||||
this.list = async function(query){
|
||||
|
||||
return await db.list(collection, {
|
||||
query,
|
||||
project: { name:1, id:1, sceneThumb: '$scenes.data.environment'}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user