mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-24 08:33:49 +00:00
wip on app2
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
export function whoami(): import('ChillCalendarAssets/types').User;
|
||||
|
||||
export function fetchCalendarRangeForUser(user: import('ChillCalendarAssets/types').User, start: Date, end: Date): import('ChillCalendarAssets/types').CalendarRange[];
|
||||
|
||||
export function fetchCalendarRemoteForUser(user: import('ChillCalendarAssets/types').User, start: Date, end: Date): import('ChillCalendarAssets/types').Calendar[];
|
@@ -1,7 +1,9 @@
|
||||
import {fetchResults} from 'ChillMainAssets/lib/api/apiMethods';
|
||||
import {datetimeToISO} from 'ChillMainAssets/chill/js/date';
|
||||
import {User} from 'ChillMainAssets/types';
|
||||
import {CalendarRange, CalendarRemote} from 'ChillCalendarAssets/types';
|
||||
|
||||
const whoami = () => {
|
||||
export const whoami = (): Promise<User> => {
|
||||
const url = `/api/1.0/main/whoami.json`;
|
||||
return fetch(url)
|
||||
.then(response => {
|
||||
@@ -25,24 +27,18 @@ const whoami = () => {
|
||||
* @param Date end
|
||||
* @return Promise
|
||||
*/
|
||||
const fetchCalendarRangeForUser = (user, start, end) => {
|
||||
export const fetchCalendarRangeForUser = (user: User, start: Date, end: Date): Promise<CalendarRange[]> => {
|
||||
const uri = `/api/1.0/calendar/calendar-range-available/${user.id}.json`;
|
||||
const dateFrom = datetimeToISO(start);
|
||||
const dateTo = datetimeToISO(end);
|
||||
|
||||
return fetchResults(uri, {dateFrom, dateTo});
|
||||
return fetchResults<CalendarRange>(uri, {dateFrom, dateTo});
|
||||
}
|
||||
|
||||
const fetchCalendarRemoteForUser = (user, start, end) => {
|
||||
export const fetchCalendarRemoteForUser = (user: User, start: Date, end: Date): Promise<CalendarRemote[]> => {
|
||||
const uri = `/api/1.0/calendar/proxy/calendar/by-user/${user.id}/events`;
|
||||
const dateFrom = datetimeToISO(start);
|
||||
const dateTo = datetimeToISO(end);
|
||||
|
||||
return fetchResults(uri, {dateFrom, dateTo});
|
||||
return fetchResults<CalendarRemote>(uri, {dateFrom, dateTo});
|
||||
}
|
||||
|
||||
export {
|
||||
whoami,
|
||||
fetchCalendarRangeForUser,
|
||||
fetchCalendarRemoteForUser,
|
||||
};
|
@@ -1,2 +0,0 @@
|
||||
|
||||
export function calendarRangeToFullCalendarEvent(entity: import('ChillCalendarAssets/types').CalendarRange): import('@fullcalendar/vue3').EventInput;
|
@@ -1,14 +1,26 @@
|
||||
import {COLORS} from '../const';
|
||||
import {ISOToDatetime} from 'ChillMainAssets/chill/js/date';
|
||||
import {DateTime, User} from 'ChillMainAssets/types';
|
||||
import {CalendarRange, CalendarRemote} from 'ChillCalendarAssets/types';
|
||||
import {EventInput} from '@fullcalendar/vue3';
|
||||
|
||||
const addIdToValue = (string, id) => {
|
||||
export interface UserData {
|
||||
user: User,
|
||||
calendarRanges: CalendarRange[],
|
||||
calendarRangesLoaded: {}[],
|
||||
remotes: CalendarRemote[],
|
||||
remotesLoaded: {}[],
|
||||
mainColor: string,
|
||||
}
|
||||
|
||||
export const addIdToValue = (string: string, id: number): string => {
|
||||
let array = string ? string.split(',') : [];
|
||||
array.push(id.toString());
|
||||
let str = array.join();
|
||||
return str;
|
||||
};
|
||||
|
||||
const removeIdFromValue = (string, id) => {
|
||||
export const removeIdFromValue = (string: string, id: number) => {
|
||||
let array = string.split(',');
|
||||
array = array.filter(el => el !== id.toString());
|
||||
let str = array.join();
|
||||
@@ -18,7 +30,7 @@ const removeIdFromValue = (string, id) => {
|
||||
/*
|
||||
* Assign missing keys for the ConcernedGroups component
|
||||
*/
|
||||
const mapEntity = (entity) => {
|
||||
export const mapEntity = (entity: EventInput): EventInput => {
|
||||
let calendar = { ...entity};
|
||||
Object.assign(calendar, {thirdParties: entity.professionals});
|
||||
|
||||
@@ -37,7 +49,7 @@ const mapEntity = (entity) => {
|
||||
return calendar;
|
||||
};
|
||||
|
||||
const createUserData = (user, colorIndex) => {
|
||||
export const createUserData = (user: User, colorIndex: number): UserData => {
|
||||
const colorId = colorIndex % COLORS.length;
|
||||
console.log('colorId', colorId);
|
||||
return {
|
||||
@@ -51,7 +63,7 @@ const createUserData = (user, colorIndex) => {
|
||||
}
|
||||
|
||||
// TODO move this function to a more global namespace, as it is in use in MyCalendarRange app
|
||||
const calendarRangeToFullCalendarEvent = (entity) => {
|
||||
export const calendarRangeToFullCalendarEvent = (entity: CalendarRange): EventInput & {id: string} => {
|
||||
return {
|
||||
id: `range_${entity.id}`,
|
||||
title: "(" + entity.user.text + ")",
|
||||
@@ -64,7 +76,7 @@ const calendarRangeToFullCalendarEvent = (entity) => {
|
||||
};
|
||||
}
|
||||
|
||||
const remoteToFullCalendarEvent = (entity) => {
|
||||
export const remoteToFullCalendarEvent = (entity: CalendarRemote): EventInput & {id: string} => {
|
||||
console.log(entity);
|
||||
return {
|
||||
id: `range_${entity.id}`,
|
||||
@@ -75,12 +87,3 @@ const remoteToFullCalendarEvent = (entity) => {
|
||||
is: 'remote',
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
addIdToValue,
|
||||
calendarRangeToFullCalendarEvent,
|
||||
removeIdFromValue,
|
||||
remoteToFullCalendarEvent,
|
||||
mapEntity,
|
||||
createUserData,
|
||||
};
|
Reference in New Issue
Block a user