fix sql queries to sync mail

This commit is contained in:
grimhilt 2023-04-05 16:10:10 +02:00
parent 8b4210914b
commit 51003b494b
4 changed files with 23 additions and 7 deletions

View File

@ -53,7 +53,7 @@ export function updateLastUpdateRoom(roomId: number, idate: string) {
}
export async function incrementNotSeenRoom(roomId: number) {
const query = `UPDATE app_room SET unseen = unseen + 1 WHERE room_id = ?`;
const query = `UPDATE app_room SET notSeen = notSeen + 1 WHERE room_id = ?`;
const values = [roomId];
execQuery(query, values);
}
@ -61,7 +61,7 @@ export async function incrementNotSeenRoom(roomId: number) {
export async function getThreadInfo(messageID: string): Promise<{ room_id: number; root_id: number }[]> {
const query = `
SELECT
app_room.room_id
app_room.room_id,
app_thread.root_id
FROM app_room
LEFT JOIN app_thread ON app_thread.room_id = app_room.room_id
@ -76,10 +76,11 @@ export async function getThreadInfo(messageID: string): Promise<{ room_id: numbe
export async function getThreadInfoOnId(threadId: number): Promise<{ room_id: number; root_id: number }[]> {
const query = `
SELECT
app_room.room_id
app_room.room_id,
app_thread.root_id
FROM app_room
WHERE room_id = ?
LEFT JOIN app_thread ON app_room.room_id = app_thread.room_id
WHERE app_room.room_id = ?
`;
const values = [threadId];
return await execQueryAsync(query, values);

View File

@ -23,7 +23,6 @@ export async function findRoomByOwner(ownerId: number): Promise<{ room_id: numbe
}
export async function getUserIdOfMailbox(boxId: number): Promise<{ user_id: number }[]> {
console.log("fuckdsvreghiu")
const query = `
SELECT app_account.user_id
FROM mailbox

View File

@ -2,6 +2,7 @@ import express from "express";
import cors from "cors";
const app = express();
import ImapSync from "./mails/imap/ImapSync";
import { execQueryAsync, execQuery } from "./db/db";
app.use(express.json());
app.use(
@ -17,3 +18,19 @@ app.use("/api/mail", mailRouter);
const imapSync = new ImapSync();
imapSync.init();
const shouldReset = false;
if (shouldReset) {
const query = "SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE table_schema = 'mail'";
execQueryAsync(query, []).then((results) => {
execQuery("SET FOREIGN_KEY_CHECKS=0", []);
results.map((table) => {
if (table.table_name == "app_account") return;
if (table.table_name == "address") return;
if (table.table_name == "mailbox") return;
console.log(table.table_name);
execQuery("DELETE FROM " + table.table_name, []);
// execQuery("DROP TABLE " + table.table_name);
});
});
}

View File

@ -21,7 +21,6 @@ interface AccountFromBack {
}
function createRoom(options: RoomFromBack): Room {
console.log(options.roomType);
return {
id: options.id,
roomName: decodeEmojis(options.roomName),