52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
const { db, execQueryAsync, execQueryAsyncWithId } = require("./db.js");
|
|
const DEBUG = require("../utils/debug").DEBUG;
|
|
|
|
async function registerMailbox(userId, pwd, xoauth, xoauth2, host, port, tls) {
|
|
const query = `
|
|
INSERT INTO app_account
|
|
(user_id, account_pwd, xoauth, xoauth2, host, port, tls) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
`;
|
|
const values = [userId, pwd, xoauth, xoauth2, host, port, tls];
|
|
return await execQueryAsyncWithId(query, values);
|
|
}
|
|
|
|
async function getMailboxes() {
|
|
const query = `
|
|
SELECT app_account.account_id AS id, address.email
|
|
FROM app_account INNER JOIN address
|
|
WHERE address.address_id = app_account.user_id
|
|
`;
|
|
const values = [];
|
|
return await execQueryAsync(query, values);
|
|
}
|
|
|
|
async function getRooms(mailboxId) {
|
|
const query = `
|
|
SELECT
|
|
app_room.room_id AS id,
|
|
app_room.room_name AS roomName,
|
|
address.email AS user,
|
|
app_room.owner_id AS userId,
|
|
app_room.notSeen,
|
|
mailbox_message.mailbox_id AS mailboxId
|
|
FROM app_room
|
|
INNER JOIN message
|
|
INNER JOIN mailbox_message
|
|
INNER JOIN address
|
|
WHERE
|
|
message.message_id = app_room.message_id AND
|
|
mailbox_message.mailbox_id = 1 AND
|
|
mailbox_message.message_id = message.message_id AND
|
|
address.address_id = app_room.owner_id
|
|
`;
|
|
// todo mailboxId
|
|
const values = [];
|
|
return await execQueryAsync(query, values);
|
|
}
|
|
|
|
module.exports = {
|
|
registerMailbox,
|
|
getMailboxes,
|
|
getRooms
|
|
};
|