started to convert to typescript
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const { execQueryAsync, execQueryAsyncWithId } = require("./db.js");
|
||||
const { queryCcId, queryToId, queryFromId } = require("./utils/addressQueries.js");
|
||||
import { execQueryAsync, execQueryAsyncWithId } from "./db";
|
||||
import { queryCcId, queryToId, queryFromId } from "./utils/addressQueries";
|
||||
|
||||
async function registerAccount(userId, pwd, xoauth, xoauth2, host, port, tls) {
|
||||
export async function registerAccount(userId, pwd, xoauth, xoauth2, host, port, tls) {
|
||||
const query = `
|
||||
INSERT INTO app_account
|
||||
(user_id, account_pwd, xoauth, xoauth2, host, port, tls) VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
@@ -10,7 +10,7 @@ async function registerAccount(userId, pwd, xoauth, xoauth2, host, port, tls) {
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
async function getAccounts() {
|
||||
export async function getAccounts() {
|
||||
// todo mailbox or account id ?
|
||||
const query = `
|
||||
SELECT
|
||||
@@ -27,7 +27,7 @@ async function getAccounts() {
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
async function getRooms(mailboxId) {
|
||||
export async function getRooms(mailboxId) {
|
||||
const query = `
|
||||
SELECT
|
||||
app_room.room_id AS id,
|
||||
@@ -51,7 +51,7 @@ async function getRooms(mailboxId) {
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
async function getMessages(roomId) {
|
||||
export async function getMessages(roomId) {
|
||||
// todo attachements name
|
||||
const query = `
|
||||
SELECT
|
||||
@@ -97,7 +97,7 @@ async function getMessages(roomId) {
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
async function getMembers(roomId) {
|
||||
export async function getMembers(roomId) {
|
||||
const query = `
|
||||
SELECT
|
||||
address.address_id,
|
||||
@@ -109,12 +109,4 @@ async function getMembers(roomId) {
|
||||
`;
|
||||
const values = [roomId];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
registerAccount,
|
||||
getAccounts,
|
||||
getRooms,
|
||||
getMessages,
|
||||
getMembers
|
||||
};
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
const mysql = require("mysql");
|
||||
const { logger } = require("../system/Logger");
|
||||
const MYSQL = require("./config.json").mysql;
|
||||
import mysql from "mysql";
|
||||
import { logger } from "../system/Logger";
|
||||
import MYSQL from "./config.json";
|
||||
|
||||
const db = mysql.createConnection({
|
||||
// todo remove export
|
||||
export const db = mysql.createConnection({
|
||||
host: MYSQL.host,
|
||||
user: MYSQL.user,
|
||||
password: MYSQL.pwd,
|
||||
@@ -17,7 +18,7 @@ db.connect(function (err) {
|
||||
}
|
||||
});
|
||||
|
||||
function execQueryAsync(query, values) {
|
||||
export function execQueryAsync(query, values) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.query(query, values, (err, results, fields) => {
|
||||
if (err) {
|
||||
@@ -29,7 +30,7 @@ function execQueryAsync(query, values) {
|
||||
});
|
||||
}
|
||||
|
||||
function execQueryAsyncWithId(query, values) {
|
||||
export function execQueryAsyncWithId(query, values) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.query(query, values, (err, results, fields) => {
|
||||
if (err) {
|
||||
@@ -41,7 +42,7 @@ function execQueryAsyncWithId(query, values) {
|
||||
});
|
||||
}
|
||||
|
||||
function execQuery(query, values) {
|
||||
export function execQuery(query, values) {
|
||||
db.query(query, values, (err, results, fields) => {
|
||||
if (err) {
|
||||
logger.error(err);
|
||||
@@ -49,11 +50,4 @@ function execQuery(query, values) {
|
||||
}
|
||||
return results;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
db, // todo remove this
|
||||
execQuery,
|
||||
execQueryAsync,
|
||||
execQueryAsyncWithId
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
const { execQueryAsyncWithId, execQueryAsync, execQuery } = require("../db");
|
||||
import { execQueryAsyncWithId, execQueryAsync, execQuery } from "../db";
|
||||
|
||||
async function getAllAccounts() {
|
||||
export async function getAllAccounts() {
|
||||
const query = `
|
||||
SELECT
|
||||
app_account.account_id AS id,
|
||||
@@ -16,34 +16,26 @@ async function getAllAccounts() {
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
async function getAllMailboxes(accountId) {
|
||||
export async function getAllMailboxes(accountId) {
|
||||
const query = 'SELECT * FROM mailbox WHERE mailbox.account_id = ?';
|
||||
const values = [accountId];
|
||||
return await execQueryAsync(query, values)
|
||||
}
|
||||
|
||||
async function registerMailbox(accountId, mailboxName) {
|
||||
export async function registerMailbox(accountId, mailboxName) {
|
||||
const query = `INSERT INTO mailbox (account_id, mailbox_name) VALUES (?, ?)`;
|
||||
const values = [accountId, mailboxName];
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
async function getMailbox(mailboxId) {
|
||||
export async function getMailbox(mailboxId) {
|
||||
const query = `SELECT * FROM mailbox WHERE mailbox_id = ?`;
|
||||
const values = [mailboxId];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
function updateMailbox(mailboxId, uidnext) {
|
||||
export function updateMailbox(mailboxId, uidnext) {
|
||||
const query = `UPDATE mailbox SET uidnext = ? WHERE mailbox_id = ?`;
|
||||
const values = [uidnext, mailboxId];
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAllAccounts,
|
||||
getAllMailboxes,
|
||||
registerMailbox,
|
||||
getMailbox,
|
||||
updateMailbox
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
const { execQueryAsync, execQueryAsyncWithId } = require("./db.js");
|
||||
import { execQueryAsync, execQueryAsyncWithId } from "./db";
|
||||
|
||||
async function getAddresseId(email, name) {
|
||||
export async function getAddresseId(email, name) {
|
||||
const localpart = email.split("@")[0];
|
||||
const domain = email.split("@")[1];
|
||||
const query = `INSERT INTO address
|
||||
@@ -10,19 +10,19 @@ async function getAddresseId(email, name) {
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
async function getFieldId(field) {
|
||||
export async function getFieldId(field) {
|
||||
const query = `INSERT INTO field_name (field_name) VALUES (?) ON DUPLICATE KEY UPDATE field_id=LAST_INSERT_ID(field_id)`;
|
||||
const values = [field]
|
||||
const values = [field];
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
async function findRoomByOwner(ownerId) {
|
||||
export async function findRoomByOwner(ownerId) {
|
||||
const query = `SELECT room_id FROM app_room WHERE owner_id = ?`;
|
||||
const values = [ownerId];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
async function getUserIdOfMailbox(boxId) {
|
||||
export async function getUserIdOfMailbox(boxId) {
|
||||
const query = `
|
||||
SELECT app_account.user_id
|
||||
FROM mailbox
|
||||
@@ -32,10 +32,3 @@ async function getUserIdOfMailbox(boxId) {
|
||||
const values = [boxId];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAddresseId,
|
||||
getFieldId,
|
||||
findRoomByOwner,
|
||||
getUserIdOfMailbox
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
const { transformEmojis } = require("../utils/string.js");
|
||||
const { db, execQuery, execQueryAsync, execQueryAsyncWithId } = require("./db.js");
|
||||
import { transformEmojis } from "../utils/string";
|
||||
import { execQuery, execQueryAsync, execQueryAsyncWithId } from "./db";
|
||||
|
||||
async function registerMessage(timestamp, rfc822size, messageId) {
|
||||
export async function registerMessage(timestamp, rfc822size, messageId) {
|
||||
const query = `
|
||||
INSERT INTO message
|
||||
(idate, messageID, rfc822size) VALUES (?, ?, ?)
|
||||
@@ -11,7 +11,7 @@ async function registerMessage(timestamp, rfc822size, messageId) {
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
function registerMailbox_message(mailboxId, uid, messageId, modseq, seen, deleted) {
|
||||
export 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 (?, ?, ?, ?, ?, ?)
|
||||
@@ -20,7 +20,7 @@ function registerMailbox_message(mailboxId, uid, messageId, modseq, seen, delete
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
function registerBodypart(messageId, part, bodypartId, bytes, nbLines) {
|
||||
export function registerBodypart(messageId, part, bodypartId, bytes, nbLines) {
|
||||
const query = `
|
||||
INSERT IGNORE INTO part_number
|
||||
(message_id, part, bodypart_id, bytes, nb_lines) VALUES (?, ?, ?, ?, ?)
|
||||
@@ -29,14 +29,14 @@ function registerBodypart(messageId, part, bodypartId, bytes, nbLines) {
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
async function saveBodypart(bytes, hash, text, data) {
|
||||
export async function saveBodypart(bytes, hash, text, data) {
|
||||
text = transformEmojis(text);
|
||||
const query = `INSERT IGNORE INTO bodypart (bytes, hash, text, data) VALUES (?, ?, ?, ?)`;
|
||||
const values = [bytes, hash, text, data];
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
async function saveHeader_fields(messageId, fieldId, bodypartId, part, value) {
|
||||
export async function saveHeader_fields(messageId, fieldId, bodypartId, part, value) {
|
||||
value = transformEmojis(value);
|
||||
const query = `
|
||||
INSERT IGNORE INTO header_field
|
||||
@@ -46,7 +46,7 @@ async function saveHeader_fields(messageId, fieldId, bodypartId, part, value) {
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
async function saveAddress_fields(messageId, fieldId, addressId, number) {
|
||||
export async function saveAddress_fields(messageId, fieldId, addressId, number) {
|
||||
const query = `
|
||||
INSERT IGNORE INTO address_field
|
||||
(message_id , field_id, address_id, number) VALUES (?, ?, ?, ?)
|
||||
@@ -55,7 +55,7 @@ async function saveAddress_fields(messageId, fieldId, addressId, number) {
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
function saveSource(messageId, content) {
|
||||
export function saveSource(messageId, content) {
|
||||
content = transformEmojis(content);
|
||||
const query = `
|
||||
INSERT INTO source (message_id, content) VALUES (?, ?)
|
||||
@@ -63,14 +63,4 @@ function saveSource(messageId, content) {
|
||||
`;
|
||||
const values = [messageId, content, content];
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
registerMessage,
|
||||
registerMailbox_message,
|
||||
saveHeader_fields,
|
||||
saveAddress_fields,
|
||||
registerBodypart,
|
||||
saveBodypart,
|
||||
saveSource
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
const { transformEmojis } = require("../utils/string.js");
|
||||
const { db, execQueryAsync, execQueryAsyncWithId, execQuery } = require("./db.js");
|
||||
const { queryFromId, queryToId, queryCcId } = require("./utils/addressQueries.js");
|
||||
import { transformEmojis } from "../utils/string";
|
||||
import { db, execQueryAsync, execQueryAsyncWithId, execQuery } from "./db";
|
||||
import { queryFromId, queryToId, queryCcId } from "./utils/addressQueries";
|
||||
|
||||
async function getAllMembers(messageId) {
|
||||
export async function getAllMembers(messageId) {
|
||||
const query = `
|
||||
SELECT GROUP_CONCAT(address.address_id) AS is
|
||||
FROM address
|
||||
@@ -15,13 +15,13 @@ async function getAllMembers(messageId) {
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
async function registerMember(roomId, memberId) {
|
||||
export async function registerMember(roomId, memberId) {
|
||||
const query = `INSERT IGNORE INTO app_room_member (room_id, member_id) VALUES (?, ?)`;
|
||||
const values = [roomId, memberId];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
async function createRoom(roomName, ownerId, messageId, roomType) {
|
||||
export async function createRoom(roomName, ownerId, messageId, roomType) {
|
||||
if (!roomName) roomName = "No room name";
|
||||
roomName = transformEmojis(roomName);
|
||||
const query = `INSERT IGNORE INTO app_room (room_name, owner_id, message_id, room_type) VALUES (?, ?, ?, ?)`;
|
||||
@@ -29,7 +29,7 @@ async function createRoom(roomName, ownerId, messageId, roomType) {
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
async function registerMessageInRoom(messageId, roomId, isSeen, idate) {
|
||||
export async function registerMessageInRoom(messageId, roomId, isSeen, idate) {
|
||||
const query = `INSERT IGNORE INTO app_room_message (message_id, room_id) VALUES (?, ?)`;
|
||||
const values = [messageId, roomId];
|
||||
await execQueryAsync(query, values);
|
||||
@@ -40,17 +40,17 @@ async function registerMessageInRoom(messageId, roomId, isSeen, idate) {
|
||||
// }
|
||||
}
|
||||
|
||||
function updateLastUpdateRoom(roomId, idate) {
|
||||
export function updateLastUpdateRoom(roomId, idate) {
|
||||
const query = `UPDATE app_room SET lastUpdate = ? WHERE room_id = ?`;
|
||||
const values = [idate, roomId];
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
function incrementNotSeenRoom(roomId) {
|
||||
export function incrementNotSeenRoom(roomId) {
|
||||
// todo
|
||||
}
|
||||
|
||||
async function getRoomInfo(messageID) {
|
||||
export async function getRoomInfo(messageID) {
|
||||
const query = `
|
||||
SELECT
|
||||
app_room.room_id
|
||||
@@ -65,13 +65,13 @@ async function getRoomInfo(messageID) {
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
async function registerThread(roomId, parentId, rootId) {
|
||||
export async function registerThread(roomId, parentId, rootId) {
|
||||
const query = `INSERT IGNORE INTO app_thread (room_id, parent_id, root_id) VALUES (?, ?, ?)`;
|
||||
const values = [roomId, parentId, rootId];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
async function isRoomGroup(roomId) {
|
||||
export async function isRoomGroup(roomId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `SELECT isGroup FROM app_room WHERE room_id = '${roomId}'`;
|
||||
db.query(query, (err, results, fields) => {
|
||||
@@ -81,13 +81,13 @@ async function isRoomGroup(roomId) {
|
||||
});
|
||||
}
|
||||
|
||||
async function findRoomsFromMessage(messageId) {
|
||||
export async function findRoomsFromMessage(messageId) {
|
||||
const query = `SELECT room_id FROM app_room_message WHERE message_id = ? ORDER BY room_id`;
|
||||
const values = [messageId];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
async function hasSameMembersAsParent(messageId, messageID) {
|
||||
export async function hasSameMembersAsParent(messageId, messageID) {
|
||||
const query1 = `
|
||||
SELECT
|
||||
GROUP_CONCAT(fromT.address_id) AS fromA,
|
||||
@@ -129,16 +129,4 @@ async function hasSameMembersAsParent(messageId, messageID) {
|
||||
addressesMsg1.length == addressesMsg2.length &&
|
||||
addressesMsg1.reduce((a, b) => a && addressesMsg2.includes(b), true)
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAllMembers,
|
||||
registerMember,
|
||||
createRoom,
|
||||
registerMessageInRoom,
|
||||
registerThread,
|
||||
isRoomGroup,
|
||||
findRoomsFromMessage,
|
||||
hasSameMembersAsParent,
|
||||
getRoomInfo
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user