adapt api endpoint, resolve id parameter passed in api functions

This commit is contained in:
Mathieu Jaumotte 2021-05-10 10:43:28 +02:00
parent 43f3270171
commit dcd1856ebb
3 changed files with 34 additions and 28 deletions

View File

@ -1,18 +1,11 @@
const
locale = 'fr',
format = 'json'
, accompanying_period_id = window.accompanyingCourseId //tmp
;
/*
* Endpoint chill_person_accompanying_course_api_show
* method GET, get AccompanyingCourse Object
* Endpoint v.2 chill_api_single_accompanying_course__entity
* method GET/HEAD, get AccompanyingCourse Instance
*
* @accompanying_period_id___ integer
* @TODO var is not used but necessary in method signature
* @id integer - id of accompanyingCourse
*/
let getAccompanyingCourse = (accompanying_period_id___) => { //tmp
const url = `/${locale}/person/api/1.0/accompanying-course/${accompanying_period_id}/show.${format}`;
let getAccompanyingCourse = (id) => { //tmp
const url = `/api/1.0/person/accompanying-course/${id}.json`
return fetch(url)
.then(response => {
if (response.ok) { return response.json(); }
@ -24,12 +17,12 @@ let getAccompanyingCourse = (accompanying_period_id___) => { //tmp
* Endpoint v.2 chill_api_single_accompanying_course_participation,
* method POST/DELETE, add/close a participation to the accompanyingCourse
*
* @accompanying_period_id integer - id of accompanyingCourse
* @person_id integer - id of person
* @method string - POST or DELETE
* @id integer - id of accompanyingCourse
* @person_id integer - id of person
* @method string - POST or DELETE
*/
let postParticipation = (accompanying_period_id, person_id, method) => {
const url = `/api/1.0/person/accompanying-course/${accompanying_period_id}/participation.${format}`
let postParticipation = (id, person_id, method) => {
const url = `/api/1.0/person/accompanying-course/${id}/participation.json`
return fetch(url, {
method: method,
headers: {

View File

@ -3,8 +3,7 @@ import { createStore } from 'vuex';
import { getAccompanyingCourse, postParticipation } from '../api';
const debug = process.env.NODE_ENV !== 'production';
const id = window.accompanyingCourseId; //tmp
const id = window.accompanyingCourseId;
let initPromise = getAccompanyingCourse(id)
.then(accompanying_course => new Promise((resolve, reject) => {

View File

@ -1,16 +1,12 @@
const
locale = 'fr',
format = 'json'
;
/*
* Endpoint chill_person_search, method GET, get a list of persons
* Endpoint chill_person_search
* method GET, get a list of persons
*
* @query string - the query to search for
*/
let searchPersons = ({ query, options }) => {
console.log('options 2', options);
let url = `/${locale}/search.${format}?name=person_regular&q=${query}`;
console.log('options', options);
let url = `/fr/search.json?name=person_regular&q=${query}`;
return fetch(url)
.then(response => {
if (response.ok) { return response.json(); }
@ -18,4 +14,22 @@ let searchPersons = ({ query, options }) => {
});
};
export { searchPersons };
/*
* Endpoint v.2 chill_main_search_global
* method GET, get a list of persons and thirdparty
*
* NOTE: this is a temporary WIP endpoint, return inconsistent random results
* @query string - the query to search for
*/
let searchPersons_2 = ({ query, options }) => {
console.log('options', options);
let url = `/api/1.0/search.json?q=${query}`
return fetch(url)
.then(response => {
if (response.ok) { return response.json(); }
throw Error('Error with request resource response');
});
};
export { searchPersons, searchPersons_2 };