Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interview dao documentation #873

Merged
merged 14 commits into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions backend/src/dao/InterviewSlotDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { DBInterviewSlot } from '../types/DataTypes';
import { getMemberFromDocumentReference } from '../utils/memberUtil';
import BaseDao from './BaseDao';

/**
* Serializes an InterviewSlot instance into a format suitable for Firestore storage.
* @param {InterviewSlot} instance - The InterviewSlot instance to serialize.
* @returns {Promise<DBInterviewSlot>} - The serialized InterviewSlot object.
*/
async function serializeInterviewSlot(instance: InterviewSlot): Promise<DBInterviewSlot> {
return {
...instance,
Expand All @@ -12,6 +17,11 @@ async function serializeInterviewSlot(instance: InterviewSlot): Promise<DBInterv
};
}

/**
* Converts a Firestore document into an InterviewSlot instance by retrieving references.
* @param {DBInterviewSlot} dbInstance - The Firestore document to materialize.
* @returns {Promise<InterviewSlot>} - The materialized InterviewSlot object.
*/
async function materializeInterviewSlot(dbInstance: DBInterviewSlot): Promise<InterviewSlot> {
return {
...dbInstance,
Expand All @@ -22,21 +32,39 @@ async function materializeInterviewSlot(dbInstance: DBInterviewSlot): Promise<In
};
}

/**
* DAO class for managing InterviewSlot objects in Firestore.
*/
export default class InterviewSlotDao extends BaseDao<InterviewSlot, DBInterviewSlot> {
constructor() {
super(interviewSlotCollection, materializeInterviewSlot, serializeInterviewSlot);
}

/**
* Retrieves all interview slots associated with a given scheduler UUID.
* @param {string} uuid - The UUID of the interview scheduler.
* @returns {Promise<InterviewSlot[]>} - A list of InterviewSlot objects.
*/
async getSlotsForScheduler(uuid: string): Promise<InterviewSlot[]> {
return this.getDocuments([
{ field: 'interviewSchedulerUuid', comparisonOperator: '==', value: uuid }
]);
}

/**
* Retrieves a specific interview slot by its UUID.
* @param {string} uuid - The UUID of the interview slot.
* @returns {Promise<InterviewSlot | null>} - The InterviewSlot object if found, otherwise null.
*/
async getSlot(uuid: string): Promise<InterviewSlot | null> {
return this.getDocument(uuid);
}

/**
* Adds multiple interview slots to the database.
* @param {InterviewSlot[]} slots - The list of InterviewSlot objects to add.
* @returns {Promise<InterviewSlot[]>} - The list of created InterviewSlot objects.
*/
async addSlots(slots: InterviewSlot[]): Promise<InterviewSlot[]> {
return Promise.all(
slots.map((slot) => {
Expand All @@ -49,6 +77,12 @@ export default class InterviewSlotDao extends BaseDao<InterviewSlot, DBInterview
);
}

/**
* Updates an interview slot, ensuring that only an admin can change the assigned applicant.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applicants and members can also edit interview slots (signing up). admin bypass is to prevent the checks seen later in the code.

* @param {InterviewSlot} updatedSlot - The updated InterviewSlot object.
* @param {boolean} adminBypass - Whether to bypass applicant change restriction.
* @returns {Promise<boolean>} - True if the update was successful, false otherwise.
*/
async updateSlot(updatedSlot: InterviewSlot, adminBypass: boolean): Promise<boolean> {
const wasUpdated: boolean = await db.runTransaction(async (t) => {
const query = this.collection.where('uuid', '==', updatedSlot.uuid);
Expand All @@ -75,6 +109,11 @@ export default class InterviewSlotDao extends BaseDao<InterviewSlot, DBInterview
return wasUpdated;
}

/**
* Deletes an interview slot from the database.
* @param {string} uuid - The UUID of the interview slot to delete.
* @returns {Promise<void>} - Resolves when the deletion is complete.
*/
async deleteSlot(uuid: string): Promise<void> {
return this.deleteDocument(uuid);
}
Expand Down
Loading