2024-10-01 12:57:53 +00:00
|
|
|
// Entrypoint
|
2024-10-14 13:50:47 +00:00
|
|
|
let Api;
|
|
|
|
|
|
|
|
function Main(api){
|
|
|
|
Api = api;
|
|
|
|
|
2024-10-01 12:57:53 +00:00
|
|
|
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
|
2024-10-16 09:48:50 +00:00
|
|
|
book: { type: "ObjectId", ref: "Book"}
|
2024-10-14 13:50:47 +00:00
|
|
|
});
|
|
|
|
|
2024-10-16 09:48:50 +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"
|
2024-10-16 09:48:50 +00:00
|
|
|
})
|
|
|
|
*/
|
|
|
|
|
|
|
|
console.log("FUNCIONA!!!!");
|
|
|
|
res.json({
|
|
|
|
status: "ok"
|
|
|
|
})
|
2024-10-14 17:25:46 +00:00
|
|
|
})
|
2024-10-16 09:48:50 +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
|
|
|
})
|
|
|
|
|
2024-10-15 12:50:14 +00:00
|
|
|
Api.socket.on("test", () => console.log("test"));
|
2024-10-14 13:50:47 +00:00
|
|
|
// Api.router.createModelRoutes(itemModel, 'item');
|
2024-10-01 12:57:53 +00:00
|
|
|
}
|
|
|
|
|
2024-10-14 13:50:47 +00:00
|
|
|
export { Main, Api };
|