Prisma Where Statement with locked presets

Hey,
i am look for a solution for the following Problem:
I have a table that contains courses, i want to create a select function that i give default values to restrict sertain Queries to only see these courses.
function providing the preset:
export function select_queable_courses() {
    return Prisma.validator<Prisma.coursesWhereInput>()({
        deleted_at: null,
        team_id: { not: null },
        locked_for_queuing: false,
    });
}

goal:
export function select_queable_courses<
    T extends Omit<Prisma.coursesWhereInput, "AND" | "OR" | "NOT" | "deleted_at" | "team_id" | "locked_for_queuing">
>(where: T) {
    return Prisma.validator<Prisma.coursesWhereInput>()({
        deleted_at: null,
        team_id: { not: null },
        locked_for_queuing: false,
        ...where,
    });
}

usage:
await prisma_client.courses.findMany({
  where: select_queable_courses({
    location_id: 4,
    // cant do this below
    deleted_at: new Date()
  })
});

the goal is currently giving we a TS error (picture) on the calling of the validator function.

(possible) SOLUTION:
since this is just a where statement the narrowing of the type isnt as neccessary as with select statements, since Prisma doesn't infer types from where statements (eg.: where: {deleted_at: null } still returns type deleted_at: null | Date ) i could just remove the Prisma.validator() part of is.
Is there a known better way of doing that?
Bildschirmfoto_2023-10-30_um_10.58.20.png
Was this page helpful?