listPublicRooms
This commit is contained in:
parent
73c09458d1
commit
4128155189
1 changed files with 32 additions and 2 deletions
|
@ -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));
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue