From 3769a7b8fee4ca3498043dd5e6067d2b17d81521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Wed, 29 May 2024 15:43:37 +0100 Subject: [PATCH] new api implementation --- src/app/models/attachment.model.ts | 24 +++- .../agenda/new-event/new-event.page.html | 2 +- .../pages/agenda/new-event/new-event.page.ts | 52 +++++++- .../Agenda/agenda-data-repository.service.ts | 75 +++++++++++- .../Repositorys/Agenda/agenda-data.service.ts | 2 +- .../Repositorys/Agenda/agendaDataModels.ts | 26 ++-- src/app/services/Repositorys/Agenda/utils.ts | 114 ++++++++++++++++++ .../agenda/edit-event/edit-event.page.html | 2 +- .../agenda/edit-event/edit-event.page.ts | 22 +++- .../agenda/new-event/new-event.page.html | 2 +- .../shared/agenda/new-event/new-event.page.ts | 27 ++++- .../agenda/view-event/view-event.page.ts | 11 +- 12 files changed, 325 insertions(+), 34 deletions(-) create mode 100644 src/app/services/Repositorys/Agenda/utils.ts diff --git a/src/app/models/attachment.model.ts b/src/app/models/attachment.model.ts index e944f6be8..d89059db4 100644 --- a/src/app/models/attachment.model.ts +++ b/src/app/models/attachment.model.ts @@ -4,8 +4,8 @@ export class Attachment { Source?: Sources; ApplicationId: number CreateDate: string - Data: null| string - Description:string + Data: null | string + Description: string Link: null SourceId: string SourceName: string @@ -13,8 +13,7 @@ export class Attachment { //Data: any; } -export enum Sources -{ +export enum Sources { Undefined = 0, webTRIX = 1, K2 = 2, @@ -35,3 +34,20 @@ export class EventAttachment { SourceTitle: string; } + +export class EventAttachment_v2 { + + sourceId: string; + sourceName: string; + description: string + applicationId: number + +} + +export class Atendees_v2 { + name: string; + emailAddress: string; + attendeeType: string; + wxUserId: number; + IsRequired: boolean; +} \ No newline at end of file diff --git a/src/app/pages/agenda/new-event/new-event.page.html b/src/app/pages/agenda/new-event/new-event.page.html index 5b638751a..f0d8ae412 100644 --- a/src/app/pages/agenda/new-event/new-event.page.html +++ b/src/app/pages/agenda/new-event/new-event.page.html @@ -403,7 +403,7 @@ - diff --git a/src/app/pages/agenda/new-event/new-event.page.ts b/src/app/pages/agenda/new-event/new-event.page.ts index dce9c8b2d..aada420d3 100644 --- a/src/app/pages/agenda/new-event/new-event.page.ts +++ b/src/app/pages/agenda/new-event/new-event.page.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { ModalController, NavParams, Platform } from '@ionic/angular'; -import { EventAttachment } from 'src/app/models/attachment.model'; +import { EventAttachment, EventAttachment_v2 } from 'src/app/models/attachment.model'; import { EventBody } from 'src/app/models/eventbody.model'; import { EventPerson } from 'src/app/models/eventperson.model'; import { SearchList } from 'src/app/models/search-document'; @@ -27,6 +27,8 @@ import { momentG } from 'src/plugin/momentG'; import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE, ThemePalette } from '@angular/material/core'; import { MatDatepickerModule } from '@angular/material/datepicker'; import { MomentDateAdapter } from '@angular/material-moment-adapter'; +import { EventInputDTO } from '../../../services/Repositorys/Agenda/agendaDataModels'; +import { AgendaDataRepositoryService } from 'src/app/services/Repositorys/Agenda/agenda-data-repository.service'; const CUSTOM_DATE_FORMATS: NgxMatDateFormats = { parse: { @@ -57,7 +59,7 @@ const MY_DATE_FORMAT = { providers: [ { provide: NGX_MAT_DATE_FORMATS, useValue: CUSTOM_DATE_FORMATS }, { provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] }, -{ provide: MAT_DATE_FORMATS, useValue: MY_DATE_FORMAT } + { provide: MAT_DATE_FORMATS, useValue: MY_DATE_FORMAT } ] }) @@ -130,7 +132,8 @@ export class NewEventPage implements OnInit { public TaskService: TaskService, private contactsService: ContactsService, private domSanitazerService: DomSanitizerService, - private dateAdapter: DateAdapter + private dateAdapter: DateAdapter, + private agendaDataRepository: AgendaDataRepositoryService ) { this.loggeduser = SessionStore.user; this.postEvent = new Event(); @@ -420,6 +423,29 @@ export class NewEventPage implements OnInit { } } + + save_v2() { + this.injectValidation() + this.runValidation() + + if (this.Form.invalid) { + + if (new Date(this.postEvent.StartDate).getTime() < new Date(this.postEvent.EndDate).getTime()) { + this.toastService._badRequest("Data de inicio menor que a data de fim") + } + + return false + } + const loader = this.toastService.loading() + + this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc); + this.postEvent.IsAllDayEvent = this.allDayCheck; + this.agendaDataRepository.createEvent(this.postEvent,this.CalendarName,this.documents); + loader.remove() + this.modalController.dismiss(); + this.hhtpErrorHandle.httpsSucessMessagge('new event') + } + async save() { this.injectValidation() @@ -532,6 +558,7 @@ export class NewEventPage implements OnInit { } + //This method return calendar id selectedCalendarId() { if (this.eventService.calendarNamesType[this.CalendarName]?.['Oficial'] && this.postEvent.CalendarName == 'Oficial') { @@ -546,6 +573,21 @@ export class NewEventPage implements OnInit { } } + //This method return calendar onwner user id + selectedCalendarUserId() { + + if (this.eventService.calendarNamesType[this.CalendarName]?.['Oficial'] && this.postEvent.CalendarName == 'Oficial') { + return this.eventService.calendarNamesType[this.CalendarName]['OwnerId'] + + } else if (this.eventService.calendarNamesType[this.CalendarName]?.['Pessoal'] && this.postEvent.CalendarName == 'Pessoal') { + + return this.eventService.calendarNamesType[this.CalendarName]['OwnerId'] + + } else { + return '11:11' + } + } + changeAgenda() { setTimeout(() => { @@ -900,13 +942,13 @@ export class NewEventPage implements OnInit { this.postEvent.IsAllDayEvent = this.allDayCheck; this.postEvent.StartDate = this.setAlldayTime(this.postEvent.StartDate) this.postEvent.EndDate = this.setAlldayTimeEndDate(this.postEvent.EndDate) - + console.log('Recurso ativado!!'); } else { this.postEvent.IsAllDayEvent = this.allDayCheck; this.postEvent.EndDate = this.setAlldayTimeEndDateNotAlday(this.postEvent.EndDate) console.log('Recurso desativado'); - + } } diff --git a/src/app/services/Repositorys/Agenda/agenda-data-repository.service.ts b/src/app/services/Repositorys/Agenda/agenda-data-repository.service.ts index 663f4f717..e8607862f 100644 --- a/src/app/services/Repositorys/Agenda/agenda-data-repository.service.ts +++ b/src/app/services/Repositorys/Agenda/agenda-data-repository.service.ts @@ -1,5 +1,9 @@ import { Injectable } from '@angular/core'; import { AgendaDataService } from './agenda-data.service'; +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' @@ -7,10 +11,75 @@ import { AgendaDataService } from './agenda-data.service'; export class AgendaDataRepositoryService { constructor( - private agendaDataService: AgendaDataService + private agendaDataService: AgendaDataService, + private utils: Utils ) { } - createEvent(eventData) { - this.agendaDataService.createEvent(eventData); + createEvent(eventData: Event,CalendarName,documents) { + console.log(eventData) + + let eventInput: EventInputDTO = { + userId: this.utils.selectedCalendarUserId(CalendarName,eventData), + 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: EventInputDTO = { + 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) + })) } } diff --git a/src/app/services/Repositorys/Agenda/agenda-data.service.ts b/src/app/services/Repositorys/Agenda/agenda-data.service.ts index 4680f32a8..01e3c13e3 100644 --- a/src/app/services/Repositorys/Agenda/agenda-data.service.ts +++ b/src/app/services/Repositorys/Agenda/agenda-data.service.ts @@ -7,7 +7,7 @@ import { Observable } from 'rxjs'; }) export class AgendaDataService { - private baseUrl = '/stage/api/v2'; // Your base URL + private baseUrl = 'https://gdapi-dev.dyndns.info/stage/api/v2'; // Your base URL constructor(private http: HttpClient) { } diff --git a/src/app/services/Repositorys/Agenda/agendaDataModels.ts b/src/app/services/Repositorys/Agenda/agendaDataModels.ts index a8593c6f5..d757e31bd 100644 --- a/src/app/services/Repositorys/Agenda/agendaDataModels.ts +++ b/src/app/services/Repositorys/Agenda/agendaDataModels.ts @@ -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(); diff --git a/src/app/services/Repositorys/Agenda/utils.ts b/src/app/services/Repositorys/Agenda/utils.ts new file mode 100644 index 000000000..d2dd34f09 --- /dev/null +++ b/src/app/services/Repositorys/Agenda/utils.ts @@ -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, + } + }); + } +} diff --git a/src/app/shared/agenda/edit-event/edit-event.page.html b/src/app/shared/agenda/edit-event/edit-event.page.html index 6307f2797..d2a9c46be 100644 --- a/src/app/shared/agenda/edit-event/edit-event.page.html +++ b/src/app/shared/agenda/edit-event/edit-event.page.html @@ -365,7 +365,7 @@ - diff --git a/src/app/shared/agenda/edit-event/edit-event.page.ts b/src/app/shared/agenda/edit-event/edit-event.page.ts index a6975183f..ad3bcfdee 100644 --- a/src/app/shared/agenda/edit-event/edit-event.page.ts +++ b/src/app/shared/agenda/edit-event/edit-event.page.ts @@ -16,6 +16,7 @@ import { SessionStore } from 'src/app/store/session.service'; import { HttpErrorHandle } from 'src/app/services/http-error-handle.service'; import { ContactsService } from 'src/app/services/contacts.service' import { DomSanitizerService } from 'src/app/services/DomSanitizer.service'; +import { AgendaDataRepositoryService } from 'src/app/services/Repositorys/Agenda/agenda-data-repository.service'; @Component({ selector: 'app-edit-event', @@ -103,10 +104,14 @@ export class EditEventPage implements OnInit { public ThemeService: ThemeService, private httpErrorHandle: HttpErrorHandle, private contactsService: ContactsService, - private domSanitizeService: DomSanitizerService - ) {} + private domSanitizeService: DomSanitizerService, + private agendaDataRepository: AgendaDataRepositoryService + ) { + + } ngOnInit() { + console.log(this.postEvent) this._postEvent = this.postEvent this.allDayCheck = this.postEvent.IsAllDayEvent; if(!this.restoreTemporaryData()) { @@ -337,6 +342,19 @@ export class EditEventPage implements OnInit { } + save_v2() { + this.injectValidation() + this.runValidation() + + if (this.Form.invalid) { + return false + } + this.showLoader = true; + this.agendaDataRepository.updateEvent(this._postEvent.EventId, this._postEvent,this._postEvent.CalendarName,this.loadedEventAttachments); + this.showLoader = false; + this.httpErrorHandle.httpsSucessMessagge('Editar evento') + + } async save() { diff --git a/src/app/shared/agenda/new-event/new-event.page.html b/src/app/shared/agenda/new-event/new-event.page.html index 166cf8a45..739299f43 100644 --- a/src/app/shared/agenda/new-event/new-event.page.html +++ b/src/app/shared/agenda/new-event/new-event.page.html @@ -418,7 +418,7 @@ - diff --git a/src/app/shared/agenda/new-event/new-event.page.ts b/src/app/shared/agenda/new-event/new-event.page.ts index 1405b6c7d..73876f171 100644 --- a/src/app/shared/agenda/new-event/new-event.page.ts +++ b/src/app/shared/agenda/new-event/new-event.page.ts @@ -8,7 +8,7 @@ import { ModalController } from '@ionic/angular'; import { removeDuplicate } from 'src/plugin/removeDuplicate.js' import { SearchPage } from 'src/app/pages/search/search.page'; import { SearchList } from "src/app/models/search-document"; -import { EventAttachment } from 'src/app/models/attachment.model'; +import { EventAttachment, EventAttachment_v2 } from 'src/app/models/attachment.model'; import { ToastService } from 'src/app/services/toast.service'; import { LoginUserRespose } from 'src/app/models/user.model'; @@ -37,6 +37,8 @@ import { TaskService } from 'src/app/services/task.service' import { ContactsService } from 'src/app/services/contacts.service'; import { DomSanitizerService } from 'src/app/services/DomSanitizer.service'; import { ChangeProfileService } from 'src/app/services/change-profile.service'; +import { EventInputDTO } from 'src/app/services/Repositorys/Agenda/agendaDataModels'; +import { AgendaDataRepositoryService } from 'src/app/services/Repositorys/Agenda/agenda-data-repository.service'; const CUSTOM_DATE_FORMATS: NgxMatDateFormats = { parse: { @@ -151,6 +153,7 @@ export class NewEventPage implements OnInit { private contactsService: ContactsService, private domSanitazerService: DomSanitizerService, private changeProfileService: ChangeProfileService, + private agendaDataRepository: AgendaDataRepositoryService ) { this.dateAdapter.setLocale('pt'); this.loggeduser = SessionStore.user; @@ -507,6 +510,28 @@ export class NewEventPage implements OnInit { } + save_v2() { + this.injectValidation() + this.runValidation() + + if (this.Form.invalid) { + + if (new Date(this.postEvent.StartDate).getTime() < new Date(this.postEvent.EndDate).getTime()) { + this.toastService._badRequest("Data de inicio menor que a data de fim") + } + + return false + } + let loader = this.toastService.loading(); + this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc); + this.postEvent.IsAllDayEvent = this.allDayCheck; + + this.agendaDataRepository.createEvent(this.postEvent,this.CalendarName,this.documents); + loader.remove(); + this.afterSave(); + this.hhtpErrorHandle.httpsSucessMessagge('new event') + } + async save() { this.injectValidation() diff --git a/src/app/shared/agenda/view-event/view-event.page.ts b/src/app/shared/agenda/view-event/view-event.page.ts index efbb05166..d2a126235 100644 --- a/src/app/shared/agenda/view-event/view-event.page.ts +++ b/src/app/shared/agenda/view-event/view-event.page.ts @@ -19,6 +19,7 @@ import { NavigationExtras, Router } from '@angular/router'; import { EventController } from 'src/app/controller/event' import { DateService } from 'src/app/services/date.service'; import { EventList } from 'src/app/models/agenda/AgendaEventList'; +import { AgendaDataRepositoryService } from 'src/app/services/Repositorys/Agenda/agenda-data-repository.service'; @Component({ selector: 'app-view-event', templateUrl: './view-event.page.html', @@ -65,7 +66,8 @@ export class ViewEventPage implements OnInit { public ThemeService: ThemeService, private httpErrorHandle: HttpErrorHandle, private router: Router, - private dateService: DateService + private dateService: DateService, + private agendaDataRepository: AgendaDataRepositoryService ) { this.isEventEdited = false; this.loadedEvent = new Event(); @@ -129,6 +131,7 @@ export class ViewEventPage implements OnInit { this.eventsService.getEvent(this.eventId).subscribe(res => { res = this.dateService.fixDate(res as any) + console.log('loaded event', res) this.loadedEvent = res; this.setTimeZone() @@ -181,7 +184,7 @@ export class ViewEventPage implements OnInit { { text: 'Sim', handler: () => { - this.deleteEvent(); + this.deleteEvent_v2(); } }, { @@ -195,6 +198,10 @@ export class ViewEventPage implements OnInit { }); } + deleteEvent_v2() { + this.agendaDataRepository.deleteEvent(this.loadedEvent.EventId) + } + async deleteEvent() { if (this.loadedEvent.IsRecurring) {