tests in typescript

This commit is contained in:
grimhilt
2023-04-01 22:36:51 +02:00
parent 9fbf5e5cf3
commit a5d325818b
22 changed files with 1258 additions and 412 deletions

View File

@@ -1,6 +1,7 @@
import { execQueryAsync, execQueryAsyncWithId } from "./db";
export async function getAddresseId(email, name) {
export async function getAddresseId(email: string, name?: string): Promise<number> {
console.log("get address id")
const localpart = email.split("@")[0];
const domain = email.split("@")[1];
const query = `INSERT INTO address
@@ -10,19 +11,19 @@ export async function getAddresseId(email, name) {
return await execQueryAsyncWithId(query, values);
}
export async function getFieldId(field) {
export async function getFieldId(field: string): Promise<number> {
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) {
export async function findRoomByOwner(ownerId: number): Promise<{ room_id: number }[]> {
const query = `SELECT room_id FROM app_room WHERE owner_id = ?`;
const values = [ownerId];
return await execQueryAsync(query, values);
}
export async function getUserIdOfMailbox(boxId) {
export async function getUserIdOfMailbox(boxId: number): Promise<{ user_id: number }[]> {
const query = `
SELECT app_account.user_id
FROM mailbox