export const getFullSlots = async (options: GetFullSlotsOptions) => {
const {
...
page = 1,
perPage = 20,
} = options;
return await db.query.slots.findMany({
with: {
campaign: true,
site: true,
study: true,
},
where: (slots, { and, gte, lte }) => (
/* some filters */
),
orderBy: (slots, { asc, sql }) => [
sql`CASE WHEN ${slots.startTime} > CURRENT_TIMESTAMP THEN 0 ELSE 1 END`,
asc(slots.startTime),
],
limit: perPage,
offset: Math.max(0, page - 1) * perPage,
});
};
export const getFullSlots = async (options: GetFullSlotsOptions) => {
const {
...
page = 1,
perPage = 20,
} = options;
return await db.query.slots.findMany({
with: {
campaign: true,
site: true,
study: true,
},
where: (slots, { and, gte, lte }) => (
/* some filters */
),
orderBy: (slots, { asc, sql }) => [
sql`CASE WHEN ${slots.startTime} > CURRENT_TIMESTAMP THEN 0 ELSE 1 END`,
asc(slots.startTime),
],
limit: perPage,
offset: Math.max(0, page - 1) * perPage,
});
};