Skip to content

Chaining middlewares and options type #1250

Pinned Answered by RobinTail
bobgubko asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @bobgubko ,

I can offer you THREE options for doing that.

Option 1: Making it aware

Create an EndpointsFactory equipped with the middleware that provides em.
Then, addMiddleware for creating another factory OR at the moment of creating an Endpoint (using build method).

const customFactory = defaultEndpointsFactory.addMiddleware(
  createMiddleware({
    input: z.object({}),
    middleware: async () => ({ em: { findOneOrFail: () => ({}) } }),
  }),
);

export const anotherFactory = customFactory.addMiddleware(
  createMiddleware({
    input: z.object({
      projectId: z.string().transform((value) => parseInt(value, 10)),
    }),
    middleware: async ({ options: { em } }) => {
      c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by RobinTail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
good first issue Good for newcomers question Further information is requested
2 participants