mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
New Services, New Login, Better things
This commit is contained in:
@@ -2,141 +2,87 @@ import { Injectable } from '@angular/core';
|
||||
|
||||
import { Event } from '../models/event.model';
|
||||
import axios from 'axios'
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { stringify } from 'querystring';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { User } from '../models/user.model';
|
||||
import { CalModalPageRoutingModule } from '../pages/cal-modal/cal-modal-routing.module';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class EventsService {
|
||||
/* Set events */
|
||||
private events: Event[] = [
|
||||
{
|
||||
EventId: '1',
|
||||
Subject: 'Reunião do Conselho de Ministros',
|
||||
Body: null,
|
||||
Location: 'Luanda, Palácio presidencial',
|
||||
CalendarId: '',
|
||||
CalendarName: 'pessoal',
|
||||
StartDate: '10:30',
|
||||
EndDate: '11:00',
|
||||
EventType: '',
|
||||
RequiredAttendees: null,
|
||||
OptionalAttendees: null,
|
||||
HasAttachments: false,
|
||||
IsMeeting: false,
|
||||
IsRecurring: false,
|
||||
AppointmentState: 0,
|
||||
TimeZone: '',
|
||||
Organizer: '',
|
||||
Categories: null,
|
||||
Attachments: null,
|
||||
},
|
||||
{
|
||||
EventId: '2',
|
||||
Subject: 'Conference call Particular',
|
||||
Body: null,
|
||||
Location: 'Luanda, Palácio presidencial',
|
||||
CalendarId: '',
|
||||
CalendarName: 'pessoal',
|
||||
StartDate: '10:30',
|
||||
EndDate: '11:00',
|
||||
EventType: '',
|
||||
RequiredAttendees: null,
|
||||
OptionalAttendees: null,
|
||||
HasAttachments: false,
|
||||
IsMeeting: false,
|
||||
IsRecurring: false,
|
||||
AppointmentState: 0,
|
||||
TimeZone: '',
|
||||
Organizer: '',
|
||||
Categories: null,
|
||||
Attachments: null,
|
||||
}
|
||||
];
|
||||
options = {};
|
||||
|
||||
authheader = {};
|
||||
loggeduser: User;
|
||||
headers: HttpHeaders;
|
||||
|
||||
constructor(private http: HttpClient, private user: AuthService) {
|
||||
constructor(private http: HttpClient, user: AuthService) {
|
||||
this.loggeduser = user.ValidatedUser;
|
||||
this.options = { headers: {'Authorization': this.loggeduser.BasicAuthKey}};
|
||||
this.headers = new HttpHeaders();
|
||||
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
|
||||
}
|
||||
|
||||
allEvents(): Observable<Event[]>{
|
||||
console.log(this.loggeduser);
|
||||
const geturl = environment.apiURL + 'calendar/GetEvents?StartDate=2020-08-14 00:00:00&EndDate=2020-08-19 23:59:00&CalendarName=Pessoal';
|
||||
getAllEvents(startdate:string, enddate:string): Observable<Event[]>{
|
||||
const geturl = environment.apiURL + 'calendar/GetAllEvents';
|
||||
let params = new HttpParams();
|
||||
|
||||
params = params.set("StartDate", startdate);
|
||||
params = params.set("EndDate", enddate);
|
||||
|
||||
return this.http.get<Event[]>(`${geturl}`, this.options)
|
||||
}
|
||||
getEvent(ev: string): Observable<Event>{
|
||||
const geturl = environment.apiURL + 'calendar/GetEvent?EventId=';
|
||||
|
||||
return this.http.get<Event>(`${geturl + ev}`, this.options)
|
||||
}
|
||||
|
||||
PutEvent(event: Event): Observable<Event>
|
||||
{
|
||||
const puturl = environment.apiURL +'calendar/PutEvent?conflictResolutionMode=2&sendInvitationsOrCancellationsMode=3';
|
||||
|
||||
return this.http.put<Event>(`${puturl}`, event,this.options)
|
||||
}
|
||||
|
||||
AddEvent(postEvent: any){
|
||||
const url = 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/api/calendar/PostEvent';
|
||||
const mydata = JSON.stringify({
|
||||
"AppointmentState":1,
|
||||
"Body":{"BodyType":1,"Text":"Noooooo"},
|
||||
"CalendarId":"AAMkAGMwNTJiZDY2LTZjN2MtNDgzYS1hNzAzLTZhZWRhNTk3ZWNiMAAuAAAAAABgX8u97PeNQrYTHXctnZkcAQB4Hy3hTowgSI7Yp8YAVgKKAAACCd9zAAA=",
|
||||
"EndDate":"8/16/2020 6:00:00 PM",
|
||||
"EventType":"Single","HasAttachments":false,
|
||||
"IsMeeting":true,"IsRecurring":false,
|
||||
"Location":postEvent.Location,
|
||||
"OptionalAttendees":null,
|
||||
"Organizer":{"EmailAddress":"paulo.pinto@gabinetedigital.local","Name":"Paulo Pinto"},
|
||||
"RequiredAttendees":[{"EmailAddress":"Administrator@gabinetedigital.local","Name":"Administrator"},{"EmailAddress":"tiago.kayaya@gabinetedigital.local","Name":"Tiago Kayaya"}],
|
||||
"StartDate":"8/14/2020 5:30:00 PM",
|
||||
"Subject":postEvent.Subject,
|
||||
"TimeZone":"(UTC+01:00) Centro-Oeste da África"});
|
||||
/* const options = {
|
||||
method: 'post',
|
||||
url: 'url',
|
||||
headears: {
|
||||
'Authorization': 'Basic Z2FiaW5ldGVkaWdpdGFsLmxvY2FsXHBhdWxvLnBpbnRvOnRhYnRlc3RlQDAwNg==',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
data: data
|
||||
} */
|
||||
console.log(postEvent.Subject);
|
||||
axios({
|
||||
method: 'post',
|
||||
url: url,
|
||||
data: mydata,
|
||||
headers: {'Authorization': 'Basic Z2FiaW5ldGVkaWdpdGFsLmxvY2FsXHBhdWxvLnBpbnRvOnRhYnRlc3RlQDAwNg==',
|
||||
'Content-Type': 'application/json' }
|
||||
})
|
||||
.then(function (response) {
|
||||
//handle success
|
||||
console.log(response);
|
||||
})
|
||||
.catch(function (response) {
|
||||
//handle error
|
||||
console.log(response);
|
||||
});
|
||||
}
|
||||
|
||||
getStaticEvent(eventId: string){
|
||||
return {
|
||||
// The find() function looks for an event in a array and return true if found
|
||||
...this.events.find(event => {
|
||||
//Compare if the event found is the same as the event passed in as parameter
|
||||
return event.EventId === eventId;
|
||||
})
|
||||
let options = {
|
||||
headers: this.headers,
|
||||
params: params
|
||||
};
|
||||
|
||||
console.log(options);
|
||||
|
||||
return this.http.get<Event[]>(`${geturl}`, options);
|
||||
}
|
||||
|
||||
getEvent(eventid: string): Observable<Event>{
|
||||
const geturl = environment.apiURL + 'calendar/GetEvent';
|
||||
let params = new HttpParams();
|
||||
|
||||
params = params.set("EventId", eventid);
|
||||
|
||||
let options = {
|
||||
headers: this.headers,
|
||||
params: params
|
||||
};
|
||||
|
||||
return this.http.get<Event>(`${geturl}`, options)
|
||||
}
|
||||
|
||||
putEvent(event: Event, conflictResolutionMode:number, sendInvitationsOrCancellationsMode:number): Observable<Event>
|
||||
{
|
||||
const puturl = environment.apiURL + 'calendar/PutEvent';
|
||||
|
||||
let params: HttpParams;
|
||||
|
||||
params.append("conflictResolutionMode", conflictResolutionMode.toString());
|
||||
params.append("sendInvitationsOrCancellationsMode", sendInvitationsOrCancellationsMode.toString());
|
||||
|
||||
let options = {
|
||||
headers: this.headers,
|
||||
params: params
|
||||
};
|
||||
|
||||
return this.http.put<Event>(`${puturl}`, event, options)
|
||||
}
|
||||
|
||||
postEvent(event:Event, calendarName:string)
|
||||
{
|
||||
const puturl = environment.apiURL + 'calendar/PostEvent';
|
||||
let params = new HttpParams();
|
||||
|
||||
params = params.set("CalendarName", calendarName);
|
||||
|
||||
let options = {
|
||||
headers: this.headers,
|
||||
params: params
|
||||
};
|
||||
|
||||
return this.http.post<Event>(`${puturl}`, event, options)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user