new renderer for newsfeed

This commit is contained in:
Ren Amamiya
2023-04-26 14:53:04 +07:00
parent 9d635d472e
commit 7a2e08f601
9 changed files with 266 additions and 212 deletions

View File

@@ -78,9 +78,16 @@ export async function countTotalNotes() {
// get all notes
export async function getNotes(time: number, limit: number, offset: number) {
const db = await connect();
return await db.select(
`SELECT * FROM notes WHERE created_at <= "${time}" ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}";`
const notes: any = { data: null, nextCursor: 0 };
const query: any = await db.select(
`SELECT * FROM notes WHERE created_at <= "${time}" GROUP BY parent_id ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}";`
);
notes['data'] = query;
notes['nextCursor'] = offset + limit;
return notes;
}
// get note by id
@@ -93,7 +100,9 @@ export async function getNoteByID(event_id: string) {
// get all latest notes
export async function getLatestNotes(time: number) {
const db = await connect();
return await db.select(`SELECT * FROM notes WHERE created_at > "${time}" ORDER BY created_at DESC;`);
return await db.select(
`SELECT * FROM notes WHERE created_at > "${time}" GROUP BY parent_id ORDER BY created_at DESC;`
);
}
// create note