dragonroll/plugins/dnd-5e/backend/main.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

// Entrypoint
2024-10-14 13:50:47 +00:00
let Api;
function Main(api){
Api = api;
console.log("Hello World from backend!");
2024-10-14 13:50:47 +00:00
// Create our module in the backend. We only need the package name, it must be equal to the one that
// we made inside the client
let dndModule = Api.createModule('dnd-5e');
let itemModel = Api.createModel("item", {
2024-10-14 17:25:46 +00:00
name: { type: "String", required: true, default: "New item"},
type: { type: "String", required: true, default: "Item" },
2024-10-14 13:50:47 +00:00
info: { type: "Object" }, // For preview only
data: { type: "Object" }, // Advanced item
book: { type: "ObjectId", ref: "Book"}
2024-10-14 13:50:47 +00:00
});
2024-10-14 17:25:46 +00:00
dndModule.router.get('/testing', (req, res) => {
/*
let item = itemModel.create({
name: "Test item!",
type: "The test item"
})
*/
console.log("FUNCIONA!!!!");
res.json({
status: "ok"
})
2024-10-14 17:25:46 +00:00
})
dndModule.router.get('/item/list', (req, res) => {
const campaign = req.campaign;
itemModel.find({campaign}).select('-data').lean().then(data => {
res.json({status: "ok", data});
});
2024-10-14 13:50:47 +00:00
})
Api.socket.on("test", () => console.log("test"));
2024-10-14 13:50:47 +00:00
// Api.router.createModelRoutes(itemModel, 'item');
}
2024-10-14 13:50:47 +00:00
export { Main, Api };