2021-07-31 15:57:43 +00:00
|
|
|
import { paginate, resolver } from "blitz";
|
|
|
|
import db, { Prisma, Customer } from "db";
|
2021-07-31 14:33:18 +00:00
|
|
|
|
|
|
|
interface GetPhoneCallsInput
|
|
|
|
extends Pick<Prisma.PhoneCallFindManyArgs, "where" | "orderBy" | "skip" | "take"> {
|
2021-07-31 15:57:43 +00:00
|
|
|
customerId: Customer["id"];
|
2021-07-31 14:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default resolver.pipe(
|
|
|
|
resolver.authorize(),
|
|
|
|
async ({ where, orderBy, skip = 0, take = 100 }: GetPhoneCallsInput) => {
|
|
|
|
// TODO: in multi-tenant app, you must add validation to ensure correct tenant
|
|
|
|
const {
|
|
|
|
items: phoneCalls,
|
|
|
|
hasMore,
|
|
|
|
nextPage,
|
|
|
|
count,
|
|
|
|
} = await paginate({
|
|
|
|
skip,
|
|
|
|
take,
|
|
|
|
count: () => db.phoneCall.count({ where }),
|
|
|
|
query: (paginateArgs) => db.phoneCall.findMany({ ...paginateArgs, where, orderBy }),
|
2021-07-31 15:57:43 +00:00
|
|
|
});
|
2021-07-31 14:33:18 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
phoneCalls,
|
|
|
|
nextPage,
|
|
|
|
hasMore,
|
|
|
|
count,
|
2021-07-31 15:57:43 +00:00
|
|
|
};
|
2021-08-01 12:04:04 +00:00
|
|
|
},
|
2021-07-31 15:57:43 +00:00
|
|
|
);
|