-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move response wrapping func to utils
See: BEDS-481
- Loading branch information
1 parent
09b2451
commit f0174b1
Showing
2 changed files
with
24 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { ApiPagingResponse } from '~/types/api/common' | ||
/** | ||
* This function wraps each element in an `ApiPagingResponse` interface with a unique id field `wrapped_identifier`. | ||
* @param response The api response to wrap | ||
* @param getIdFromRow A function that takes a row and builds a unique identifier | ||
* @returns The wrapped response | ||
*/ | ||
export function wrapWithIdentifier<T>(response: ApiPagingResponse<T> | undefined, getIdFromRow: (row: T) => string) { | ||
if (!response) { | ||
return | ||
} | ||
return { | ||
data: response.data.map(row => ({ | ||
...row, | ||
wrapped_identifier: getIdFromRow(row), | ||
})), | ||
paging: response.paging, | ||
} | ||
} |