Corrected a problem with too many participants
This commit is contained in:
@@ -57,7 +57,7 @@ export async function getSpecificUsers(ids: string[]) {
|
|||||||
export async function getLinkedUsers(userID?: string, userType?: Type, type?: Type, firstID?: string, lastID?: string, size?: number) {
|
export async function getLinkedUsers(userID?: string, userType?: Type, type?: Type, firstID?: string, lastID?: string, size?: number) {
|
||||||
const q = [
|
const q = [
|
||||||
...(!!type ? [where("type", "==", type)] : []),
|
...(!!type ? [where("type", "==", type)] : []),
|
||||||
orderBy(documentId()),
|
orderBy("registrationDate"),
|
||||||
...(!!firstID && !lastID ? [endBefore(firstID)] : []),
|
...(!!firstID && !lastID ? [endBefore(firstID)] : []),
|
||||||
...(!!lastID && !firstID ? [startAfter(lastID)] : []),
|
...(!!lastID && !firstID ? [startAfter(lastID)] : []),
|
||||||
...(!!size ? [limit(size)] : []),
|
...(!!size ? [limit(size)] : []),
|
||||||
@@ -89,6 +89,7 @@ export async function getLinkedUsers(userID?: string, userType?: Type, type?: Ty
|
|||||||
// ⨯ [FirebaseError: Invalid Query. A non-empty array is required for 'in' filters.] {
|
// ⨯ [FirebaseError: Invalid Query. A non-empty array is required for 'in' filters.] {
|
||||||
if (participants.length === 0) return {users: [], total: 0};
|
if (participants.length === 0) return {users: [], total: 0};
|
||||||
|
|
||||||
|
if (participants.length < 30) {
|
||||||
const snapshot = await getDocs(query(collection(db, "users"), ...[where(documentId(), "in", participants), ...q]));
|
const snapshot = await getDocs(query(collection(db, "users"), ...[where(documentId(), "in", participants), ...q]));
|
||||||
const users = snapshot.docs.map((doc) => ({
|
const users = snapshot.docs.map((doc) => ({
|
||||||
id: doc.id,
|
id: doc.id,
|
||||||
@@ -103,6 +104,20 @@ export async function getLinkedUsers(userID?: string, userType?: Type, type?: Ty
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const snapshot = await getDocs(query(collection(db, "users"), ...q));
|
||||||
|
const users = snapshot.docs.map((doc) => ({
|
||||||
|
id: doc.id,
|
||||||
|
...doc.data(),
|
||||||
|
})) as User[];
|
||||||
|
|
||||||
|
const participantUsers = users.filter((x) => participants.includes(x.id));
|
||||||
|
|
||||||
|
return {
|
||||||
|
users: participantUsers,
|
||||||
|
total: participantUsers.length,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function getUserBalance(user: User) {
|
export async function getUserBalance(user: User) {
|
||||||
const codes = await getUserCodes(user.id);
|
const codes = await getUserCodes(user.id);
|
||||||
if (user.type !== "corporate" && user.type !== "mastercorporate") return codes.length;
|
if (user.type !== "corporate" && user.type !== "mastercorporate") return codes.length;
|
||||||
|
|||||||
Reference in New Issue
Block a user