started to convert to typescript

This commit is contained in:
grimhilt
2023-04-01 16:32:29 +02:00
parent 1d761fa6df
commit 9fbf5e5cf3
32 changed files with 1045 additions and 3897 deletions

34
back/db/mail.ts Normal file
View File

@@ -0,0 +1,34 @@
import { execQueryAsync, execQueryAsyncWithId } from "./db";
export 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 (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE address_name = ?, address_id = LAST_INSERT_ID(address_id)`;
const values = [name, localpart, domain, email, name];
return await execQueryAsyncWithId(query, values);
}
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];
return await execQueryAsyncWithId(query, values);
}
export async function findRoomByOwner(ownerId) {
const query = `SELECT room_id FROM app_room WHERE owner_id = ?`;
const values = [ownerId];
return await execQueryAsync(query, values);
}
export async function getUserIdOfMailbox(boxId) {
const query = `
SELECT app_account.user_id
FROM mailbox
INNER JOIN app_account ON app_account.account_id = mailbox.account_id
WHERE mailbox.mailbox_id = ?
`;
const values = [boxId];
return await execQueryAsync(query, values);
}