File tree Expand file tree Collapse file tree 3 files changed +9
-5
lines changed
Expand file tree Collapse file tree 3 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ const getFilter = async (
8080}
8181
8282
83- const computeAdditionalAttributes =
83+ export const computeAdditionalAttributes =
8484 < R > ( additionalAttributes : GetListOptions < R > [ "additionalAttributes" ] , concurrency : number , req : Request ) => {
8585 const limit = pLimit ( concurrency )
8686
Original file line number Diff line number Diff line change 11import { RequestHandler , Request , Response } from 'express'
2- import { Get } from './getList'
2+ import { Get , GetListOptions , computeAdditionalAttributes } from './getList'
33
4- export const getOne = < R > ( doGetList : Get < R > ) : RequestHandler => async (
4+ export const getOne = < R > ( doGetList : Get < R > , options ?: Partial < GetListOptions < R > > ) : RequestHandler => async (
55 req ,
66 res ,
77 next
@@ -18,7 +18,11 @@ export const getOne = <R>(doGetList: Get<R>): RequestHandler => async (
1818 if ( rows . length === 0 ) {
1919 return res . status ( 404 ) . json ( { error : 'Record not found' } )
2020 }
21- res . json ( rows [ 0 ] )
21+ const populatedRows =
22+ options ?. additionalAttributes
23+ ? await computeAdditionalAttributes ( options . additionalAttributes , options . additionalAttributesConcurrency ?? 1 , req ) ( rows )
24+ : rows
25+ res . json ( populatedRows [ 0 ] )
2226 } catch ( error ) {
2327 next ( error )
2428 }
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ export const crud = <I extends string | number, R>(
3333 options
3434 )
3535 )
36- router . get ( `${ path } /:id` , getOne ( actions . get ) )
36+ router . get ( `${ path } /:id` , getOne ( actions . get , options ) )
3737 }
3838
3939 if ( actions . create ) {
You can’t perform that action at this time.
0 commit comments