Skip to content
Discussion options

You must be logged in to vote

no that's not what i mean, i mean use object literal to map condition.
like this

type DirectionEnum  = 'asc' | 'desc';

const DirectionMap = {
   'asc': asc, // import direction query from drizzle
   'desc': desc, // import direction query from drizzle
} as const;

export const getDirection = (direction: DirectionEnum | null) => (direction ? DirectionMap[direction] : asc);

and in query just do this

   query.orderBy(getDirection(sort.sort)(athletes[sort.colId]))

Also i suggest to use something like zod to validate request input like sort.colId and sort.sort

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@berlin2
Comment options

@Senbonzakura1234
Comment options

Answer selected by berlin2
@berlin2
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants