advancement on logic of app
This commit is contained in:
@@ -18,9 +18,9 @@ bdd.connect(function (err) {
|
||||
}
|
||||
});
|
||||
|
||||
function execQueryAsync(query) {
|
||||
function execQueryAsync(query, values) {
|
||||
return new Promise((resolve, reject) => {
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
bdd.query(query, values, (err, results, fields) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
@@ -30,9 +30,9 @@ function execQueryAsync(query) {
|
||||
});
|
||||
}
|
||||
|
||||
function execQueryAsyncWithId(query) {
|
||||
function execQueryAsyncWithId(query, values) {
|
||||
return new Promise((resolve, reject) => {
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
bdd.query(query, values, (err, results, fields) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
@@ -42,10 +42,13 @@ function execQueryAsyncWithId(query) {
|
||||
});
|
||||
}
|
||||
|
||||
function execQuery(query) {
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) throw (err);
|
||||
return results
|
||||
function execQuery(query, values) {
|
||||
bdd.query(query, values, (err, results, fields) => {
|
||||
if (err) {
|
||||
DEBUG.log(err);
|
||||
throw (err);
|
||||
}
|
||||
return results;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { bdd, execQueryAsyncWithId } = require("./bdd.js");
|
||||
const { bdd, execQueryAsync, execQueryAsyncWithId } = require("./bdd.js");
|
||||
const DEBUG = require("../utils/debug").DEBUG;
|
||||
|
||||
function isValidEmail(email) {
|
||||
@@ -10,9 +10,11 @@ function isValidEmail(email) {
|
||||
async function getAddresseId(email, name) {
|
||||
const localpart = email.split("@")[0];
|
||||
const domain = email.split("@")[1];
|
||||
const query = `INSERT INTO address (address_name, localpart, domain, email) VALUES ('${name}', '${localpart}', '${domain}', '${email}')
|
||||
ON DUPLICATE KEY UPDATE email = '${email}', address_id = LAST_INSERT_ID(address_id)`;
|
||||
return await execQueryAsyncWithId(query);
|
||||
const query = `INSERT INTO address
|
||||
(address_name, localpart, domain, email) VALUES (?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE email = ?, address_id = LAST_INSERT_ID(address_id)`;
|
||||
const values = [name, localpart, domain, email, email];
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
function getMailboxId(email) {
|
||||
@@ -23,18 +25,15 @@ function getMailboxId(email) {
|
||||
}
|
||||
|
||||
async function getFieldId(field) {
|
||||
const query = `INSERT INTO field_name (field_name) VALUES ('${field}') ON DUPLICATE KEY UPDATE field_id=LAST_INSERT_ID(field_id)`;
|
||||
return await execQueryAsyncWithId(query);
|
||||
const query = `INSERT INTO field_name (field_name) VALUES (?) ON DUPLICATE KEY UPDATE field_id=LAST_INSERT_ID(field_id)`;
|
||||
const values = [field]
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
function findRoomByOwner(ownerId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `SELECT room_id FROM app_room WHERE owner_id = '${ownerId}'`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) reject(err);
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
async function findRoomByOwner(ownerId) {
|
||||
const query = `SELECT room_id FROM app_room WHERE owner_id = ?`;
|
||||
const values = [ownerId];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
const {bdd} = require("./bdd.js");
|
||||
const { bdd, execQuery, execQueryAsync, execQueryAsyncWithId } = require("./bdd.js");
|
||||
const DEBUG = require("../utils/debug").DEBUG;
|
||||
|
||||
function registerMessage(timestamp, rfc822size, messageId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT INTO message (idate, messageID, rfc822size) VALUES ('${timestamp}', '${messageId}', ${rfc822size})
|
||||
ON DUPLICATE KEY UPDATE message_id = LAST_INSERT_ID(message_id)`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) reject(err);
|
||||
resolve(results.insertId);
|
||||
});
|
||||
});
|
||||
async function registerMessage(timestamp, rfc822size, messageId) {
|
||||
const query = `INSERT INTO message
|
||||
(idate, messageID, rfc822size) VALUES (?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE message_id = LAST_INSERT_ID(message_id)`;
|
||||
const values = [timestamp, messageId, rfc822size];
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
function registerMailbox_message(mailboxId, uid, messageId, modseq, seen, deleted) {
|
||||
@@ -38,17 +35,15 @@ function saveBodypart(bytes, hash, text, data) {
|
||||
}
|
||||
|
||||
function saveHeader_fields(message, part, position, field, value) {
|
||||
const query = `INSERT IGNORE INTO header_field (message_id, part, position, field_id, value) VALUES ('${message}', '${part}', '${position}', '${field}', '${value}')`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
const query = `INSERT INTO header_field (message_id, part, position, field_id, value) VALUES (?, ?, ?, ?, ?)`;
|
||||
const values = [message, part, position, field, value];
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
function saveAddress_fields(message, part, position, field, number, address) {
|
||||
const query = `INSERT IGNORE INTO address_field (message_id , part, position, field_id, number, address_id) VALUES ('${message}', '${part}', '${position}', '${field}', '${number}', '${address}')`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
const query = `INSERT INTO address_field (message_id , part, position, field_id, number, address_id) VALUES (?, ?, ?, ?, ?, ?)`;
|
||||
const values = [message, part, position, field, number, address];
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
const bdd = require("./bdd.js").bdd;
|
||||
const { bdd, execQueryAsync, execQueryAsyncWithId } = require("./bdd.js");
|
||||
const DEBUG = require("../utils/debug").DEBUG;
|
||||
|
||||
function createRoom(roomName, ownerId, notSeen) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT INTO app_room (room_name, owner_id, notSeen) VALUES ('${roomName}', '${ownerId}', '${notSeen}')`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) reject(err);
|
||||
resolve(results.insertId);
|
||||
});
|
||||
});
|
||||
async function createRoom(roomName, ownerId) {
|
||||
const query = `INSERT INTO app_room (room_name, owner_id) VALUES (?, ?)`;
|
||||
const values = [roomName.substring(0, 255), ownerId];
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
// todo add members
|
||||
}
|
||||
|
||||
function registerMessageInRoom(messageId, roomId, isSeen) {
|
||||
const query = `INSERT INTO app_room_message (message_id, room_id) VALUES ('${messageId}', '${roomId}')`;
|
||||
const query = `INSERT INTO app_space_message (message_id, room_id) VALUES ('${messageId}', '${roomId}')`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
@@ -32,14 +29,13 @@ function incrementNotSeenRoom(roomId) {
|
||||
// todo
|
||||
}
|
||||
|
||||
function createThread(roomId, threadName, notSeen, isDm) {
|
||||
function createThread(roomId, threadName, isDm) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT INTO app_thread
|
||||
(room_id, thread_name, notSeen, isDm)
|
||||
(room_id, thread_name, isDm)
|
||||
VALUES (
|
||||
'${roomId}',
|
||||
'${threadName}',
|
||||
'${notSeen}',
|
||||
'${isDm}',
|
||||
)`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
@@ -47,11 +43,13 @@ function createThread(roomId, threadName, notSeen, isDm) {
|
||||
resolve(results.insertId);
|
||||
});
|
||||
});
|
||||
|
||||
// todo add members
|
||||
}
|
||||
|
||||
function registerMessageInThread(messageId, threadId, isSeen) {
|
||||
// todo check if it is still a thread or should be a room
|
||||
const query = `INSERT IGNORE INTO app_room_messages
|
||||
const query = `INSERT IGNORE INTO app_space_message
|
||||
(message_id, thread_id) VALUES ('${messageId}', '${threadId}')`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) throw err;
|
||||
@@ -83,8 +81,15 @@ function isRoomGroup(roomId) {
|
||||
});
|
||||
}
|
||||
|
||||
function findSpacesFromMessage(messageId) {
|
||||
const query = ``;
|
||||
async function findSpacesFromMessage(messageId) {
|
||||
const query = `SELECT room_id, thread_id FROM app_space_message WHERE message_id = '${messageId}'`;
|
||||
return await execQueryAsync(query);
|
||||
}
|
||||
|
||||
async function hasSameMembersAsParent(messageId, parentID) {
|
||||
// const query = `SELECT `;
|
||||
// return await execQueryAsync(query)
|
||||
// todo
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
/**
|
||||
* Mail storage
|
||||
*/
|
||||
-- Mail storage
|
||||
|
||||
-- 1
|
||||
CREATE TABLE address (
|
||||
@@ -13,6 +11,20 @@ CREATE TABLE address (
|
||||
UNIQUE KEY (email)
|
||||
);
|
||||
|
||||
-- 2 app
|
||||
CREATE TABLE app_account (
|
||||
account_id INT AUTO_INCREMENT,
|
||||
user_id INT NOT NULL,
|
||||
account_pwd BINARY(22),
|
||||
xoauth VARCHAR(116),
|
||||
xoauth2 VARCHAR(116),
|
||||
host VARCHAR(255) NOT NULL DEFAULT 'localhost',
|
||||
port INT(5) NOT NULL DEFAULT 143,
|
||||
tls BOOLEAN NOT NULL DEFAULT true,
|
||||
PRIMARY KEY (account_id),
|
||||
FOREIGN KEY (user_id) REFERENCES address(address_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 3
|
||||
CREATE TABLE mailbox (
|
||||
mailbox_id INT AUTO_INCREMENT,
|
||||
@@ -44,14 +56,24 @@ CREATE TABLE mailbox_message (
|
||||
uid INT,
|
||||
message_id INT,
|
||||
modseq BIGINT NOT NULL,
|
||||
seen BIT(1) NOT NULL DEFAULT 0,
|
||||
deleted BIT(1) NOT NULL DEFAULT 0,
|
||||
seen BOOLEAN NOT NULL DEFAULT false,
|
||||
deleted BOOLEAN NOT NULL DEFAULT false,
|
||||
PRIMARY KEY (uid, message_id),
|
||||
FOREIGN KEY (mailbox_id) REFERENCES mailbox(mailbox_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (message_id) REFERENCES message(message_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 6
|
||||
CREATE TABLE bodypart (
|
||||
bodypart_id INT AUTO_INCREMENT,
|
||||
bytes INT NOT NULL,
|
||||
hash TEXT NOT NULL,
|
||||
text TEXT,
|
||||
data BINARY,
|
||||
PRIMARY KEY (bodypart_id)
|
||||
);
|
||||
|
||||
-- 7
|
||||
CREATE TABLE part_number (
|
||||
message_id INT NOT NULL,
|
||||
part VARCHAR(128) NOT NULL,
|
||||
@@ -63,16 +85,6 @@ CREATE TABLE part_number (
|
||||
FOREIGN KEY (bodypart_id) REFERENCES bodypart(bodypart_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 7
|
||||
CREATE TABLE bodypart (
|
||||
bodypart_id INT AUTO_INCREMENT,
|
||||
bytes INT NOT NULL,
|
||||
hash TEXT NOT NULL,
|
||||
text TEXT,
|
||||
data BINARY,
|
||||
PRIMARY KEY (bodypart_id)
|
||||
);
|
||||
|
||||
-- 8
|
||||
CREATE TABLE field_name (
|
||||
field_id INT AUTO_INCREMENT,
|
||||
@@ -106,30 +118,14 @@ CREATE TABLE address_field (
|
||||
FOREIGN KEY (address_id) REFERENCES address(address_id)
|
||||
);
|
||||
|
||||
/**
|
||||
* App table
|
||||
*/
|
||||
|
||||
-- 2
|
||||
CREATE TABLE app_account (
|
||||
account_id INT AUTO_INCREMENT,
|
||||
user_id INT NOT NULL,
|
||||
account_pwd BINARY(22),
|
||||
xoauth VARCHAR(116),
|
||||
xoauth2 VARCHAR(116),
|
||||
host VARCHAR(255) NOT NULL DEFAULT 'localhost',
|
||||
port INT(5) NOT NULL DEFAULT 143,
|
||||
tls BIT(1) NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (account_id),
|
||||
FOREIGN KEY (user_id) REFERENCES address(address_id) ON DELETE CASCADE
|
||||
);
|
||||
-- App table
|
||||
|
||||
-- 11
|
||||
CREATE TABLE app_room (
|
||||
room_id INT AUTO_INCREMENT,
|
||||
room_name VARCHAR(30) NOT NULL,
|
||||
room_name VARCHAR(255) NOT NULL,
|
||||
owner_id INT NOT NULL,
|
||||
isGroup BIT(1) NOT NULL DEFAULT 0,
|
||||
isGroup BOOLEAN NOT NULL DEFAULT false,
|
||||
notSeen INT NOT NULL DEFAULT 0,
|
||||
lastUpdate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
|
||||
PRIMARY KEY (room_id),
|
||||
@@ -140,16 +136,16 @@ CREATE TABLE app_room (
|
||||
CREATE TABLE app_thread (
|
||||
thread_id INT AUTO_INCREMENT,
|
||||
room_id INT NOT NULL,
|
||||
thread_name VARCHAR(30) NOT NULL,
|
||||
thread_name VARCHAR(255) NOT NULL,
|
||||
notSeen INT NOT NULL DEFAULT 0,
|
||||
lastUpdate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
|
||||
isDm BIT(1) NOT NULL DEFAULT 0,
|
||||
isDm BOOLEAN NOT NULL DEFAULT false,
|
||||
PRIMARY KEY (thread_id),
|
||||
FOREIGN KEY (room_id) REFERENCES app_room(room_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 13
|
||||
CREATE TABLE app_room_message (
|
||||
CREATE TABLE app_space_message (
|
||||
message_id INT NOT NULL,
|
||||
room_id INT,
|
||||
thread_id INT,
|
||||
|
||||
Reference in New Issue
Block a user