27 lines
942 B
TypeScript
27 lines
942 B
TypeScript
import { Response } from "express";
|
|
import { getAccounts, registerAccount } from "../db/api-db";
|
|
import { getAddresseId } from "../db/utils/mail";
|
|
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;
|
|
getAddresseId(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
|
|
}
|
|
}
|