mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
153 lines
4.7 KiB
TypeScript
153 lines
4.7 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { AgendaDataService } from './agenda-data.service';
|
|
import { catchError, map } from 'rxjs/operators';
|
|
import { ListEventMapper } from './mapper/EventListMapper';
|
|
import { EventMapper } from './mapper/EventDetailsMapper';
|
|
import { Utils } from './utils';
|
|
import { EventInputDTO } from './agendaDataModels';
|
|
import { Event } from 'src/app/models/event.model';
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
import { EventListToApproveMapper } from './mapper/eventToApproveListMapper';
|
|
import { err, ok } from 'neverthrow';
|
|
import { of } from 'rxjs';
|
|
import { HttpErrorResponse } from '@angular/common/http';
|
|
import { EventToApproveDetailsMapper } from './mapper/EventToApproveDetailsMapper';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class AgendaDataRepositoryService {
|
|
|
|
constructor(
|
|
private agendaDataService: AgendaDataService,
|
|
private utils: Utils
|
|
) { }
|
|
|
|
async getEventById(id: string) {
|
|
try {
|
|
const result = await this.agendaDataService.getEvent(id).pipe(
|
|
map((response) => {
|
|
return EventMapper.toDomain(response.data)
|
|
})
|
|
).toPromise()
|
|
return ok (result)
|
|
} catch (e) {
|
|
return err(e as HttpErrorResponse)
|
|
}
|
|
}
|
|
|
|
async getEventToApproveById(id: string) {
|
|
|
|
try {
|
|
const result = await this.agendaDataService.getEvent(id).pipe(
|
|
map((response) => {
|
|
return EventToApproveDetailsMapper.toDomain(response.data)
|
|
})
|
|
).toPromise()
|
|
return ok (result)
|
|
} catch (e) {
|
|
return err(e as HttpErrorResponse)
|
|
}
|
|
|
|
}
|
|
|
|
async EventList({userId = null, startDate = null, endDate = null, status= 2, category= null, type= null, calendarOwnerName = ''}) {
|
|
try {
|
|
const result = await this.agendaDataService.getEvents(userId, startDate, endDate, status, category, type).pipe(
|
|
map((response) => {
|
|
return ListEventMapper.toDomain(response.data, calendarOwnerName, userId)
|
|
}
|
|
)).toPromise()
|
|
return ok (result)
|
|
} catch (e) {
|
|
return err(e as HttpErrorResponse)
|
|
}
|
|
}
|
|
|
|
eventToApproveList({userId, startDate = null, endDate = null, status = 0, category= null, type= null, calendarOwnerName = ''}) {
|
|
|
|
return this.agendaDataService.getEvents(userId, startDate = null, endDate = null, status, category= null, type= null).pipe(
|
|
map((response) => {
|
|
return EventListToApproveMapper.toDomain(response.data, calendarOwnerName, userId)
|
|
}
|
|
))
|
|
}
|
|
|
|
createEvent(eventData: Event, CalendarName, documents) {
|
|
console.log(eventData)
|
|
|
|
let eventInput = {
|
|
userId: this.utils.selectedCalendarUserId(CalendarName, eventData) as any,
|
|
ownerType: this.utils.selectedCalendarOwner(CalendarName),
|
|
subject: eventData.Subject,
|
|
body: eventData.Body.Text,
|
|
location: eventData.Location,
|
|
startDate: eventData.StartDate.toISOString(),
|
|
endDate: eventData.EndDate.toISOString(),
|
|
type: this.utils.calendarTypeSeleted(eventData.Category),
|
|
category: this.utils.calendarCategorySeleted(eventData.CalendarName),
|
|
attendees: this.utils.attendeesAdded(eventData.Attendees),
|
|
attachments: this.utils.documentAdded(documents),
|
|
recurrence: {
|
|
frequency: 0,
|
|
occurrences: 0,
|
|
},
|
|
organizerId: SessionStore.user.UserId,
|
|
isAllDayEvent: eventData.IsAllDayEvent,
|
|
}
|
|
|
|
return this.agendaDataService.createEvent(eventInput)
|
|
}
|
|
|
|
updateEvent(eventId, eventData) {
|
|
console.log(eventData.StartDate)
|
|
console.log(eventData.EndDate)
|
|
|
|
let eventInput = {
|
|
subject: eventData.Subject,
|
|
body: eventData.Body.Text || eventData.Body,
|
|
location: eventData.Location,
|
|
startDate: eventData.StartDate,
|
|
endDate: eventData.EndDate,
|
|
isAllDayEvent: eventData.IsAllDayEvent,
|
|
updateAllEvents: false,
|
|
recurrence: {
|
|
frequency: 0,
|
|
occurrences: 0
|
|
}
|
|
}
|
|
return this.agendaDataService.updateEvent(eventId, eventInput)
|
|
}
|
|
|
|
addEventAttendee(id,attendeeData) {
|
|
return this.agendaDataService.addEventAttendee(id,attendeeData);
|
|
}
|
|
|
|
addEventAttachment(id,attachmentData) {
|
|
return this.agendaDataService.addEventAttachment(id,attachmentData);
|
|
}
|
|
|
|
deleteEvent(eventId) {
|
|
return this.agendaDataService.deleteEvent(eventId, false)
|
|
}
|
|
|
|
removeEventAttachment(eventId,attachmentData) {
|
|
return this.agendaDataService.removeEventAttachment(eventId,attachmentData);
|
|
}
|
|
|
|
async deleteEvent1(eventId) {
|
|
|
|
try {
|
|
const result = await this.agendaDataService.deleteEvent(eventId,false).toPromise()
|
|
return ok (result)
|
|
} catch (e) {
|
|
return err(e as HttpErrorResponse)
|
|
}
|
|
|
|
}
|
|
|
|
eventToaprovalStatus(eventId, status) {
|
|
return this.agendaDataService.updateEventStatus(eventId,this.utils.statusEventAproval(status))
|
|
}
|
|
}
|