40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { Response } from "express";
|
|
import { getAccounts, getRooms, registerAccount } from "../db/api-db";
|
|
import { getAddressId } from "../db/utils/mail";
|
|
import logger from "../system/Logger";
|
|
import statusCodes from "../utils/statusCodes";
|
|
|
|
export default class Account {
|
|
static async getAll(body, res: Response) {
|
|
getAccounts().then((data) => {
|
|
res.status(statusCodes.OK).json(data);
|
|
});
|
|
}
|
|
|
|
static async register(body, res: Response) {
|
|
const { email, pwd, xoauth, xoauth2, host, port, tls } = body;
|
|
getAddressId(email).then((addressId) => {
|
|
registerAccount(addressId, pwd, xoauth, xoauth2, host, port, tls)
|
|
.then((mailboxId) => {
|
|
res.status(statusCodes.OK).json({ id: mailboxId });
|
|
})
|
|
.catch(() => {
|
|
res.status(statusCodes.INTERNAL_SERVER_ERROR);
|
|
});
|
|
});
|
|
// todo change mailbox to account
|
|
}
|
|
|
|
static async getRooms(body, res: Response) {
|
|
const { mailboxId, offset, limit } = body;
|
|
getRooms(mailboxId)
|
|
.then((rooms) => {
|
|
res.status(statusCodes.OK).json(rooms);
|
|
})
|
|
.catch((err) => {
|
|
logger.err(err);
|
|
res.status(statusCodes.INTERNAL_SERVER_ERROR);
|
|
});
|
|
}
|
|
}
|