39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { Router } from "express";
|
|
import Notification from "@schemas/Notification";
|
|
import { islogged } from "@/utility";
|
|
import { authRouter } from "./auth/index";
|
|
import mongoose from "mongoose";
|
|
import { apiRouter } from "./api";
|
|
import sync from "@/helpers/sync";
|
|
import usettings, { Features } from "@/helpers/usettings";
|
|
|
|
const router = Router();
|
|
|
|
router.use('/', apiRouter)
|
|
router.use('/auth', authRouter)
|
|
|
|
router.get("/healthcheck", async (req, res) => {
|
|
res.status(200).send({
|
|
uptime: process.uptime(),
|
|
date: new Date(),
|
|
db: mongoose.connection.readyState
|
|
})
|
|
})
|
|
|
|
router.post("/notif", islogged, usettings.mw(Features.Notif), async (req, res) => {
|
|
var obj = { user: req.user._id, ...req.body }
|
|
await Notification.findOneAndUpdate(obj, obj, { upsert: true })
|
|
res.send({ "status": 200 })
|
|
})
|
|
|
|
router.get("/sync", islogged, async (req, res) => {
|
|
const sub = sync.subscribe(req.user._id, v => {
|
|
res.send(v)
|
|
})
|
|
|
|
req.once('close', () => {
|
|
sub.unsubscribe()
|
|
})
|
|
})
|
|
|
|
export default router; |