Skip to content

Commit

Permalink
feat: pass request to fetchAll helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
nicgirault committed Jun 19, 2024
1 parent 1a8df35 commit 330dafe
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/additionalAttributeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const populateReference = <R extends RaRecord, T extends RaRecord>({fetch
}

export const populateReferenceMany = <R extends RaRecord, T extends RaRecord>({fetchAll,source= 'id', target }: {
fetchAll: (rows: R[]) => Promise<T[]>,
fetchAll: (rows: R[], req: Request) => Promise<T[]>,
source?: keyof R
target: keyof T
}) => {
Expand All @@ -38,7 +38,7 @@ export const populateReferenceMany = <R extends RaRecord, T extends RaRecord>({f
let referencesByTarget = cache.get(req)

if (!referencesByTarget) {
const references = await fetchAll(rows)
const references = await fetchAll(rows, req)

referencesByTarget = references.reduce((referencesByTarget, reference) => {
if (!referencesByTarget[reference[target] as unknown as string]) {
Expand All @@ -56,7 +56,7 @@ export const populateReferenceMany = <R extends RaRecord, T extends RaRecord>({f


export const populateReferenceManyCount = <R extends RaRecord, T extends RaRecord>({fetchAll,source= 'id', target }: {
fetchAll: (rows: R[]) => Promise<T[]>,
fetchAll: (rows: R[], req: Request) => Promise<T[]>,
source?: keyof R
target: keyof T
}) => {
Expand All @@ -66,7 +66,7 @@ export const populateReferenceManyCount = <R extends RaRecord, T extends RaRecor
let referencesByTarget = cache.get(req)

if (!referencesByTarget) {
const references = await fetchAll(rows)
const references = await fetchAll(rows, req)

referencesByTarget = references.reduce((referencesByTarget, reference) => {
if (!referencesByTarget[reference[target] as unknown as string]) {
Expand All @@ -84,7 +84,7 @@ export const populateReferenceManyCount = <R extends RaRecord, T extends RaRecor
}

export const populateReferenceOne = <R extends RaRecord, T extends RaRecord>({fetchAll,source= 'id', target }: {
fetchAll: (rows: R[]) => Promise<T[]>,
fetchAll: (rows: R[], req: Request) => Promise<T[]>,
source?: keyof R
target: keyof T,
}) => {
Expand Down

0 comments on commit 330dafe

Please sign in to comment.