Files
doneit-web/src/app/shared/API/middleware/middleware-service.service.ts
T

138 lines
4.0 KiB
TypeScript
Raw Normal View History

import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { HttpServiceService } from 'src/app/services/http/http-service.service';
2023-12-13 16:44:29 +01:00
import { Observable} from 'rxjs';
2023-12-27 10:37:32 +01:00
import { CreateEvent, EditEvent, EventDetailsDTO, EventsDTO, refreshTokenDTO } from "./interface";
2023-12-13 16:44:29 +01:00
import { HttpParams } from '@angular/common/http';
import { DetectCalendars, makeHeaderForCalendar } from '../../utils/utils';
import { z } from "zod";
import { ok, err } from 'neverthrow';
2023-12-27 10:37:32 +01:00
import { SessionStore } from 'src/app/store/session.service';
2023-12-13 18:20:36 +01:00
/* import { ok, err } from 'neverthrow'; */
2023-12-13 16:44:29 +01:00
@Injectable({
providedIn: 'root'
})
export class MiddlewareServiceService {
constructor(
private HttpServiceService: HttpServiceService,
) {}
2023-12-13 16:44:29 +01:00
refreshToken(refreshToken: string): Observable<refreshTokenDTO> {
const data = {
refreshToken: refreshToken
}
return this.HttpServiceService.put(environment.apiURL + "UserAuthentication/RefreshToken", data, {})
2023-12-13 16:44:29 +01:00
// .pipe(
// map((response: HttpResponse<refreshToken>) => {
// return response.body
// })
// );
}
// ================================ Calendar =================================================
GetEvents(startDate: string, endDate: string, calendarId): Observable<EventsDTO[]> {
let geturl = environment.apiURL + 'calendar/GetEvents';
geturl = geturl.replace('/V4/', '/V5/')
let params = new HttpParams();
params = params.set("StartDate", startDate);
params = params.set("EndDate", endDate);
const calendar = DetectCalendars(calendarId)
const header = makeHeaderForCalendar(calendar)
let options = {
headers: header,
params: params
};
// return this.HttpServiceService.get<Event[]>(`${geturl}`, options);
return {} as any
}
2023-12-13 16:44:29 +01:00
2023-12-27 10:37:32 +01:00
GetEventDetail(eventId: string, calendarId: string) {
let geturl = environment.apiURL + 'calendar/GetEvent';
let params = new HttpParams();
params = params.set("EventId", eventId);
const calendar = DetectCalendars(calendarId)
const header = makeHeaderForCalendar(calendar)
let options = {
headers: header,
params: params
}
return this.HttpServiceService.get<EventDetailsDTO>(`${geturl}`, options);
}
createEvent(event: CreateEvent, calendarName: string, CalendarId) {
const puturl = environment.apiURL + 'Calendar/PostEvent';
let params = new HttpParams();
if(!event.TimeZone) {
const now = new Date();
event.TimeZone = event.TimeZone = now.toString().match(/([A-Z]+[\+-][0-9]+.*)/)[1];
}
if(!event.Organizer) {
event.Organizer = {
"Id": SessionStore.user.UserId,
"EmailAddress": SessionStore.user.Email,
"Name": SessionStore.user.UserName,
"IsRequired": true,
"UserType": "GD"
}
}
params = params.set("CalendarName", calendarName);
params = params.set("notifyUsers", true)
let options: any;
const calendar = DetectCalendars(CalendarId)
const header = makeHeaderForCalendar(calendar)
options = {
headers: header,
params: params
};
return this.HttpServiceService.post<string>(`${puturl}`, event, options)
}
editEvent(event: EditEvent, conflictResolutionMode: number, sendInvitationsOrCancellationsMode: number, CalendarId? ) {
let options: any;
const calendar = DetectCalendars(CalendarId)
const header = makeHeaderForCalendar(calendar)
let params = new HttpParams();
params = params.set("conflictResolutionMode", conflictResolutionMode.toString());
params = params.set("sendInvitationsOrCancellationsMode", sendInvitationsOrCancellationsMode.toString());
params.set('CalendarId', event.CalendarId)
params.set('CalendarName', event.CalendarName)
options = {
headers: header,
params: params
};
const putUrl = environment.apiURL + 'calendar/PutEvent';
return this.HttpServiceService.put<string>(`${putUrl}`, event, options);
}
2023-12-28 13:59:45 +01:00
// ================================ Acções =================================================
}