I have this function:
export const getProducts = makeRequest(
/** Your query */
`asasd*[_type == "product"] {
_id,
title
}`,
/** Optionally transform the response */
(i) => i,
/** Validate exact type */
D.array(Product)
);
which is of type:
const getProducts: TaskEither<Error, {
_id: string;
title: string;
}[]>
This is used in a Next.js API route like this:
export default async (
_: NextApiRequest,
res: NextApiResponse<Array<Product>>
) => {
const request = await getProducts();
return pipe(
request,
E.fold((v) => res.status(400).end(v.message), res.status(200).json)
);
};
It work, but how can I simplify the last function?
I would like for await getProducts()
to be inline in the pipe, so I don't have to do the request
assignment up front.