Cleaned up some code
This commit is contained in:
@@ -1,30 +1,10 @@
|
|||||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
import { app } from "@/firebase";
|
|
||||||
import {
|
|
||||||
getFirestore,
|
|
||||||
collection,
|
|
||||||
getDocs,
|
|
||||||
query,
|
|
||||||
where,
|
|
||||||
setDoc,
|
|
||||||
doc,
|
|
||||||
getDoc,
|
|
||||||
} from "firebase/firestore";
|
|
||||||
import { withIronSessionApiRoute } from "iron-session/next";
|
import { withIronSessionApiRoute } from "iron-session/next";
|
||||||
import { sessionOptions } from "@/lib/session";
|
import { sessionOptions } from "@/lib/session";
|
||||||
import { uuidv4 } from "@firebase/util";
|
|
||||||
import { Module } from "@/interfaces";
|
|
||||||
import { getExams } from "@/utils/exams.be";
|
|
||||||
import { Exam, InstructorGender, Variant } from "@/interfaces/exam";
|
|
||||||
import { capitalize, flatten, uniqBy } from "lodash";
|
|
||||||
import { User } from "@/interfaces/user";
|
|
||||||
import moment from "moment";
|
|
||||||
import { sendEmail } from "@/email";
|
|
||||||
import { getAllAssignersByCorporate } from "@/utils/groups.be";
|
import { getAllAssignersByCorporate } from "@/utils/groups.be";
|
||||||
import { getAssignmentsByAssigners } from "@/utils/assignments.be";
|
import { getAssignmentsByAssigners } from "@/utils/assignments.be";
|
||||||
|
|
||||||
const db = getFirestore(app);
|
|
||||||
|
|
||||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ export const getAssignmentsByAssigner = async (id: string) => {
|
|||||||
return docs.map((x) => ({...x.data(), id: x.id})) as Assignment[];
|
return docs.map((x) => ({...x.data(), id: x.id})) as Assignment[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getAssignmentsByAssignerBetweenDates = async (id: string, startDate: Date, endDate: Date) => {
|
||||||
|
const {docs} = await getDocs(query(collection(db, "assignments"), where("assigner", "==", id), ));
|
||||||
|
return docs.map((x) => ({...x.data(), id: x.id})) as Assignment[];
|
||||||
|
};
|
||||||
|
|
||||||
export const getAssignmentsByAssigners = async (ids: string[]) => {
|
export const getAssignmentsByAssigners = async (ids: string[]) => {
|
||||||
return (await Promise.all(ids.map(getAssignmentsByAssigner))).flat();
|
return (await Promise.all(ids.map(getAssignmentsByAssigner))).flat();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user