This commit is contained in:
Peter Maquiran
2024-05-29 16:06:48 +01:00
12 changed files with 334 additions and 98 deletions
@@ -3,6 +3,10 @@ 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 { EventInputDTO } from './agendaDataModels';
import { Event } from 'src/app/models/event.model';
import { SessionStore } from 'src/app/store/session.service';
@Injectable({
providedIn: 'root'
@@ -10,12 +14,9 @@ import { EventMapper } from './mapper/EventDetailsMapper';
export class AgendaDataRepositoryService {
constructor(
private agendaDataService: AgendaDataService
) {}
createEvent(eventData: any) {
return this.agendaDataService.createEvent(eventData).pipe(map(EventMapper.toDomain))
}
private agendaDataService: AgendaDataService,
private utils: Utils
) { }
getEventById(id: string) {
return this.agendaDataService.getEvent(id).pipe(
@@ -41,4 +42,71 @@ export class AgendaDataRepositoryService {
))
}
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,
}
this.agendaDataService.createEvent(eventInput).subscribe((value) => {
console.log(value)
},((error) => {
console.log('create event',error)
}));
}
updateEvent(eventId,eventData: Event,CalendarName,documents) {
console.log(this.utils.editeEventCalendarUserId(CalendarName,eventData));
let eventInput = {
userId: this.utils.selectedCalendarUserId(CalendarName,eventData),
ownerType: this.utils.selectedCalendarOwner(CalendarName),
subject: eventData.Subject,
body: eventData.Body.Text,
location: eventData.Location,
startDate: JSON.stringify(eventData.StartDate),
endDate: JSON.stringify(eventData.EndDate),
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,
}
this.agendaDataService.updateEvent(eventId, eventInput).subscribe((value) => {
console.log(value)
},((error) => {
console.log(error)
}));
}
deleteEvent(eventId) {
this.agendaDataService.deleteEvent(eventId,false).subscribe(() => {
console.log()
},((error) => {
console.log(error)
}))
}
}
@@ -6,12 +6,12 @@ import { EventOutputDTO } from './model/eventDTOOutput';
@Injectable({
providedIn: 'root'
})
export class AgendaDataService {
private baseUrl = 'https://gdapi-dev.dyndns.info/stage/api/v2'; // Your base URL
constructor(private http: HttpClient) { }
// Contacts Endpoints
getContacts(value: string): Observable<any> {
const params = new HttpParams().set('value', value);
return this.http.get<any>(`${this.baseUrl}/Contacts`, { params });
@@ -45,6 +45,10 @@ export class AgendaDataService {
return this.http.get<any>(`${this.baseUrl}/Events`, { params });
}
getEvent(id: string): Observable<any> {
return this.http.get<any>(`${this.baseUrl}/Events/${id}`);
}
updateEvent(id: string, eventData: any): Observable<any> {
return this.http.put<any>(`${this.baseUrl}/Events/${id}`, eventData);
}
@@ -53,10 +57,6 @@ export class AgendaDataService {
return this.http.patch<any>(`${this.baseUrl}/Events/${id}/Approval`, {});
}
getEvent(id: string): Observable<any> {
return this.http.get<any>(`${this.baseUrl}/Events/${id}`);
}
deleteEvent(id: string, deleteAllEvents: boolean): Observable<any> {
const params = new HttpParams().set('DeleteAllEvents', deleteAllEvents.toString());
return this.http.delete<any>(`${this.baseUrl}/Events/${id}`, { params });
@@ -92,6 +92,7 @@ export class AgendaDataService {
return this.http.get<any>(`${this.baseUrl}/Users`, { params });
}
getToken(): Observable<any> {
return this.http.get<any>(`${this.baseUrl}/Users/token`);
}
@@ -9,9 +9,9 @@ export const AttachCommunicationInputDTOSchema = z.object({
export const AttachmentInputDTOSchema = z.object({
sourceId: z.string().nullable(),
sourceName: z.string().nullable(),
description: z.string().nullable(),
sourceId: z.string().nullable().optional(),
sourceName: z.string().nullable().optional(),
description: z.string().nullable().optional(),
applicationId: z.number().int(),
}).strict();
@@ -30,27 +30,27 @@ export const AttendeeExternalInputDTOSchema = z.object({
export const AttendeeInputDTOSchema = z.object({
name: z.string().min(1),
emailAddress: z.string().nullable().optional(),
attendeeType: z.enum(["0", "1", "2"]),
attendeeType: z.number(),
wxUserId: z.number().int(),
}).strict();
const EAttendeeTypeDTO = z.enum(["0", "1", "2"]);
const EAttendeeTypeDTO = z.number();
const EEventCategoryDTO = z.enum(["1", "2"]);
const EEventCategoryDTO = z.number();
const EEventFilterCategoryDTO = z.enum(["1", "2", "3"]);
const EEventFilterCategoryDTO = z.number();
const EEventFilterStatusDTO = z.enum(["0", "1", "2", "3", "4", "5"]);
const EEventFilterStatusDTO = z.number();
const EEventFilterTypeDTO = z.enum(["1", "2", "3", "4"]);
const EEventFilterTypeDTO = z.number();
const EEventOwnerTypeDTO = z.enum(["1", "2", "3"]);
const EEventOwnerTypeDTO = z.number();
const EEventStatusDTO = z.enum(["0", "1", "2", "3", "4"]);
const EEventStatusDTO = z.number();
const EEventTypeDTO = z.enum(["1", "2", "3"]);
const EEventTypeDTO = z.number();
const ERecurringTypeDTO = z.enum(["0", "1", "2", "3", "4"]);
const ERecurringTypeDTO = z.number();
const EventAddAttachmentDTOSchema = z.object({
attachments: z.array(AttachmentInputDTOSchema),
@@ -79,7 +79,7 @@ export const EventInputDTOSchema = z.object({
attendees: z.array(AttendeeInputDTOSchema).nullable().optional(),
attachments: z.array(AttachmentInputDTOSchema).nullable().optional(),
recurrence: z.object({
frequency: ERecurringTypeDTO,
frequency: z.number().int(),
occurrences: z.number().int(),
}),
organizerId: z.number().int(),
@@ -87,7 +87,7 @@ export const EventInputDTOSchema = z.object({
}).strict();
export const EventRecurrenceInputDTOSchema = z.object({
frequency: ERecurringTypeDTO,
frequency: z.number().int(),
occurrences: z.number().int(),
}).strict();
@@ -108,7 +108,7 @@ export const EventUpdateDTOSchema = z.object({
isAllDayEvent: z.boolean(),
updateAllEvents: z.boolean(),
recurrence: z.object({
frequency: ERecurringTypeDTO,
frequency: z.number().int(),
occurrences: z.number().int(),
}),
}).strict();
@@ -133,57 +133,6 @@ export const ResponseSimpleDTOSchema = z.object({
})
const CommentSchema = z.object({
message: z.string(),
createdAt: z.string(),
});
const AttendeeSchema = z.object({
id: z.string(),
name: z.string(),
attendeeType: EAttendeeTypeDTO,
emailAddress: z.string(),
wxUserId: z.number(),
});
const OwnerSchema = z.object({
wxUserId: z.number(),
wxFullName: z.string(),
wxeMail: z.string(),
userPhoto: z.string(),
});
const OrganizerSchema = z.object({
wxUserId: z.number(),
wxFullName: z.string(),
wxeMail: z.string(),
userPhoto: z.string(),
});
const EventOutputDTOSchema = z.object({
id: z.string(),
owner: OwnerSchema,
ownerType: z.string(),
subject: z.string(),
body: z.string(),
location: z.string(),
startDate: z.string(),
endDate: z.string(),
type: z.string(),
category: z.string(),
attendees: z.array(AttendeeSchema),
isRecurring: z.boolean(),
eventRecurrence: z.null(),
hasAttachments: z.boolean(),
attachments:z.array(AttachmentInputDTOSchema),
comments: z.array(CommentSchema),
isPrivate: z.boolean(),
isAllDayEvent: z.boolean(),
organizer: OrganizerSchema,
status: z.string(),
});
export type EventOutputDTO = z.infer<typeof EventOutputDTOSchema>
export type AttachCommunicationInputDTO = z.infer<typeof AttachCommunicationInputDTOSchema>;
export type AttachmentInputDTO = z.infer<typeof AttachCommunicationInputDTOSchema>;
export type AttendeeCommunicationInputDTO = z.infer<typeof AttachCommunicationInputDTOSchema>;
@@ -192,7 +141,7 @@ export type AttendeeInputDTO = z.infer<typeof AttachCommunicationInputDTOSchema>
export type EventAddAttachmentDTO = z.infer<typeof AttachCommunicationInputDTOSchema>;
export type EventAddAttendeeDTO = z.infer<typeof AttachCommunicationInputDTOSchema>;
export type EventCommunicationInputDTO = z.infer<typeof AttachCommunicationInputDTOSchema>;
export type EventInputDTO = z.infer<typeof AttachCommunicationInputDTOSchema>;
export type EventInputDTO = z.infer<typeof EventInputDTOSchema>;
export type EventRecurrenceInputDTO = z.infer<typeof AttachCommunicationInputDTOSchema>;
export type EventRemoveAttachmentDTO = z.infer<typeof AttachCommunicationInputDTOSchema>;
export type EventRemoveAttendeeDTO = z.infer<typeof AttachCommunicationInputDTOSchema>;
@@ -0,0 +1,114 @@
import { Injectable } from '@angular/core';
import { AgendaDataService } from './agenda-data.service';
import { EventsService } from '../../events.service';
@Injectable({
providedIn: 'root'
})
export class Utils {
constructor(
private agendaDataService: AgendaDataService,
public eventService: EventsService,
) { }
selectedCalendarUserId(CalendarName,postEvent) {
if (this.eventService.calendarNamesType[CalendarName]?.['Oficial'] && postEvent.CalendarName == 'Oficial') {
return this.eventService.calendarNamesType[CalendarName]['OwnerId']
} else if (this.eventService.calendarNamesType[CalendarName]?.['Pessoal'] && postEvent.CalendarName == 'Pessoal') {
return this.eventService.calendarNamesType[CalendarName]['OwnerId']
} else {
return '11:11'
}
}
editeEventCalendarUserId(CalendarName,postEvent) {
let CalendarNameOwnerName = this.eventService.detectCalendarNameByCalendarId(postEvent.CalendarId)
if(this.eventService.calendarNamesType[CalendarNameOwnerName]?.['Oficial'] && this.eventService.calendarNamesType[CalendarNameOwnerName]?.['Pessoal']) {
return this.eventService.calendarNamesType[CalendarName]['OwnerId']
} else if (this.eventService.calendarNamesType[CalendarNameOwnerName]?.['Oficial']) {
return this.eventService.calendarNamesType[CalendarName]['OwnerId']
} else if (this.eventService.calendarNamesType[CalendarNameOwnerName]?.['Pessoal']) {
return this.eventService.calendarNamesType[CalendarName]['OwnerId']
} else {
return this.eventService.calendarNamesType[CalendarName]['OwnerId']
}
}
selectedCalendarOwner(CalendarName) {
let selectedCalendar = this.eventService.calendarNamesType[CalendarName]?.['RoleId'];
if (selectedCalendar) {
if (selectedCalendar.Role == 100000014) {
return 1;
} else if (selectedCalendar.Role == 100000011) {
return 2
} else {
return 3
}
}
}
calendarCategorySeleted(calendarName) {
var selectedCalendar = {
'Oficial': 1,
'Pessoal': 2
}
return selectedCalendar[calendarName];
}
calendarTypeSeleted(calendarName) {
var selectedType = {
'Reunião': 1,
'Viagem': 2,
'Conferência': 3,
'Encontro': 1
}
return selectedType[calendarName];
}
documentAdded(documents:any[]) {
return documents.map((e) => {
return {
sourceId: e.Id,
sourceName: e.Assunto,
description: "",
applicationId: parseInt(e.ApplicationType.toString())
};
});
}
atendeesSeletedType(type) {
var selectedType = {
'true': 1,
'false':2,
'other':3,
}
return selectedType[type];
}
attendeesAdded(taskParticipants: any[]) {
return taskParticipants.map((e) => {
return {
name: e.Name,
emailAddress: e.EmailAddress,
attendeeType: this.atendeesSeletedType(JSON.stringify(e.IsRequired)),
wxUserId: e.Id,
}
});
}
}