listPublicRooms

This commit is contained in:
jusax23 2023-03-18 14:45:31 +01:00
parent 73c09458d1
commit 4128155189
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41

View file

@ -1,4 +1,4 @@
import { and, eq, insert, remove, select, update } from "dblang";
import { and, eq, ge, insert, remove, select, update } from "dblang";
import { PERMISSIONS } from "../../server/permissions.js";
import { sha256, sign } from "../../sys/crypto.js";
import { accounts, db, roomMembers, rooms } from "../../sys/db.js";
@ -151,4 +151,34 @@ export const deleteRoom = {
aws("error", "existence");
}
}
};
export const listPublicRooms = {
state: STATE.client,
right: PERMISSIONS.CAN_USE_API,
data: {},
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
let req = await select([
rooms.name,
rooms.public,
rooms.title,
rooms.description,
rooms.icon
], rooms)
.where(ge(rooms.public, 0))
.query(db);
let out = req.map(d => {
let name = d[rooms.name];
let isPublic = d[rooms.public];
let title = d[rooms.title];
let description = d[rooms.description];
let icon = d[rooms.icon];
if (name != null && isPublic != null && title != null && description != null && icon != null) {
return { name, public: isPublic, title, description, icon };
}
return null;
});
aws("ok", out.filter(d => d != null));
}
};