gameobject module dev

This commit is contained in:
2024-11-04 20:26:27 +02:00
parent 53350ef548
commit 2978f11869
20 changed files with 1391 additions and 114 deletions
@@ -0,0 +1,49 @@
import express from 'express';
import multipart from 'connect-multiparty';
const multipartMiddleware = multipart();
class GameObjectsController{
name = 'gameObjectsApi'
route = '/api/game-object'
init(app){
const { gameObject } = app;
const router = express.Router();
/**
* Create & update
*/
router.put('/', multipartMiddleware, async (req, res)=>{
try{
let data = req.body;
let object = await gameObject[data.id? 'update' : 'create'](req, data)
res.json({status: 'OK', object});
}catch(err){
console.error(err);
res.status(500).json({status: 'ERR', err});
}
});
/**
* List
*/
router.post('/', async (req, res)=>{
let result = await gameObject.list(req.body);
res.json(result);
})
router.get('/', async (req, res)=>{
})
router.get('/:id', async (req, res)=>{
let object = await gameObject.read(parseInt(req.params.id));
res.json(object);
})
app.webServer.xapp.use(this.route, router);
}
}
export {GameObjectsController}