Add custom db read support

This commit is contained in:
pikiou
2021-12-11 04:34:36 +01:00
parent 7fb466d91c
commit 0391fdccd9
17 changed files with 249 additions and 86 deletions

View File

@@ -147,5 +147,26 @@ export default function getServiceAccessors<
}
}
return { listGet, get, set, add }
function countGet(): () => Promise<{
data?: number
error?: Error
}> {
interface ElementCountGetResponse {
data?: number
error?: Error
}
return async (): Promise<ElementCountGetResponse> => {
try {
const { data } = await axios.get(
`${config.API_URL}/${elementName}CountGet`,
axiosConfig
)
return { data }
} catch (error) {
return { error: error as Error }
}
}
}
return { listGet, get, set, add, countGet }
}

View File

@@ -30,12 +30,13 @@ const elementName = "PreVolunteer"
export type PreVolunteerWithoutId = Omit<PreVolunteer, "id">
const { listGet, get, set, add } = getServiceAccessors<PreVolunteerWithoutId, PreVolunteer>(
elementName,
translationPreVolunteer
)
const { listGet, get, set, add, countGet } = getServiceAccessors<
PreVolunteerWithoutId,
PreVolunteer
>(elementName, translationPreVolunteer)
export const preVolunteerListGet = listGet()
export const preVolunteerGet = get()
export const preVolunteerAdd = add()
export const preVolunteerSet = set()
export const preVolunteerCountGet = countGet()