tests in typescript
This commit is contained in:
@@ -2,7 +2,7 @@ import { transformEmojis } from "../utils/string";
|
||||
import { db, execQueryAsync, execQueryAsyncWithId, execQuery } from "./db";
|
||||
import { queryFromId, queryToId, queryCcId } from "./utils/addressQueries";
|
||||
|
||||
export async function getAllMembers(messageId) {
|
||||
export async function getAllMembers(messageId: number) {
|
||||
const query = `
|
||||
SELECT GROUP_CONCAT(address.address_id) AS is
|
||||
FROM address
|
||||
@@ -15,13 +15,18 @@ export async function getAllMembers(messageId) {
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
export async function registerMember(roomId, memberId) {
|
||||
export async function registerMember(roomId: number, memberId: number) {
|
||||
const query = `INSERT IGNORE INTO app_room_member (room_id, member_id) VALUES (?, ?)`;
|
||||
const values = [roomId, memberId];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
export async function createRoom(roomName, ownerId, messageId, roomType) {
|
||||
export async function createRoom(
|
||||
roomName: string | null | undefined,
|
||||
ownerId: number,
|
||||
messageId: number,
|
||||
roomType: number,
|
||||
) {
|
||||
if (!roomName) roomName = "No room name";
|
||||
roomName = transformEmojis(roomName);
|
||||
const query = `INSERT IGNORE INTO app_room (room_name, owner_id, message_id, room_type) VALUES (?, ?, ?, ?)`;
|
||||
@@ -29,7 +34,14 @@ export async function createRoom(roomName, ownerId, messageId, roomType) {
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
export async function registerMessageInRoom(messageId, roomId, isSeen, idate) {
|
||||
// todo date not good
|
||||
export async function registerMessageInRoom(
|
||||
messageId: number,
|
||||
roomId: number,
|
||||
isSeen: boolean,
|
||||
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);
|
||||
@@ -40,17 +52,17 @@ export async function registerMessageInRoom(messageId, roomId, isSeen, idate) {
|
||||
// }
|
||||
}
|
||||
|
||||
export function updateLastUpdateRoom(roomId, idate) {
|
||||
export function updateLastUpdateRoom(roomId: number, idate: string) {
|
||||
const query = `UPDATE app_room SET lastUpdate = ? WHERE room_id = ?`;
|
||||
const values = [idate, roomId];
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
export function incrementNotSeenRoom(roomId) {
|
||||
export function incrementNotSeenRoom(roomId: number) {
|
||||
// todo
|
||||
}
|
||||
|
||||
export async function getRoomInfo(messageID) {
|
||||
export async function getRoomInfo(messageID: string): Promise<{ room_id: number; root_id: number }[]> {
|
||||
const query = `
|
||||
SELECT
|
||||
app_room.room_id
|
||||
@@ -65,13 +77,13 @@ export async function getRoomInfo(messageID) {
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
export async function registerThread(roomId, parentId, rootId) {
|
||||
export async function registerThread(roomId: number, parentId: number, rootId: number) {
|
||||
const query = `INSERT IGNORE INTO app_thread (room_id, parent_id, root_id) VALUES (?, ?, ?)`;
|
||||
const values = [roomId, parentId, rootId];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
export async function isRoomGroup(roomId) {
|
||||
export async function isRoomGroup(roomId: number): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `SELECT isGroup FROM app_room WHERE room_id = '${roomId}'`;
|
||||
db.query(query, (err, results, fields) => {
|
||||
@@ -81,13 +93,14 @@ export async function isRoomGroup(roomId) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function findRoomsFromMessage(messageId) {
|
||||
export async function findRoomsFromMessage(messageID: string) {
|
||||
// todo find message in room not started
|
||||
const query = `SELECT room_id FROM app_room_message WHERE message_id = ? ORDER BY room_id`;
|
||||
const values = [messageId];
|
||||
const values = [messageID];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
export async function hasSameMembersAsParent(messageId, messageID) {
|
||||
export async function hasSameMembersAsParent(messageId: number, messageID: string) {
|
||||
const query1 = `
|
||||
SELECT
|
||||
GROUP_CONCAT(fromT.address_id) AS fromA,
|
||||
@@ -129,4 +142,4 @@ export async function hasSameMembersAsParent(messageId, messageID) {
|
||||
addressesMsg1.length == addressesMsg2.length &&
|
||||
addressesMsg1.reduce((a, b) => a && addressesMsg2.includes(b), true)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user