diff --git a/server/plugins/messageStorage/sqlite.ts b/server/plugins/messageStorage/sqlite.ts index f2a3b526..50eae3c1 100644 --- a/server/plugins/messageStorage/sqlite.ts +++ b/server/plugins/messageStorage/sqlite.ts @@ -224,7 +224,7 @@ class SqliteMessageStorage implements ISqliteMessageStorage { let select = 'SELECT msg, type, time, network, channel FROM messages WHERE type = "message" AND json_extract(msg, "$.text") LIKE ? ESCAPE \'@\''; - const params = [`%${escapedSearchTerm}%`]; + const params: any[] = [`%${escapedSearchTerm}%`]; if (query.networkUuid) { select += " AND network = ? "; @@ -239,9 +239,8 @@ class SqliteMessageStorage implements ISqliteMessageStorage { const maxResults = 100; select += " ORDER BY time DESC LIMIT ? OFFSET ? "; - params.push(maxResults.toString()); - query.offset = parseInt(query.offset as string, 10) || 0; - params.push(String(query.offset)); + params.push(maxResults); + params.push(query.offset); return new Promise((resolve, reject) => { this.database.all(select, params, (err, rows) => { @@ -252,8 +251,8 @@ class SqliteMessageStorage implements ISqliteMessageStorage { searchTerm: query.searchTerm, target: query.channelName, networkUuid: query.networkUuid, - offset: query.offset as number, - results: parseSearchRowsToMessages(query.offset as number, rows).reverse(), + offset: query.offset, + results: parseSearchRowsToMessages(query.offset, rows).reverse(), }; resolve(response); } diff --git a/server/plugins/messageStorage/types.d.ts b/server/plugins/messageStorage/types.d.ts index 6dfa20db..9e81929e 100644 --- a/server/plugins/messageStorage/types.d.ts +++ b/server/plugins/messageStorage/types.d.ts @@ -26,7 +26,7 @@ export type SearchQuery = { searchTerm: string; networkUuid: string; channelName: string; - offset: number | string; + offset: number; }; export type SearchResponse = diff --git a/test/plugins/sqlite.ts b/test/plugins/sqlite.ts index 00211339..bd27141f 100644 --- a/test/plugins/sqlite.ts +++ b/test/plugins/sqlite.ts @@ -167,7 +167,9 @@ describe("SQLite Message Storage", function () { .search({ searchTerm: "msg", networkUuid: "retrieval-order-test-network", - } as any) + channelName: "", + offset: 0, + }) .then((messages) => { // @ts-expect-error Property 'results' does not exist on type '[]'. expect(messages.results).to.have.lengthOf(100); @@ -192,7 +194,9 @@ describe("SQLite Message Storage", function () { .search({ searchTerm: query, networkUuid: "this-is-a-network-guid2", - } as any) + channelName: "", + offset: 0, + }) .then((messages) => { // @ts-expect-error Property 'results' does not exist on type '[]'. expect(messages.results.map((i) => i.text)).to.deep.equal(expected);