generated from argahsuknesib/TS-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds : method to fetch events betwen timestamps. fixes #4
- Loading branch information
1 parent
9c726af
commit 16f50e7
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Readable } from "stream" | ||
import { CacheService } from "../service/CacheService"; | ||
const cache_service = new CacheService(); | ||
export async function getMembers(opts?: { | ||
from?: Date, | ||
until?: Date, | ||
}): Promise<Readable> { | ||
opts = opts ?? {}; | ||
const from = opts.from ?? new Date(0); | ||
const until = opts.until ?? new Date(); | ||
const from_epoch = from.getTime(); | ||
const until_epoch = until.getTime(); | ||
const member_stream = new Readable({ | ||
objectMode: true, | ||
read() { | ||
|
||
} | ||
}); | ||
const database = await cache_service.read_whole_database(); | ||
for (const key in database) { | ||
const value = database[key]; | ||
const timestamp = parseInt(key); | ||
if (timestamp >= from_epoch && timestamp <= until_epoch) { | ||
member_stream.push(value); | ||
} | ||
} | ||
return member_stream; | ||
} |