diff --git a/packages/app/app/api/flights/[id]/route.ts b/packages/app/app/api/flights/[id]/route.ts index d3e9b5bd..20ccafbd 100644 --- a/packages/app/app/api/flights/[id]/route.ts +++ b/packages/app/app/api/flights/[id]/route.ts @@ -29,7 +29,6 @@ export async function GET( } const flight = await db.query.flights.findFirst({ - columns: { cycle: false }, where: (flights, { eq }) => eq(flights.id, data.data.id), }) if (flight === null) { diff --git a/packages/app/app/api/flights/all/route.ts b/packages/app/app/api/flights/all/route.ts index f0a6cd45..c33965d5 100644 --- a/packages/app/app/api/flights/all/route.ts +++ b/packages/app/app/api/flights/all/route.ts @@ -24,6 +24,10 @@ const schema = z.object({ .preprocess((x) => (Array.isArray(x) ? x : [x]), z.array(z.string())) .transform((values) => values.map((value) => value.toUpperCase())) .optional(), + cycle: z + .preprocess((x) => (Array.isArray(x) ? x : [x]), z.array(z.string())) + .transform((values) => values.map((value) => new Date(value))) + .optional(), }) export async function GET(request: Request) { @@ -55,11 +59,10 @@ export async function GET(request: Request) { } const items = await db.query.flights.findMany({ - columns: { cycle: false }, orderBy: (fields, { desc }) => desc(fields.id), where: (fields, { sql, and, eq }) => and( - eq(fields.cycle, currentCycleSubquery), + data.data.cycle ? sql`${fields.cycle} IN ${data.data.cycle}` : eq(fields.cycle, currentCycleSubquery), data.data.departureIcao && sql`${fields.departureIcao} IN ${data.data.departureIcao}`, data.data.arrivalIcao && diff --git a/packages/app/app/api/flights/route.ts b/packages/app/app/api/flights/route.ts index 96c9756f..31d910ec 100644 --- a/packages/app/app/api/flights/route.ts +++ b/packages/app/app/api/flights/route.ts @@ -33,6 +33,10 @@ const schema = z.object({ (x) => (x ? Number(x) : undefined), z.number().min(0).default(0) ), + cycle: z + .preprocess((x) => (Array.isArray(x) ? x : [x]), z.array(z.string())) + .transform((values) => values.map((value) => new Date(value))) + .optional(), }) export async function GET(request: Request) { @@ -64,7 +68,7 @@ export async function GET(request: Request) { } const criteria = and( - eq(flights.cycle, currentCycleSubquery), + data.data.cycle ? sql`${flights.cycle} IN ${data.data.cycle}` : eq(flights.cycle, currentCycleSubquery), data.data.departureIcao && sql`${flights.departureIcao} IN ${data.data.departureIcao}`, data.data.arrivalIcao && diff --git a/packages/app/app/api/route.ts b/packages/app/app/api/route.ts index 044c4c96..2626f088 100644 --- a/packages/app/app/api/route.ts +++ b/packages/app/app/api/route.ts @@ -100,6 +100,18 @@ const openApi = { }, }, }, + { + in: 'query', + name: 'cycle', + style: 'form', + explode: true, + schema: { + type: 'array', + items: { + type: 'string', + }, + }, + }, ], responses: { '200': { @@ -178,6 +190,18 @@ const openApi = { }, }, }, + { + in: 'query', + name: 'cycle', + style: 'form', + explode: true, + schema: { + type: 'array', + items: { + type: 'string', + }, + }, + }, ], responses: { '200': { @@ -319,6 +343,10 @@ const openApi = { type: 'string', enum: ['IFR', 'Y', 'Z'], }, + cycle: { + type: 'string', + format: 'date-time', + }, createdAt: { type: 'string', format: 'date-time',