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 => { 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 => 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 => fetchResults("/api/1.0/main/civility.json"); export const getGenders = async (): Promise => 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> { 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 => { return makeFetch( "POST", "/api/1.0/person/person.json", person, ); };