fetching mailboxes from api
This commit is contained in:
26
back/db/api.js
Normal file
26
back/db/api.js
Normal file
@@ -0,0 +1,26 @@
|
||||
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);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
registerMailbox,
|
||||
getMailboxes
|
||||
};
|
||||
@@ -14,7 +14,7 @@ async function registerMessage(timestamp, rfc822size, messageId) {
|
||||
function registerMailbox_message(mailboxId, uid, messageId, modseq, seen, deleted) {
|
||||
const query = `
|
||||
INSERT IGNORE INTO mailbox_message
|
||||
(mailbox_id, uid, message_id, modseq, seen, deleted) VALUES (?, ?, ?, ?, ?, ?)
|
||||
(mailbox_id, uid, message_id, modseq, seen, deleted) VALUES (1, 19, 10, '12450', 0, 0)
|
||||
`;
|
||||
const values = [mailboxId, uid, messageId, modseq, seen, deleted];
|
||||
execQuery(query, values);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
const { db, execQueryAsync, execQueryAsyncWithId } = require("./db.js");
|
||||
const DEBUG = require("../utils/debug").DEBUG;
|
||||
|
||||
async function createRoom(roomName, ownerId) {
|
||||
const query = `INSERT INTO app_room (room_name, owner_id) VALUES (?, ?)`;
|
||||
const values = [roomName.substring(0, 255), ownerId];
|
||||
async function createRoom(roomName, ownerId, messageId) {
|
||||
const query = `INSERT INTO app_room (room_name, owner_id, message_id) VALUES (?, ?, ?)`;
|
||||
const values = [roomName.substring(0, 255), ownerId, messageId];
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
// todo add members
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ CREATE TABLE mailbox (
|
||||
first_recent INT NOT NULL DEFAULT 1,
|
||||
uidvalidity INT NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (mailbox_id),
|
||||
UNIQUE KEY (mailbox_name),
|
||||
FOREIGN KEY (account_id) REFERENCES app_account(account_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
@@ -121,11 +120,13 @@ CREATE TABLE app_room (
|
||||
room_id INT AUTO_INCREMENT,
|
||||
room_name VARCHAR(255) NOT NULL,
|
||||
owner_id INT NOT NULL,
|
||||
message_id INT NOT NULL,
|
||||
isGroup BOOLEAN NOT NULL DEFAULT false,
|
||||
notSeen INT NOT NULL DEFAULT 0,
|
||||
lastUpdate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
|
||||
PRIMARY KEY (room_id),
|
||||
FOREIGN KEY (owner_id) REFERENCES address(address_id)
|
||||
FOREIGN KEY (owner_id) REFERENCES address(address_id),
|
||||
FOREIGN KEY (message_id) REFERENCES message(message_id)
|
||||
);
|
||||
|
||||
-- 12
|
||||
@@ -145,7 +146,7 @@ CREATE TABLE app_space_message (
|
||||
message_id INT NOT NULL,
|
||||
room_id INT,
|
||||
thread_id INT,
|
||||
UNIQUE KEY (member_id, room_id, thread_id),
|
||||
UNIQUE KEY (message_id, room_id, thread_id),
|
||||
FOREIGN KEY (message_id) REFERENCES message(message_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (room_id) REFERENCES app_room(room_id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (thread_id) REFERENCES app_thread(thread_id) ON DELETE SET NULL
|
||||
|
||||
Reference in New Issue
Block a user