const notifications = { 10: [{ desc: "Test", author: "Owner Lvorex" }] } /** * @param {string} key * @returns {Array} */ app.use("/getPlayerNotifications.lvorex", express.json()) app.post("/getPlayerNotifications.lvorex", async (req, res) => { const postBody = req.body const { keyFound, userKey } = await controlKey(req, postBody.key) if (keyFound === false) return res.json({ code: 404, message: "Not authorized." }) if(notifications[userKey.userId]) return res.json({ code: 200, message: notifications[userKey.userId] }) res.json({ code: 200, message: [] }) }) /** * @param {string} key * @param {string} desc * @param {string} author * @param {boolean} self Optional * @returns {string} */ app.use("/sendNotification.lvorex", express.json()) app.post("/sendNotification.lvorex", async (req, res) => { const postBody = req.body const { keyFound, userKey } = await controlKey(req, postBody.key) if (keyFound === false) return res.json({ code: 404, message: "Not authorized." }) if (postBody.self) { if (notifications[userKey.userId]) { notifications[userKey.userId].push({ desc: postBody.desc, author: postBody.author }) } else { notifications[userKey.userId] = [{ desc: postBody.desc, author: postBody.author }] } } else { usersKeys.forEach(key => { if (notifications[key.userId]) { notifications[key.userId].push({ desc: postBody.desc, author: postBody.author }) } else { notifications[key.userId] = [{ desc: postBody.desc, author: postBody.author }] } }) } res.json({ code: 200, message: "Sent." }) }) /** * @param {string} key * @returns {string} */ app.use("/clearAllUserNotifications.lvorex", express.json()) app.post("/clearAllUserNotifications.lvorex", async (req, res) => { const postBody = req.body const { keyFound, userKey } = await controlKey(req, postBody.key) if (keyFound === false) return res.json({ code: 404, message: "Not authorized." }) if (notifications[userKey.userId]) { delete notifications[userKey.userId] } res.json({ code: 200, message: "Cleared" }) })