* init * -- * update dialog * reassignment * further changes * add unit test * fix * type fix?? * fix type?? * emails * workflows * reason recorder * refactor reassigned email * fix reassigned reason * fix type * improve dialog * add integration tests * - * remove unnecessary comments --1 * removed unnecessary comments * fix type? * address cubic * address feedback * -- * fix type? * address cubic * type-fix? * fix type * further fixes * fix location update * type fix * propagate error to top * fix mocking * fix reported bugs * fix * fix success page video URL * remove PII from logs * persist video URL * better audit trail * revert email function name change * fix test * fix flake * di * fixes * extract logic and other repo access from BookingRepository * fixes * (☞゚∀゚)☞ udit * integration test fixes * mroe fixes * extract to repo * extract to repo --2 * fix type * cubic * address feedback --1 * --2 * wip * addressed feedback * type fixes * type fixes * fix issues * feedback --1 * feedback --2 * BookingAccessService DI * fix * break down function into small functions * fixes --1 * fixes * typefix * addressing feedback * fix merge conflict lost change
68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
import logger from "@calcom/lib/logger";
|
|
import type { AssignmentReason, AssignmentReasonEnum } from "@calcom/prisma/client";
|
|
import type { PrismaClient } from "@calcom/prisma";
|
|
|
|
const log = logger.getSubLogger({ prefix: ["AssignmentReasonRepository"] });
|
|
|
|
export class AssignmentReasonRepository {
|
|
constructor(private prismaClient: PrismaClient) {}
|
|
|
|
/**
|
|
* Creates a new assignment reason record for a booking
|
|
* @param data - The assignment reason data
|
|
* @returns The created assignment reason
|
|
*/
|
|
async createAssignmentReason(data: {
|
|
bookingId: number;
|
|
reasonEnum: AssignmentReasonEnum;
|
|
reasonString: string;
|
|
}): Promise<AssignmentReason> {
|
|
log.debug("Creating assignment reason", { bookingId: data.bookingId, reasonEnum: data.reasonEnum });
|
|
|
|
return this.prismaClient.assignmentReason.create({
|
|
data: {
|
|
bookingId: data.bookingId,
|
|
reasonEnum: data.reasonEnum,
|
|
reasonString: data.reasonString,
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Finds all assignment reasons for a booking
|
|
* @param bookingId - The booking ID
|
|
* @returns Array of assignment reasons
|
|
*/
|
|
async findByBookingId(bookingId: number): Promise<Omit<AssignmentReason, "id">[]> {
|
|
return this.prismaClient.assignmentReason.findMany({
|
|
where: { bookingId },
|
|
orderBy: { createdAt: "desc" },
|
|
select: {
|
|
createdAt: true,
|
|
bookingId: true,
|
|
reasonEnum: true,
|
|
reasonString: true,
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Finds the latest assignment reason for a booking
|
|
* @param bookingId - The booking ID
|
|
* @returns The most recent assignment reason or null
|
|
*/
|
|
async findLatestByBookingId(bookingId: number): Promise<Omit<AssignmentReason, "id"> | null> {
|
|
return this.prismaClient.assignmentReason.findFirst({
|
|
where: { bookingId },
|
|
orderBy: { createdAt: "desc" },
|
|
select: {
|
|
createdAt: true,
|
|
bookingId: true,
|
|
reasonEnum: true,
|
|
reasonString: true,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|