Added payment done and pending visible to Admin and Developers without filters

This commit is contained in:
Joao Ramos
2024-01-12 19:55:46 +00:00
parent ad1dbaef27
commit 72b9e1f11d
2 changed files with 53 additions and 11 deletions

View File

@@ -30,16 +30,20 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
return;
}
const codeQuery = query(
collection(db, "payments"),
// where("agent", "==", "xRMirufz6PPQqxKBgvPTWiWKBD63"),
where(req.session.user.type, "==", req.session.user.id)
// Based on the logic of query we should be able to do this:
// where("isPaid", "==", paid === "paid"),
// but for some reason it is ignoring all but the first clause
// I opted into only fetching relevant content for the user
// and then filter it with JS
);
// if it's an admin, don't apply query filters
const whereClauses = ["admin", "developer"].includes(req.session.user.type)
? []
: [
// where("agent", "==", "xRMirufz6PPQqxKBgvPTWiWKBD63"),
where(req.session.user.type, "==", req.session.user.id),
// Based on the logic of query we should be able to do this:
// where("isPaid", "==", paid === "paid"),
// but for some reason it is ignoring all but the first clause
// I opted into only fetching relevant content for the user
// and then filter it with JS
];
const codeQuery = query(collection(db, "payments"), ...whereClauses);
const snapshot = await getDocs(codeQuery);
if (snapshot.empty) {