mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
improve api interface
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { HttpContext, HttpHeaders, HttpParams } from '@angular/common/http';
|
import { HttpContext, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpResponse, HttpErrorResponse } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { tap, shareReplay, catchError } from "rxjs/operators";
|
import { tap, shareReplay, catchError } from "rxjs/operators";
|
||||||
import { Observable, of } from "rxjs";
|
import { Observable, of } from "rxjs";
|
||||||
|
|
||||||
@@ -11,8 +11,7 @@ export class HttpServiceService {
|
|||||||
|
|
||||||
constructor(private http: HttpClient) {}
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
|
put<T>(url: string, body: any | null, options: Options): Observable<T> {
|
||||||
put(url: string, body: any | null, options: Options): Observable<any> {
|
|
||||||
return this.http.put(url, body, options as any).pipe(
|
return this.http.put(url, body, options as any).pipe(
|
||||||
tap((response) => {
|
tap((response) => {
|
||||||
// Handle success response if needed
|
// Handle success response if needed
|
||||||
@@ -24,20 +23,35 @@ export class HttpServiceService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
post<T>(url: string, body: any | null, options: Options): Observable<T> {
|
||||||
|
return this.http.post(url, body, options as any).pipe(
|
||||||
|
tap((response) => {
|
||||||
|
// Handle success response if needed
|
||||||
|
}),
|
||||||
|
catchError((error) => {
|
||||||
|
// Handle error response if needed
|
||||||
|
return of(error);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
get<T>(url: string, options: Options): Observable<T> {
|
||||||
|
return this.http.get(url, options ).pipe(
|
||||||
|
tap((response) => {
|
||||||
|
// Handle success response if needed
|
||||||
|
}),
|
||||||
|
catchError((error) => {
|
||||||
|
// Handle error response if needed
|
||||||
|
return of(error);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
headers?: HttpHeaders | {
|
headers?: HttpHeaders
|
||||||
[header: string]: string | string[];
|
params?: HttpParams
|
||||||
};
|
|
||||||
context?: HttpContext;
|
|
||||||
observe?: 'body';
|
|
||||||
params?: HttpParams | {
|
|
||||||
[param: string]: string | number | boolean | ReadonlyArray<string | number | boolean>;
|
|
||||||
};
|
|
||||||
reportProgress?: boolean;
|
|
||||||
responseType?: 'arraybuffer';
|
|
||||||
withCredentials?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+128
-1
@@ -4,7 +4,7 @@ export interface refreshTokenDTO {
|
|||||||
refreshToken: null
|
refreshToken: null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===========================================================
|
||||||
export interface EventsDTO {
|
export interface EventsDTO {
|
||||||
HasAttachments: boolean
|
HasAttachments: boolean
|
||||||
IsAllDayEvent: boolean
|
IsAllDayEvent: boolean
|
||||||
@@ -23,6 +23,7 @@ export interface EventsDTO {
|
|||||||
IsPrivate: boolean
|
IsPrivate: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===========================================================
|
||||||
|
|
||||||
export interface EventDetailsDTO {
|
export interface EventDetailsDTO {
|
||||||
HasAttachments: boolean
|
HasAttachments: boolean
|
||||||
@@ -101,3 +102,129 @@ interface EventDetailsAttachment {
|
|||||||
ApplicationId: number
|
ApplicationId: number
|
||||||
FileSize: number
|
FileSize: number
|
||||||
}
|
}
|
||||||
|
// ===========================================================
|
||||||
|
|
||||||
|
|
||||||
|
// =================================================== Post ===========================================
|
||||||
|
|
||||||
|
export interface CreateEvent {
|
||||||
|
EventId: string;
|
||||||
|
Subject: string;
|
||||||
|
Body: {
|
||||||
|
BodyType: string;
|
||||||
|
Text: string;
|
||||||
|
};
|
||||||
|
Location: string;
|
||||||
|
CalendarId: string;
|
||||||
|
CalendarName: string;
|
||||||
|
StartDate: string;
|
||||||
|
EndDate: string;
|
||||||
|
EventType: string;
|
||||||
|
Attendees: CreateAttendee[];
|
||||||
|
IsMeeting: boolean;
|
||||||
|
IsRecurring: boolean;
|
||||||
|
AppointmentState: number;
|
||||||
|
TimeZone: string;
|
||||||
|
Organizer?: CreateOrganizer;
|
||||||
|
Category: string;
|
||||||
|
HasAttachments: boolean;
|
||||||
|
EventRecurrence: {
|
||||||
|
Type: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CreateAttendee {
|
||||||
|
Id: number;
|
||||||
|
EmailAddress: string;
|
||||||
|
Name: string;
|
||||||
|
IsRequired: boolean;
|
||||||
|
UserType: string;
|
||||||
|
IsPR: boolean;
|
||||||
|
Entity: string;
|
||||||
|
Acknowledgment: boolean;
|
||||||
|
RoleDescription: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CreateOrganizer {
|
||||||
|
Id: number;
|
||||||
|
EmailAddress: string;
|
||||||
|
Name: string;
|
||||||
|
IsRequired: boolean;
|
||||||
|
UserType: string;
|
||||||
|
}
|
||||||
|
// ================================================ PUT =============================================
|
||||||
|
|
||||||
|
|
||||||
|
export interface EditEvent {
|
||||||
|
HasAttachments: boolean;
|
||||||
|
EventComunicationId: number;
|
||||||
|
EventId: string;
|
||||||
|
Subject: string;
|
||||||
|
Body: {
|
||||||
|
BodyType: number;
|
||||||
|
Text: string;
|
||||||
|
};
|
||||||
|
Location: string;
|
||||||
|
CalendarId: string;
|
||||||
|
CalendarName: string;
|
||||||
|
StartDate: string;
|
||||||
|
EndDate: string;
|
||||||
|
EventType: string;
|
||||||
|
Attendees: Attendee[];
|
||||||
|
IsMeeting: boolean;
|
||||||
|
IsRecurring: boolean;
|
||||||
|
IsAllDayEvent: boolean;
|
||||||
|
AppointmentState: number;
|
||||||
|
TimeZone: string;
|
||||||
|
Organizer: Organizer;
|
||||||
|
InstanceId: null | string;
|
||||||
|
Category: string;
|
||||||
|
EventRecurrence: {
|
||||||
|
Type: string;
|
||||||
|
Day: null | string;
|
||||||
|
DayOfWeek: null | string;
|
||||||
|
Month: null | string;
|
||||||
|
LastOccurrence: null | string;
|
||||||
|
};
|
||||||
|
Attachments: Attachment[];
|
||||||
|
IsPrivate: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Attendee {
|
||||||
|
Id: number;
|
||||||
|
EmailAddress: string;
|
||||||
|
Name: string;
|
||||||
|
IsRequired: boolean;
|
||||||
|
UserType: string;
|
||||||
|
IsPR: boolean;
|
||||||
|
Entity: null | string;
|
||||||
|
Acknowledgment: boolean;
|
||||||
|
RoleDescription: null | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Organizer {
|
||||||
|
Id: number;
|
||||||
|
EmailAddress: string;
|
||||||
|
Name: string;
|
||||||
|
IsRequired: boolean;
|
||||||
|
UserType: null | string;
|
||||||
|
IsPR: boolean;
|
||||||
|
Entity: null | string;
|
||||||
|
Acknowledgment: boolean;
|
||||||
|
RoleDescription: null | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Attachment {
|
||||||
|
Id: number;
|
||||||
|
ParentId: string;
|
||||||
|
Source: number;
|
||||||
|
SourceId: string;
|
||||||
|
Description: string;
|
||||||
|
SourceName: string;
|
||||||
|
CreateDate: string;
|
||||||
|
Stakeholders: string;
|
||||||
|
Link: string;
|
||||||
|
Data: null | string;
|
||||||
|
ApplicationId: number;
|
||||||
|
FileSize: number;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,14 +2,12 @@ import { Injectable } from '@angular/core';
|
|||||||
import { environment } from 'src/environments/environment';
|
import { environment } from 'src/environments/environment';
|
||||||
import { HttpServiceService } from 'src/app/services/http/http-service.service';
|
import { HttpServiceService } from 'src/app/services/http/http-service.service';
|
||||||
import { Observable} from 'rxjs';
|
import { Observable} from 'rxjs';
|
||||||
import { EventsDTO, refreshTokenDTO } from "./interface";
|
import { CreateEvent, EditEvent, EventDetailsDTO, EventsDTO, refreshTokenDTO } from "./interface";
|
||||||
import { HttpParams } from '@angular/common/http';
|
import { HttpParams } from '@angular/common/http';
|
||||||
import { DetectCalendars, makeHeaderForCalendar } from '../../utils/utils';
|
import { DetectCalendars, makeHeaderForCalendar } from '../../utils/utils';
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ok, err } from 'neverthrow';
|
import { ok, err } from 'neverthrow';
|
||||||
|
import { SessionStore } from 'src/app/store/session.service';
|
||||||
// let a = z
|
|
||||||
// let b = ok
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -58,4 +56,79 @@ export class MiddlewareServiceService {
|
|||||||
return {} as any
|
return {} as any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
|
|||||||
import { PublicationFolderService } from 'src/app/store/publication-folder.service';
|
import { PublicationFolderService } from 'src/app/store/publication-folder.service';
|
||||||
import { AskModalPage } from 'src/app/modals/ask-modal/ask-modal.page';
|
import { AskModalPage } from 'src/app/modals/ask-modal/ask-modal.page';
|
||||||
import { checkFileTypeService } from 'src/app/services/checkFileType.service';
|
import { checkFileTypeService } from 'src/app/services/checkFileType.service';
|
||||||
import { PublicationVideoManagerService } from "src/app/services/publication/publication-video-manager.service"
|
import { PublicationVideoManagerService } from "src/app/services/publication/publication-video-manager.service";
|
||||||
import { StopvideoService } from "src/app/services/stopvideo.service"
|
import { StopvideoService } from "src/app/services/stopvideo.service";
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-view-publications',
|
selector: 'app-view-publications',
|
||||||
templateUrl: './view-publications.page.html',
|
templateUrl: './view-publications.page.html',
|
||||||
|
|||||||
Reference in New Issue
Block a user