delete room when empty

This commit is contained in:
grimhilt
2023-05-06 15:58:33 +02:00
parent 1a7828b281
commit 843659b495
6 changed files with 62 additions and 28 deletions

View File

@@ -12,8 +12,10 @@ export async function getRoomOwner(roomId: number) {
return await execQueryAsync(query, values);
}
/**
* get all the data needed to reply to a message in a room
*/
export async function getLastMsgData(roomId: number) {
const query = `
SELECT
msg.message_id AS id,
@@ -59,3 +61,21 @@ export async function getLastMsgData(roomId: number) {
const values = [roomId];
return await execQueryAsync(query, values);
}
export async function getRoomOnMessageId(messageId: number) {
const query = `SELECT room_id FROM app_room_message WHERE message_id = ?`;
const values = [messageId];
return await execQueryAsync(query, values);
}
export async function getRoomNbMessage(roomId: number) {
const query = `SELECT COUNT(room_id) AS nbMessage FROM app_room_message WHERE room_id = ?`;
const values = [roomId];
return await execQueryAsync(query, values);
}
export async function deleteRoom(roomId: number) {
const query = `DELETE FROM app_room WHERE room_id = ?`;
const values = [roomId];
return await execQueryAsync(query, values);
}