dragonroll/backend/services/api.js

103 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-10-05 10:57:47 +00:00
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
2024-10-05 12:31:09 +00:00
/**
2024-10-05 17:27:28 +00:00
* Class for managing the backend api
* @hideconstructor
2024-10-05 12:31:09 +00:00
*/
2024-10-05 17:27:28 +00:00
class BackendApi {
#_plugin;
#_router;
/**
* This object is already created for you
* @param {plugin} Plugin instance
*/
constructor(plugin){
this.#_plugin = plugin;
this.#_router = new BackendRouter(plugin.package);
}
2024-10-05 12:31:09 +00:00
2024-10-05 17:27:28 +00:00
/**
* Gets the router for your plugin
* @type {BackendRouter}
*/
get router(){
return this.#_router;
}
/**
* Returns a new database model for the plugin
* @param {String} name
* @param {Object} schema
* @returns {Model}
*/
createModel(name, schema){
return new Model(name, this.#_plugin, schema);
}
};
/**
* This class registers routes to the backend that can be accessed from the frontend
* @hideconstructor
*/
class BackendRouter {
#_root;
constructor(path){
this.#_root = `plugins/${path}`;
2024-10-05 12:31:09 +00:00
}
/**
* Hola
2024-10-05 17:27:28 +00:00
* @param {String} route
2024-10-05 12:31:09 +00:00
*/
get(route){
}
/**
* @param {String} route
*
*/
post(route){
}
/**
* @param {String} route
*
*/
put(route){
}
/**
* @param {String} route
*
*/
delete(route){
}
}
2024-10-05 17:27:28 +00:00
/**
* @hideconstructor
*/
2024-10-05 23:36:18 +00:00
class BackendModel {
2024-10-05 17:27:28 +00:00
#_name;
2024-10-05 12:31:09 +00:00
#_plugin;
2024-10-05 17:27:28 +00:00
#_schema;
2024-10-05 10:57:47 +00:00
2024-10-05 17:27:28 +00:00
constructor(name, plugin, schema){
this.#_name = name;
this.#_plugin = plugin;
this.#_schema = schema;
2024-10-05 10:57:47 +00:00
}
};
2024-10-05 17:27:28 +00:00
2024-10-05 10:57:47 +00:00
module.exports = {
2024-10-05 17:27:28 +00:00
BackendApi
2024-10-05 10:57:47 +00:00
}