implement database as a class for tests
This commit is contained in:
@@ -35,21 +35,13 @@ export async function createRoom(
|
||||
}
|
||||
|
||||
// todo date not good
|
||||
export async function registerMessageInRoom(
|
||||
messageId: number,
|
||||
roomId: number,
|
||||
isSeen: boolean,
|
||||
idate: string | undefined | null,
|
||||
) {
|
||||
export async function registerMessageInRoom(messageId: number, roomId: number, idate: string | undefined | null) {
|
||||
if (!idate) idate = new Date().toString();
|
||||
const query = `INSERT IGNORE INTO app_room_message (message_id, room_id) VALUES (?, ?)`;
|
||||
const values = [messageId, roomId];
|
||||
await execQueryAsync(query, values);
|
||||
|
||||
updateLastUpdateRoom(roomId, idate);
|
||||
// if (!isSeen) {
|
||||
// incrementNotSeenRoom(roomId);
|
||||
// }
|
||||
}
|
||||
|
||||
export function updateLastUpdateRoom(roomId: number, idate: string) {
|
||||
@@ -58,11 +50,13 @@ export function updateLastUpdateRoom(roomId: number, idate: string) {
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
export function incrementNotSeenRoom(roomId: number) {
|
||||
// todo
|
||||
export async function incrementNotSeenRoom(roomId: number) {
|
||||
const query = `UPDATE app_room SET unseen = unseen + 1 WHERE room_id = ?`;
|
||||
const values = [roomId];
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
export async function getRoomInfo(messageID: string): Promise<{ room_id: number; root_id: number }[]> {
|
||||
export async function getThreadInfo(messageID: string): Promise<{ room_id: number; root_id: number }[]> {
|
||||
const query = `
|
||||
SELECT
|
||||
app_room.room_id
|
||||
@@ -92,9 +86,13 @@ export async function isRoomGroup(roomId: number): Promise<boolean> {
|
||||
});
|
||||
}
|
||||
|
||||
export async function findRoomsFromMessage(messageID: string) {
|
||||
export async function findRoomsFromMessage(messageID: string): Promise<{ room_id: number }[]> {
|
||||
// todo find message in room not started
|
||||
const query = `SELECT room_id FROM app_room_message WHERE message_id = ? ORDER BY room_id`;
|
||||
const query = `
|
||||
SELECT room_id FROM app_room_message
|
||||
INNER JOIN message ON message.message_id = app_room_message.message_id
|
||||
WHERE message.messageID = ? ORDER BY room_id
|
||||
`;
|
||||
const values = [messageID];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user