Skip to content

Instantly share code, notes, and snippets.

@femyeda
Created January 22, 2023 21:23
Show Gist options
  • Save femyeda/6c0a30afc237110ccd98144e92f02a47 to your computer and use it in GitHub Desktop.
Save femyeda/6c0a30afc237110ccd98144e92f02a47 to your computer and use it in GitHub Desktop.
Autogenerated Prisma API
const getHandler = async (
req: AuthenticatedApiRequest,
res: NextApiResponse
) => {
const query = qp(req.query.query)
? JSON.parse(qp(req.query.query))
: undefined;
const selectInput = coalesceUndefined(query?.select);
const whereInput = coalesceUndefined(query?.where);
const includeInput = coalesceUndefined(query?.include);
const orderByInput = coalesceUndefined(query?.orderBy);
const cursorInput = coalesceUndefined(query?.cursor);
const takeInput = coalesceUndefined(query?.take);
const skipInput = coalesceUndefined(query?.skip);
const distinctInput = coalesceUndefined(query?.distinct);
const findManyArgs = {
select: selectInput,
where: whereInput,
include: includeInput,
orderBy: orderByInput,
cursor: cursorInput,
take: takeInput,
skip: skipInput,
distinct: distinctInput,
};
try {
const likes = await _getManyLike(findManyArgs);
return res.status(200).json({ data: filterSensitiveData(likes) });
} catch (error) {
console.error("[api] Likes/getMany", error);
return res.status(500).json({ statusCode: 500, message: error.message });
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment