2023-03-09 13:44:46 +01:00
|
|
|
import { alias, eq, count, select, naturalJoin, innerJoinOn } from "dblang";
|
|
|
|
import { accounts, db, roomMembers, rooms } from "../sys/db.js";
|
|
|
|
|
|
|
|
export const isRoomFull = async (roomID: number) => {
|
|
|
|
let currentCount = alias(
|
|
|
|
select([count(roomMembers.roomMemberID)], roomMembers)
|
|
|
|
.where(eq(roomMembers.roomID, roomID)),
|
|
|
|
"currentCount"
|
|
|
|
) as any;
|
|
|
|
let maxCount = alias(
|
|
|
|
select([accounts.maxUsersPerRoom],
|
|
|
|
innerJoinOn(accounts, rooms, eq(accounts.accID, rooms.owner)))
|
|
|
|
.where(eq(rooms.roomID, roomID)),
|
|
|
|
"maxCount"
|
|
|
|
) as any;
|
|
|
|
let req = await select([currentCount, maxCount], null)
|
|
|
|
.query(db);
|
|
|
|
return req[0][currentCount] >= req[0][maxCount];
|
|
|
|
};
|