mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
169 lines
5.3 KiB
TypeScript
169 lines
5.3 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { AgendaDataService } from './agenda-data.service';
|
|
import { map } from 'rxjs/operators';
|
|
import { ListEventMapper } from './mapper/EventListMapper';
|
|
import { EventMapper } from './mapper/EventDetailsMapper';
|
|
import { Utils } from './utils';
|
|
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 { 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) => {
|
|
console.log('Response',response.data)
|
|
console.log('Output',EventMapper.toDomain(response.data))
|
|
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)
|
|
}
|
|
}
|
|
|
|
async eventToApproveList({userId, startDate = null, endDate = null, status = 0, category= null, type= null, calendarOwnerName = ''}) {
|
|
|
|
try {
|
|
const result = await this.agendaDataService.getEvents(userId, startDate = null, endDate = null, status, category= null, type= null).pipe(
|
|
map((response) => {
|
|
return EventListToApproveMapper.toDomain(response.data, calendarOwnerName, userId)
|
|
}
|
|
)).toPromise()
|
|
|
|
return ok (result)
|
|
} catch (e) {
|
|
return err(e as HttpErrorResponse)
|
|
}
|
|
}
|
|
|
|
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,) {
|
|
console.log(attendeeData)
|
|
console.log(this.utils.attendeesEdit(attendeeData))
|
|
return this.agendaDataService.addEventAttendee(id,{ attendees: this.utils.attendeesAdded(attendeeData) });
|
|
}
|
|
|
|
addEventAttachment(id,attachmentData) {
|
|
return this.agendaDataService.addEventAttachment(id,{ attachments: this.utils.documentAdded(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) {
|
|
let statusObject = {
|
|
status: this.utils.statusEventAproval(status),
|
|
comment: ""
|
|
}
|
|
return this.agendaDataService.updateEventStatus(eventId,statusObject)
|
|
}
|
|
|
|
getDocumentAttachments(applicationId,userId,subject,pageNumber,pageSize) {
|
|
return this.agendaDataService.getDocumentAttachment(applicationId,userId,subject,pageNumber,pageSize)
|
|
}
|
|
}
|