chanfana icon indicating copy to clipboard operation
chanfana copied to clipboard

Base Auto Endpoints: add context to custom serializer

Open marceloverdijk opened this issue 11 months ago • 1 comments

The serializer options currently just passes in the object to transform/serialize.

export type Model = {
  tableName: string;
  schema: AnyZodObject;
  primaryKeys: Array<string>;
  serializer?: (obj: object) => object;
  serializerSchema?: AnyZodObject;
};

but I would like to access the context (mainly request params) here to decide how to transform it.

Rationale is an expand query param that would allow me to expand some objects in the response.

marceloverdijk avatar Apr 10 '25 20:04 marceloverdijk

I think passing the filters object would already help a lot:

    let filters = await this.getFilters();

    ...

    return {
      success: true,
      result: this.meta.model.serializer(obj, filters),
    };

marceloverdijk avatar Apr 11 '25 07:04 marceloverdijk