SearchQuery: offset is always a number

Fix type confusion that specified offset to be a string, it is
always a number.
This commit is contained in:
Reto Brunner 2022-11-12 22:50:56 +01:00
parent dca202427a
commit 8095d9e88a
3 changed files with 12 additions and 9 deletions

View File

@ -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);
}

View File

@ -26,7 +26,7 @@ export type SearchQuery = {
searchTerm: string;
networkUuid: string;
channelName: string;
offset: number | string;
offset: number;
};
export type SearchResponse =

View File

@ -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);