chanfana
chanfana copied to clipboard
Base Auto Endpoints: add context to custom serializer
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.
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),
};