-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e552c7c
commit 48749be
Showing
20 changed files
with
275 additions
and
223 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
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
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,13 @@ | ||
import { getBaseURI } from './utils'; | ||
|
||
type Init = { | ||
isSearchDisable: boolean; | ||
}; | ||
|
||
export async function getInit(): Promise<Init> { | ||
const url = `${getBaseURI()}/init`; | ||
const headers = new Headers(); | ||
headers.append('Accept', 'application/json'); | ||
|
||
return fetch(url, { headers }).then((res) => res.json() as Promise<Init>); | ||
} |
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,43 @@ | ||
import { computeAuthorizationHeader, getBaseURI } from './utils'; | ||
|
||
export async function getSeries(token: string): Promise<unknown> { | ||
const url = `${getBaseURI()}/search/series`; | ||
const headers = new Headers(); | ||
headers.append('Accept', 'application/json'); | ||
headers.append('Authorization', computeAuthorizationHeader(token)); | ||
|
||
return fetch(url, { headers }).then((res) => res.json()); | ||
} | ||
|
||
export async function getOperations( | ||
id: string, | ||
token: string, | ||
): Promise<unknown> { | ||
const url = `${getBaseURI()}/search/series/${id}/operations`; | ||
const headers = new Headers(); | ||
headers.append('Accept', 'application/json'); | ||
headers.append('Authorization', computeAuthorizationHeader(token)); | ||
|
||
return fetch(url, { headers }).then((res) => res.json()); | ||
} | ||
|
||
export async function getCampaigns( | ||
id: string, | ||
token: string, | ||
): Promise<unknown> { | ||
const url = `${getBaseURI()}/search/operations/${id}/collections`; | ||
const headers = new Headers(); | ||
headers.append('Accept', 'application/json'); | ||
headers.append('Authorization', computeAuthorizationHeader(token)); | ||
|
||
return fetch(url, { headers }).then((res) => res.json()); | ||
} | ||
|
||
export async function getUnitsList(token: string): Promise<unknown> { | ||
const url = `${getBaseURI()}/meta-data/units`; | ||
const headers = new Headers(); | ||
headers.append('Accept', 'application/json'); | ||
headers.append('Authorization', computeAuthorizationHeader(token)); | ||
|
||
return fetch(url, { headers }).then((res) => res.json()); | ||
} |
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,15 @@ | ||
import getNomenclaturesContent from '../utils/codes-lists/__mocks__/get-nomenclatures.json'; | ||
|
||
type NomenclaturesJSON = { | ||
nomenclatures: { [key: string]: unknown }; | ||
}; | ||
|
||
const nomenclaturesJSON: NomenclaturesJSON = getNomenclaturesContent; | ||
|
||
export function getNomenclatures(): NomenclaturesJSON { | ||
return nomenclaturesJSON; | ||
} | ||
|
||
export function getNomenclature(id: string): unknown { | ||
return nomenclaturesJSON.nomenclatures[id]; | ||
} |
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,117 @@ | ||
import { computeAuthorizationHeader, getBaseURI } from './utils'; | ||
|
||
const pathQuestionnaire = 'persistence/questionnaire'; | ||
const pathQuestionnaireList = 'persistence/questionnaires'; | ||
|
||
/** | ||
* Retrieve questionnaires associated to the provided stamp (e.g. "DR59-SNDI59") | ||
*/ | ||
export async function getQuestionnaireList( | ||
stamp: string, | ||
token: string, | ||
): Promise<unknown[]> { | ||
const url = `${getBaseURI()}/${pathQuestionnaireList}/search/meta?owner=${stamp}`; | ||
const headers = new Headers(); | ||
headers.append('Accept', 'application/json'); | ||
headers.append('Authorization', computeAuthorizationHeader(token)); | ||
|
||
return fetch(url, { | ||
headers, | ||
}).then((res) => res.json() as Promise<unknown[]>); | ||
} | ||
|
||
export async function getStampsList(token: string): Promise<unknown> { | ||
const url = `${getBaseURI()}/${pathQuestionnaireList}/stamps`; | ||
const headers = new Headers(); | ||
headers.append('Accept', 'application/json'); | ||
headers.append('Authorization', computeAuthorizationHeader(token)); | ||
|
||
return fetch(url, { | ||
headers, | ||
}).then((res) => res.json()); | ||
} | ||
|
||
/** | ||
* Create new questionnaire | ||
*/ | ||
export async function postQuestionnaire(qr: unknown, token: string) { | ||
const url = `${getBaseURI()}/${pathQuestionnaireList}`; | ||
const headers = new Headers(); | ||
headers.append('Content-Type', 'application/json'); | ||
headers.append('Authorization', computeAuthorizationHeader(token)); | ||
|
||
return fetch(url, { | ||
method: 'POST', | ||
headers, | ||
body: JSON.stringify(qr), | ||
}).then((res) => { | ||
if (res.ok) return res; | ||
throw new Error(`Network request failed :${res.statusText}`); | ||
}); | ||
} | ||
|
||
/** | ||
* Update questionnaire by id | ||
*/ | ||
export async function putQuestionnaire(id: string, qr: unknown, token: string) { | ||
const url = `${getBaseURI()}/${pathQuestionnaire}/${id}`; | ||
const headers = new Headers(); | ||
headers.append('Content-Type', 'application/json'); | ||
headers.append('Authorization', computeAuthorizationHeader(token)); | ||
|
||
return fetch(url, { | ||
method: 'PUT', | ||
headers, | ||
body: JSON.stringify(qr), | ||
}).then((res) => { | ||
if (res.ok) return res; | ||
throw new Error(`Network request failed :${res.statusText}`); | ||
}); | ||
} | ||
|
||
/** | ||
* Retrieve questionnaire by id | ||
*/ | ||
export async function getQuestionnaire( | ||
id: string, | ||
token: string, | ||
): Promise<unknown> { | ||
const url = `${getBaseURI()}/${pathQuestionnaire}/${id}`; | ||
const headers = new Headers(); | ||
headers.append('Accept', 'application/json'); | ||
headers.append('Authorization', computeAuthorizationHeader(token)); | ||
|
||
return fetch(url, { | ||
headers, | ||
}).then((res) => res.json()); | ||
} | ||
|
||
/** | ||
* Will send a DELETE request in order to remove an existing questionnaire | ||
* | ||
* @param {deleteQuestionnaire} id The id of the questionnaire we want to delete | ||
*/ | ||
export async function deleteQuestionnaire(id: string, token: string) { | ||
const url = `${getBaseURI()}/${pathQuestionnaire}/${id}`; | ||
const headers = new Headers(); | ||
headers.append('Authorization', computeAuthorizationHeader(token)); | ||
|
||
return fetch(url, { | ||
method: 'DELETE', | ||
headers, | ||
}); | ||
} | ||
|
||
export async function getVariablesById( | ||
id: string, | ||
token: string, | ||
): Promise<unknown> { | ||
const url = `${getBaseURI()}/${pathQuestionnaire}/${id}/variables`; | ||
const headers = new Headers(); | ||
headers.append('Accept', 'application/json'); | ||
headers.append('Authorization', computeAuthorizationHeader(token)); | ||
|
||
return fetch(url, { | ||
headers, | ||
}).then((res) => res.json()); | ||
} |
Oops, something went wrong.