31 lines
765 B
TypeScript
31 lines
765 B
TypeScript
import { paginate, resolver } from "blitz"
|
|
import db, { Prisma } from "db"
|
|
|
|
interface GetItemPropsInput
|
|
extends Pick<Prisma.ItemPropFindManyArgs, "where" | "orderBy" | "skip" | "take"> {}
|
|
|
|
export default resolver.pipe(
|
|
resolver.authorize(),
|
|
async ({ where, orderBy, skip = 0, take = 100 }: GetItemPropsInput) => {
|
|
// TODO: in multi-tenant app, you must add validation to ensure correct tenant
|
|
const {
|
|
items: itemProps,
|
|
hasMore,
|
|
nextPage,
|
|
count,
|
|
} = await paginate({
|
|
skip,
|
|
take,
|
|
count: () => db.itemProp.count({ where }),
|
|
query: (paginateArgs) => db.itemProp.findMany({ ...paginateArgs, where, orderBy }),
|
|
})
|
|
|
|
return {
|
|
itemProps,
|
|
nextPage,
|
|
hasMore,
|
|
count,
|
|
}
|
|
}
|
|
)
|