SpaceNinjaServer/src/controllers/api/inboxController.ts

37 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-05-19 15:22:48 -03:00
import { RequestHandler } from "express";
2024-07-06 01:15:01 +08:00
import { deleteAllReadInbox, deleteInbox, getInboxReponse, readInbox } from "@/src/services/inboxService";
import { getAccountIdForRequest } from "@/src/services/loginService";
2023-05-19 15:22:48 -03:00
2024-07-06 01:15:01 +08:00
// eslint-disable-next-line @typescript-eslint/no-misused-promises
const inboxController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const messageId = req.query.messageId as string;
const deleteId = req.query.deleteId as string;
const lastMessage = req.query.lastMessage as string;
if (messageId) {
const inbox = await readInbox(messageId);
res.json({ Inbox: [inbox] });
}
if (deleteId) {
if (deleteId == "DeleteAllRead") {
await deleteAllReadInbox(accountId);
} else {
await deleteInbox(deleteId);
}
const result = await getInboxReponse(accountId);
res.json(result);
}
if (lastMessage) {
/* empty */
}
const result = await getInboxReponse(accountId);
if (result) res.json(result);
else res.json({ Inbox: [] });
2023-05-19 15:22:48 -03:00
};
export { inboxController };