Website/db/app/item-props/queries/getItemProps.ts
Mangiang 4b26395870
Some checks failed
continuous-integration/drone/push Build is failing
chore: work in progress
2022-05-06 21:05:02 -04:00

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,
}
}
)