mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-27 00:55:01 +00:00
83 lines
2.3 KiB
TypeScript
83 lines
2.3 KiB
TypeScript
import { fetchResults, makeFetch } from "ChillMainAssets/lib/api/apiMethods";
|
|
import { Center, Civility, Gender } from "ChillMainAssets/types";
|
|
import {
|
|
AltName,
|
|
Person,
|
|
PersonIdentifierWorker,
|
|
PersonWrite,
|
|
} from "ChillPersonAssets/types";
|
|
import person from "ChillPersonAssets/vuejs/_components/OnTheFly/Person.vue";
|
|
|
|
/*
|
|
* GET a person by id
|
|
*/
|
|
export const getPerson = async (id: number): Promise<Person> => {
|
|
const url = `/api/1.0/person/person/${id}.json`;
|
|
return fetch(url).then((response) => {
|
|
if (response.ok) {
|
|
return response.json();
|
|
}
|
|
throw Error("Error with request resource response");
|
|
});
|
|
};
|
|
|
|
export const getPersonAltNames = async (): Promise<AltName[]> =>
|
|
fetch("/api/1.0/person/config/alt_names.json").then((response) => {
|
|
if (response.ok) {
|
|
return response.json();
|
|
}
|
|
throw Error("Error with request resource response");
|
|
});
|
|
|
|
export const getCivilities = async (): Promise<Civility[]> =>
|
|
fetchResults("/api/1.0/main/civility.json");
|
|
|
|
export const getGenders = async (): Promise<Gender[]> =>
|
|
fetchResults("/api/1.0/main/gender.json");
|
|
|
|
export const getCentersForPersonCreation = async (): Promise<{
|
|
showCenters: boolean;
|
|
centers: Center[];
|
|
}> => makeFetch("GET", "/api/1.0/person/creation/authorized-centers", null);
|
|
|
|
export const getPersonIdentifiers = async (): Promise<
|
|
PersonIdentifierWorker[]
|
|
> => fetchResults("/api/1.0/person/identifiers/workers");
|
|
|
|
export interface WritePersonViolationMap
|
|
extends Record<string, Record<string, unknown>> {
|
|
firstName: {
|
|
"{{ value }}": string | null;
|
|
};
|
|
lastName: {
|
|
"{{ value }}": string | null;
|
|
};
|
|
gender: {
|
|
"{{ value }}": string | null;
|
|
};
|
|
mobilenumber: {
|
|
"{{ types }}": string; // ex: "mobile number"
|
|
"{{ value }}": string; // ex: "+33 1 02 03 04 05"
|
|
};
|
|
phonenumber: {
|
|
"{{ types }}": string; // ex: "mobile number"
|
|
"{{ value }}": string; // ex: "+33 1 02 03 04 05"
|
|
};
|
|
email: {
|
|
"{{ value }}": string | null;
|
|
};
|
|
center: {
|
|
"{{ value }}": string | null;
|
|
};
|
|
civility: {
|
|
"{{ value }}": string | null;
|
|
};
|
|
}
|
|
export const createPerson = async (person: PersonWrite): Promise<Person> => {
|
|
return makeFetch<PersonWrite, Person, WritePersonViolationMap>(
|
|
"POST",
|
|
"/api/1.0/person/person.json",
|
|
person,
|
|
);
|
|
};
|