refactor(api): extract holiday calendar support
This commit is contained in:
@@ -3,6 +3,10 @@ import { z } from "zod";
|
||||
import { findUniqueOrThrow } from "../db/helpers.js";
|
||||
import { adminProcedure } from "../trpc.js";
|
||||
import { asHolidayCalendarDb, type HolidayReadContext } from "./holiday-calendar-shared.js";
|
||||
import {
|
||||
holidayCalendarDetailInclude,
|
||||
holidayCalendarListInclude,
|
||||
} from "./holiday-calendar-support.js";
|
||||
|
||||
const HolidayCalendarCatalogInputSchema = z.object({
|
||||
includeInactive: z.boolean().optional(),
|
||||
@@ -100,12 +104,7 @@ async function readCalendarsSnapshot(
|
||||
|
||||
return db.holidayCalendar.findMany({
|
||||
where,
|
||||
include: {
|
||||
country: { select: { id: true, code: true, name: true } },
|
||||
metroCity: { select: { id: true, name: true } },
|
||||
_count: { select: { entries: true } },
|
||||
entries: { orderBy: [{ date: "asc" }, { name: "asc" }] },
|
||||
},
|
||||
include: holidayCalendarListInclude,
|
||||
orderBy: [
|
||||
{ country: { name: "asc" } },
|
||||
{ scopeType: "asc" },
|
||||
@@ -121,32 +120,20 @@ async function readCalendarByIdentifierSnapshot(ctx: HolidayReadContext, identif
|
||||
|
||||
let calendar = await db.holidayCalendar.findUnique({
|
||||
where: { id: trimmedIdentifier },
|
||||
include: {
|
||||
country: { select: { id: true, code: true, name: true } },
|
||||
metroCity: { select: { id: true, name: true } },
|
||||
entries: { orderBy: [{ date: "asc" }, { name: "asc" }] },
|
||||
},
|
||||
include: holidayCalendarDetailInclude,
|
||||
});
|
||||
|
||||
if (!calendar) {
|
||||
calendar = await db.holidayCalendar.findFirst({
|
||||
where: { name: { equals: trimmedIdentifier, mode: "insensitive" } },
|
||||
include: {
|
||||
country: { select: { id: true, code: true, name: true } },
|
||||
metroCity: { select: { id: true, name: true } },
|
||||
entries: { orderBy: [{ date: "asc" }, { name: "asc" }] },
|
||||
},
|
||||
include: holidayCalendarDetailInclude,
|
||||
});
|
||||
}
|
||||
|
||||
if (!calendar) {
|
||||
calendar = await db.holidayCalendar.findFirst({
|
||||
where: { name: { contains: trimmedIdentifier, mode: "insensitive" } },
|
||||
include: {
|
||||
country: { select: { id: true, code: true, name: true } },
|
||||
metroCity: { select: { id: true, name: true } },
|
||||
entries: { orderBy: [{ date: "asc" }, { name: "asc" }] },
|
||||
},
|
||||
include: holidayCalendarDetailInclude,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -191,11 +178,7 @@ export const holidayCalendarCatalogReadProcedures = {
|
||||
return findUniqueOrThrow(
|
||||
db.holidayCalendar.findUnique({
|
||||
where: { id: input.id },
|
||||
include: {
|
||||
country: { select: { id: true, code: true, name: true } },
|
||||
metroCity: { select: { id: true, name: true } },
|
||||
entries: { orderBy: [{ date: "asc" }, { name: "asc" }] },
|
||||
},
|
||||
include: holidayCalendarDetailInclude,
|
||||
}),
|
||||
"Holiday calendar",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user