From 433a8893d474d359ec08d6c11b362e0c9d1c9863 Mon Sep 17 00:00:00 2001 From: Berend Wouters Date: Fri, 7 Apr 2023 23:23:43 +0200 Subject: [PATCH 1/4] fix: Format datetime as timezone json notation --- Singer.API/ClientApp/package-lock.json | 4 +- Singer.API/ClientApp/package.json | 2 +- Singer.API/ClientApp/src/app/app.module.ts | 9 +- .../src/app/modules/admin/admin.module.ts | 102 +++++++++--------- .../singerevent-overview.component.ts | 18 ++-- .../core/DTOs/event-registration.dto.ts | 9 +- .../src/app/modules/core/core.module.ts | 19 ++-- .../singerevents-api/singerevents.service.ts | 36 ++++--- .../app/modules/dashboard/dashboard.module.ts | 4 + .../src/app/modules/login/login.module.ts | 1 - .../src/app/modules/shared/shared.module.ts | 76 ++++++------- 11 files changed, 142 insertions(+), 138 deletions(-) diff --git a/Singer.API/ClientApp/package-lock.json b/Singer.API/ClientApp/package-lock.json index e97803d87..125280caa 100644 --- a/Singer.API/ClientApp/package-lock.json +++ b/Singer.API/ClientApp/package-lock.json @@ -1,12 +1,12 @@ { "name": "Singer", - "version": "0.1.0-PullRequest0237.1582", + "version": "0.1.0-issue-fix-date-time.1583", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "Singer", - "version": "0.1.0-PullRequest0237.1582", + "version": "0.1.0-issue-fix-date-time.1583", "hasInstallScript": true, "dependencies": { "@angular/animations": "^14.3.0", diff --git a/Singer.API/ClientApp/package.json b/Singer.API/ClientApp/package.json index 03d626a37..e48156ab4 100644 --- a/Singer.API/ClientApp/package.json +++ b/Singer.API/ClientApp/package.json @@ -1,6 +1,6 @@ { "name": "Singer", - "version": "0.1.0-PullRequest0237.1582", + "version": "0.1.0-issue-fix-date-time.1583", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/Singer.API/ClientApp/src/app/app.module.ts b/Singer.API/ClientApp/src/app/app.module.ts index 8da46ecf7..3556cb0b3 100644 --- a/Singer.API/ClientApp/src/app/app.module.ts +++ b/Singer.API/ClientApp/src/app/app.module.ts @@ -13,14 +13,14 @@ import { AuthService } from './modules/core/services/auth.service'; import { AuthGuard } from './modules/core/services/auth.guard'; import { AuthInterceptor } from './modules/core/services/auth-interceptor'; import { NavMenuComponent } from './modules/core/components/nav-menu/nav-menu.component'; -import { NativeDateModule, MAT_DATE_LOCALE, DateAdapter, MAT_DATE_FORMATS } from '@angular/material/core'; +import { NativeDateModule, MAT_DATE_LOCALE, MAT_DATE_FORMATS } from '@angular/material/core'; import { AdminModule } from './modules/admin/admin.module'; -import { MomentDateAdapter } from '@angular/material-moment-adapter'; import { ConfigurationService } from './modules/core/services/clientconfiguration.service'; import { ApplicationInsightsService } from './modules/core/services/applicationinsights.service'; import { registerLocaleData } from '@angular/common'; import localeBe from '@angular/common/locales/be'; -import { CalendarModule } from 'angular-calendar'; +import { OWL_DATE_TIME_LOCALE, OwlDateTimeIntl } from '@danielmoncada/angular-datetime-picker'; +import { DutchOwlDateTimeIntl } from './modules/legalguardians/dutchowldatetime'; // Import locale settings for Belgium registerLocaleData(localeBe); @@ -74,7 +74,8 @@ export const MY_FORMATS = { BrowserAnimationsModule, { provide: MAT_DATE_LOCALE, useValue: 'nl-BE' }, { provide: MAT_DATE_FORMATS, useValue: MY_FORMATS }, - { provide: DateAdapter, useClass: MomentDateAdapter }, + { provide: OWL_DATE_TIME_LOCALE, useValue: 'nl-BE' }, + { provide: OwlDateTimeIntl, useClass: DutchOwlDateTimeIntl }, // AppInsightsService, ], bootstrap: [AppComponent], diff --git a/Singer.API/ClientApp/src/app/modules/admin/admin.module.ts b/Singer.API/ClientApp/src/app/modules/admin/admin.module.ts index 74b4f7907..21f66d3a5 100644 --- a/Singer.API/ClientApp/src/app/modules/admin/admin.module.ts +++ b/Singer.API/ClientApp/src/app/modules/admin/admin.module.ts @@ -11,7 +11,7 @@ import { CoreModule } from '../core/core.module'; import { CareUserDetailsComponent } from './components/careusers/careuser-details/care-user-details.component'; import { ReactiveFormsModule, FormsModule } from '@angular/forms'; import { KeysPipe } from '../core/pipes/keys.pipe'; -import { MAT_DATE_LOCALE } from '@angular/material/core'; +import { MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material/core'; import { MatPaginatorModule } from '@angular/material/paginator'; import { MatSortModule } from '@angular/material/sort'; import { MatTableModule } from '@angular/material/table'; @@ -39,59 +39,55 @@ import { PendingActionsComponent } from './components/pending-actions/pending-ac import { LocationOverviewComponent } from './components/location-overview/location-overview.component'; import { LocationDetailsComponent } from './components/location-details/location-details.component'; import { SingerLocationProxy } from '../core/services/singer-location-api/singer-location.proxy'; +import { OWL_DATE_TIME_LOCALE, OwlDateTimeIntl } from '@danielmoncada/angular-datetime-picker'; +import { MY_FORMATS } from 'src/app/app.module'; +import { DutchOwlDateTimeIntl } from '../legalguardians/dutchowldatetime'; @NgModule({ - declarations: [ - CareUserOverviewComponent, - CareUserDetailsComponent, - LegalguardianOverviewComponent, - LegalguardianDetailsComponent, - SingerEventOverviewComponent, - SingerEventDetailsComponent, - AdminOverviewComponent, - AdminDetailsComponent, - SingerRegistrationsComponent, - SingerEventAdminRegisterComponent, - AddFamilyWizardComponent, - PendingRegistrationsComponent, - PendingActionsComponent, - LocationOverviewComponent, - LocationDetailsComponent, - ], - imports: [ - CoreModule, - CommonModule, - SharedModule, - AdminRoutingModule, - MaterialModule, - ReactiveFormsModule, - FormsModule, - MatMomentDateModule, - MatTableModule, - MatPaginatorModule, - MatSortModule, - ], - providers: [ - CareUserProxy, - LegalGuardianProxy, - SingerEventsProxy, - SingerLocationProxy, - CareUserService, - AdminUserProxy, - AdminUserService, - LegalguardiansService, - SingerEventsService, - SingerLocationService, - ApiService, - AgegroupPipe, - KeysPipe, - { - provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, - useValue: { - useUtc: true, - }, - }, - { provide: MAT_DATE_LOCALE, useValue: 'nl-BE' }, - ] + declarations: [ + CareUserOverviewComponent, + CareUserDetailsComponent, + LegalguardianOverviewComponent, + LegalguardianDetailsComponent, + SingerEventOverviewComponent, + SingerEventDetailsComponent, + AdminOverviewComponent, + AdminDetailsComponent, + SingerRegistrationsComponent, + SingerEventAdminRegisterComponent, + AddFamilyWizardComponent, + PendingRegistrationsComponent, + PendingActionsComponent, + LocationOverviewComponent, + LocationDetailsComponent, + ], + imports: [ + CoreModule, + CommonModule, + SharedModule, + AdminRoutingModule, + MaterialModule, + ReactiveFormsModule, + FormsModule, + MatMomentDateModule, + MatTableModule, + MatPaginatorModule, + MatSortModule, + ], + providers: [ + CareUserProxy, + LegalGuardianProxy, + SingerEventsProxy, + SingerLocationProxy, + CareUserService, + AdminUserProxy, + AdminUserService, + LegalguardiansService, + SingerEventsService, + SingerLocationService, + ApiService, + AgegroupPipe, + KeysPipe, + ], }) export class AdminModule {} diff --git a/Singer.API/ClientApp/src/app/modules/admin/components/singerevents/singerevent-overview/singerevent-overview.component.ts b/Singer.API/ClientApp/src/app/modules/admin/components/singerevents/singerevent-overview/singerevent-overview.component.ts index d2d44fe22..c184a0030 100644 --- a/Singer.API/ClientApp/src/app/modules/admin/components/singerevents/singerevent-overview/singerevent-overview.component.ts +++ b/Singer.API/ClientApp/src/app/modules/admin/components/singerevents/singerevent-overview/singerevent-overview.component.ts @@ -75,7 +75,7 @@ export class SingerEventOverviewComponent implements OnInit, AfterViewInit { ngOnInit() { this.dataSource = new SingerEventOverviewDataSource(this._singerEventsService); - this._singerLocationService.fetchSingerLocationsData('asc', 'name', 0, 1000, '').subscribe(res => { + this._singerLocationService.fetchSingerLocationsData('asc', 'name', 0, 1000, '').subscribe((res) => { this.availableLocations = res.items as SingerLocation[]; }); this.sort.active = 'title'; @@ -104,7 +104,7 @@ export class SingerEventOverviewComponent implements OnInit, AfterViewInit { }) ) .subscribe(); - this.dataSource.loading$.subscribe(res => { + this.dataSource.loading$.subscribe((res) => { if (res) { this._loadingService.show(); } else { @@ -121,7 +121,7 @@ export class SingerEventOverviewComponent implements OnInit, AfterViewInit { } isMaxRegistrantsExceeded(row: SingerEvent): boolean { - return row.eventSlots.some(x => x.currentRegistrants > row.maxRegistrants); + return row.eventSlots.some((x) => x.currentRegistrants > row.maxRegistrants); } getRegistrantsNumberString(row: SingerEvent): string { @@ -158,12 +158,13 @@ export class SingerEventOverviewComponent implements OnInit, AfterViewInit { }); dialogRef.componentInstance.submitEvent.subscribe((result: SingerEvent) => { + console.log(result); this._singerEventsService.create(result).subscribe( () => { this.loadSingerEvents(); this._snackBar.open(`Evenement ${result.title} werd toegevoegd.`, 'OK', { duration: 2000 }); }, - err => { + (err) => { this.handleApiError(err); } ); @@ -180,14 +181,15 @@ export class SingerEventOverviewComponent implements OnInit, AfterViewInit { }); dialogRef.componentInstance.submitEvent.subscribe((result: SingerEvent) => { + console.log(result); // Update the SingerEvent - this._singerEventsService.update(result).subscribe( + this._singerEventsService.updateSingerEvent(result).subscribe( () => { // Reload SingerEvents this.loadSingerEvents(); this._snackBar.open(`Evenement ${result.title} werd aangepast.`, 'OK', { duration: 2000 }); }, - err => { + (err) => { this.handleApiError(err); // TODO: Should be optimised, reloading results should be necessary this.loadSingerEvents(); @@ -197,12 +199,12 @@ export class SingerEventOverviewComponent implements OnInit, AfterViewInit { dialogRef.componentInstance.deleteEvent.subscribe((result: SingerEvent) => { this._singerEventsService.deleteSingerEvent(result.id).subscribe( - res => { + (res) => { // Reload SingerEvents this.loadSingerEvents(); this._snackBar.open(`Evenement ${result.title} werd verwijderd.`, 'OK', { duration: 2000 }); }, - err => { + (err) => { this.handleApiError(err); // TODO: Should be optimised, reloading results should be necessary this.loadSingerEvents(); diff --git a/Singer.API/ClientApp/src/app/modules/core/DTOs/event-registration.dto.ts b/Singer.API/ClientApp/src/app/modules/core/DTOs/event-registration.dto.ts index d11b509fb..c5e7f225e 100644 --- a/Singer.API/ClientApp/src/app/modules/core/DTOs/event-registration.dto.ts +++ b/Singer.API/ClientApp/src/app/modules/core/DTOs/event-registration.dto.ts @@ -3,6 +3,7 @@ import { EventSlotDTO } from '../models/eventslot.dto'; import { SingerLocationDTO } from './singer-event-location.dto'; import { DaycareLocationDTO } from './daycarelocation.dto'; import { IFilterBaseDTO } from './filterbase.dto'; +import format from 'date-fns/format'; export interface CreateEventSlotRegistrationDTO { eventSlotId: string; @@ -107,8 +108,8 @@ export interface UpdateSingerEventDTO { locationId: string; maxRegistrants: number; cost: number; - startDateTime: Date; - endDateTime: Date; + startDateTime: string; + endDateTime: string; startRegistrationDateTime: Date; endRegistrationDateTime: Date; finalCancellationDateTime: Date; @@ -126,8 +127,8 @@ export interface CreateSingerEventDTO { locationId: string; maxRegistrants: number; cost: number; - startDateTime: Date; - endDateTime: Date; + startDateTime: string; + endDateTime: string; startRegistrationDateTime: Date; endRegistrationDateTime: Date; finalCancellationDateTime: Date; diff --git a/Singer.API/ClientApp/src/app/modules/core/core.module.ts b/Singer.API/ClientApp/src/app/modules/core/core.module.ts index fec0353c7..ef5cb6119 100644 --- a/Singer.API/ClientApp/src/app/modules/core/core.module.ts +++ b/Singer.API/ClientApp/src/app/modules/core/core.module.ts @@ -14,7 +14,10 @@ import { AboutComponent } from './components/about/about.component'; import { RegistrationTypePipe } from './pipes/registration-type.pipe'; import { TitlePipe } from './pipes/title.pipe'; import { MAT_MOMENT_DATE_ADAPTER_OPTIONS } from '@angular/material-moment-adapter'; -import { MAT_DATE_LOCALE } from '@angular/material/core'; +import { MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material/core'; +import { OWL_DATE_TIME_LOCALE, OwlDateTimeIntl } from '@danielmoncada/angular-datetime-picker'; +import { MY_FORMATS } from 'src/app/app.module'; +import { DutchOwlDateTimeIntl } from '../legalguardians/dutchowldatetime'; @NgModule({ declarations: [ @@ -42,17 +45,9 @@ import { MAT_DATE_LOCALE } from '@angular/material/core'; SingereventCostPipe, AboutComponent, RegistrationTypePipe, - TitlePipe + TitlePipe, ], - providers: [ - RegistrationTypePipe, - { - provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, - useValue: { - useUtc: true, - }, - }, - { provide: MAT_DATE_LOCALE, useValue: 'nl-BE' },] + providers: [RegistrationTypePipe], }) -export class CoreModule { } +export class CoreModule {} diff --git a/Singer.API/ClientApp/src/app/modules/core/services/singerevents-api/singerevents.service.ts b/Singer.API/ClientApp/src/app/modules/core/services/singerevents-api/singerevents.service.ts index 726fc5153..a77c08a65 100644 --- a/Singer.API/ClientApp/src/app/modules/core/services/singerevents-api/singerevents.service.ts +++ b/Singer.API/ClientApp/src/app/modules/core/services/singerevents-api/singerevents.service.ts @@ -18,6 +18,7 @@ import { GenericService } from '../generic-service'; import { HttpClient } from '@angular/common/http'; import { EventSlot } from '../../models/eventslot'; import { RegistrationDTO, CreateRegistrationDTO } from '../../DTOs/registration.dto'; +import * as moment from 'moment'; @Injectable({ providedIn: 'root', @@ -42,8 +43,8 @@ export class SingerEventsService extends GenericService< endRegistrationDateTime: model.endRegistrationDateTime, finalCancellationDateTime: model.finalCancellationDateTime, registrationOnDailyBasis: model.registrationOnDailyBasis, - startDateTime: model.startDateTime, - endDateTime: model.endDateTime, + startDateTime: moment(model.startDateTime).format(), + endDateTime: moment(model.endDateTime).format(), hasDayCareBefore: model.hasDayCareBefore, dayCareBeforeStartDateTime: model.dayCareBeforeStartDateTime, hasDayCareAfter: model.hasDayCareAfter, @@ -65,8 +66,8 @@ export class SingerEventsService extends GenericService< endRegistrationDateTime: model.endRegistrationDateTime, finalCancellationDateTime: model.finalCancellationDateTime, registrationOnDailyBasis: model.registrationOnDailyBasis, - startDateTime: model.startDateTime, - endDateTime: endDateTime, + startDateTime: moment(model.startDateTime).format(), + endDateTime: moment(endDateTime).format(), hasDayCareBefore: model.hasDayCareBefore, dayCareBeforeStartDateTime: model.dayCareBeforeStartDateTime, hasDayCareAfter: model.hasDayCareAfter, @@ -89,7 +90,7 @@ export class SingerEventsService extends GenericService< description: dto.description, endDateTime: dto.endDateTime, endRegistrationDateTime: dto.endRegistrationDateTime, - eventSlots: dto.eventSlots.map(x => { + eventSlots: dto.eventSlots.map((x) => { return { currentRegistrants: x.currentRegistrants, endDateTime: x.endDateTime, @@ -123,7 +124,7 @@ export class SingerEventsService extends GenericService< ): Observable> { return this.singerEventsProxy .getSingerEvents(sortDirection, sortColumn, pageIndex, pageSize, filter) - .pipe(map(res => res)); + .pipe(map((res) => res)); } updateSingerEvent(updateSingerEvent: SingerEvent) { @@ -139,16 +140,17 @@ export class SingerEventsService extends GenericService< endRegistrationDateTime: updateSingerEvent.endRegistrationDateTime, finalCancellationDateTime: updateSingerEvent.finalCancellationDateTime, registrationOnDailyBasis: updateSingerEvent.registrationOnDailyBasis, - startDateTime: updateSingerEvent.startDateTime, - endDateTime: updateSingerEvent.endDateTime, + startDateTime: moment(updateSingerEvent.startDateTime).format(), + endDateTime: moment(updateSingerEvent.endDateTime).format(), hasDayCareBefore: updateSingerEvent.hasDayCareBefore, dayCareBeforeStartDateTime: updateSingerEvent.dayCareBeforeStartDateTime, hasDayCareAfter: updateSingerEvent.hasDayCareAfter, dayCareAfterEndDateTime: updateSingerEvent.dayCareAfterEndDateTime, }; + console.log(updateSingerEventDTO); return this.singerEventsProxy .updateSingerEvents(updateSingerEventDTO.id, updateSingerEventDTO) - .pipe(map(res => res)); + .pipe(map((res) => res)); } createSingerEvent(createSingerEvent: SingerEvent) { @@ -166,8 +168,8 @@ export class SingerEventsService extends GenericService< endRegistrationDateTime: createSingerEvent.endRegistrationDateTime, finalCancellationDateTime: createSingerEvent.finalCancellationDateTime, registrationOnDailyBasis: createSingerEvent.registrationOnDailyBasis, - startDateTime: createSingerEvent.startDateTime, - endDateTime: endDateTime, + startDateTime: moment(createSingerEvent.startDateTime).format(), + endDateTime: moment(endDateTime).format(), hasDayCareBefore: createSingerEvent.hasDayCareBefore, dayCareBeforeStartDateTime: createSingerEvent.dayCareBeforeStartDateTime, hasDayCareAfter: createSingerEvent.hasDayCareAfter, @@ -180,11 +182,11 @@ export class SingerEventsService extends GenericService< stopRepeatDate: createSingerEvent.endDateTime, }, }; - return this.singerEventsProxy.createSingerEvents(createSingerEventDTO).pipe(map(res => res)); + return this.singerEventsProxy.createSingerEvents(createSingerEventDTO).pipe(map((res) => res)); } deleteSingerEvent(eventId: string) { - return this.singerEventsProxy.deleteSingerEvent(eventId).pipe(map(res => res)); + return this.singerEventsProxy.deleteSingerEvent(eventId).pipe(map((res) => res)); } getEventRegisterDetails(eventId: string) { @@ -201,7 +203,7 @@ export class SingerEventsService extends GenericService< ): Observable { return this.singerEventsProxy .getRegistrations(eventId, sortDirection, sortColumn, pageIndex, pageSize, filter) - .pipe(map(res => res.items)); + .pipe(map((res) => res.items)); } registerCareUserOnEvent(eventId: string, careUserId: string) { @@ -221,13 +223,13 @@ export class SingerEventsService extends GenericService< } isUserRegisteredForEvent(eventId: string, careUserId: string): Observable { - return this.singerEventsProxy.isUserRegisteredForEvent(eventId, careUserId).pipe(map(res => res)); + return this.singerEventsProxy.isUserRegisteredForEvent(eventId, careUserId).pipe(map((res) => res)); } getPublicEvents(eventFilterData: EventFilterParameters): Observable { return this.singerEventsProxy.getPublicEvents(eventFilterData).pipe( - map(res => - res.map(y => { + map((res) => + res.map((y) => { return { id: y.id, title: y.title, diff --git a/Singer.API/ClientApp/src/app/modules/dashboard/dashboard.module.ts b/Singer.API/ClientApp/src/app/modules/dashboard/dashboard.module.ts index 390a0b32e..d922603e5 100644 --- a/Singer.API/ClientApp/src/app/modules/dashboard/dashboard.module.ts +++ b/Singer.API/ClientApp/src/app/modules/dashboard/dashboard.module.ts @@ -14,6 +14,10 @@ import { ApiService } from '../core/services/api.service'; import { SharedModule } from '../shared/shared.module'; import { AdminMenuComponent } from './components/admin-menu/admin-menu.component'; import { RegistrationOverviewComponent } from './components/registration-overview/registration-overview.component'; +import { DutchOwlDateTimeIntl } from '../legalguardians/dutchowldatetime'; +import { MAT_DATE_LOCALE, MAT_DATE_FORMATS } from '@angular/material/core'; +import { OWL_DATE_TIME_LOCALE, OwlDateTimeIntl } from '@danielmoncada/angular-datetime-picker'; +import { MY_FORMATS } from 'src/app/app.module'; @NgModule({ declarations: [ diff --git a/Singer.API/ClientApp/src/app/modules/login/login.module.ts b/Singer.API/ClientApp/src/app/modules/login/login.module.ts index 743c0fbb3..d7529b7b1 100644 --- a/Singer.API/ClientApp/src/app/modules/login/login.module.ts +++ b/Singer.API/ClientApp/src/app/modules/login/login.module.ts @@ -2,7 +2,6 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { RouterModule, Routes } from '@angular/router'; import { AuthComponent } from './components/auth/auth.component'; -import { AuthService } from '../core/services/auth.service'; import { MaterialModule } from 'src/app/material.module'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { ResetPasswordComponent } from './components/reset-password/reset-password.component'; diff --git a/Singer.API/ClientApp/src/app/modules/shared/shared.module.ts b/Singer.API/ClientApp/src/app/modules/shared/shared.module.ts index 45869dad2..3380655e9 100644 --- a/Singer.API/ClientApp/src/app/modules/shared/shared.module.ts +++ b/Singer.API/ClientApp/src/app/modules/shared/shared.module.ts @@ -21,43 +21,47 @@ import { AccountInfoPageComponent } from './components/account-info/account-info import { CareUserMultiAutocompleteComponent } from './components/care-user-multi-autocomplete/care-user-multi-autocomplete.component'; import { RegistrationStatusToggleComponent } from './components/registration-status-toggle/registration-status-toggle.component'; import { RegistrationStatusComponent } from './components/registration-status/registration-status.component'; +import { MAT_DATE_LOCALE, MAT_DATE_FORMATS } from '@angular/material/core'; +import { OWL_DATE_TIME_LOCALE, OwlDateTimeIntl } from '@danielmoncada/angular-datetime-picker'; +import { MY_FORMATS } from 'src/app/app.module'; +import { DutchOwlDateTimeIntl } from '../legalguardians/dutchowldatetime'; @NgModule({ - declarations: [ - RegistrationComponent, - UserCardComponent, - DetailedUserCardComponent, - LoadingComponent, - EventTimelineComponent, - ConfirmComponent, - DeleteConfirmationComponent, - DeleteConfirmationDialogComponent, - CareUserSearchComponent, - AccountInfoSummaryComponent, - AccountInfoPageComponent, - AccountInfoCareusersListComponent, - CareUserMultiAutocompleteComponent, - RegistrationStatusToggleComponent, - RegistrationStatusComponent, - ], - imports: [CommonModule, MaterialModule, CoreModule, ReactiveFormsModule], - exports: [ - RegistrationComponent, - UserCardComponent, - DetailedUserCardComponent, - LoadingComponent, - EventTimelineComponent, - ConfirmComponent, - DeleteConfirmationComponent, - DeleteConfirmationDialogComponent, - CareUserSearchComponent, - AccountInfoSummaryComponent, - AccountInfoPageComponent, - AccountInfoCareusersListComponent, - CareUserMultiAutocompleteComponent, - RegistrationStatusToggleComponent, - RegistrationStatusComponent, - ], - providers: [ApiService, SingerEventsService, SingerEventsProxy] + declarations: [ + RegistrationComponent, + UserCardComponent, + DetailedUserCardComponent, + LoadingComponent, + EventTimelineComponent, + ConfirmComponent, + DeleteConfirmationComponent, + DeleteConfirmationDialogComponent, + CareUserSearchComponent, + AccountInfoSummaryComponent, + AccountInfoPageComponent, + AccountInfoCareusersListComponent, + CareUserMultiAutocompleteComponent, + RegistrationStatusToggleComponent, + RegistrationStatusComponent, + ], + imports: [CommonModule, MaterialModule, CoreModule, ReactiveFormsModule], + exports: [ + RegistrationComponent, + UserCardComponent, + DetailedUserCardComponent, + LoadingComponent, + EventTimelineComponent, + ConfirmComponent, + DeleteConfirmationComponent, + DeleteConfirmationDialogComponent, + CareUserSearchComponent, + AccountInfoSummaryComponent, + AccountInfoPageComponent, + AccountInfoCareusersListComponent, + CareUserMultiAutocompleteComponent, + RegistrationStatusToggleComponent, + RegistrationStatusComponent, + ], + providers: [ApiService, SingerEventsService, SingerEventsProxy], }) export class SharedModule {} From 2741eb89f3f5aba090937acaef97e7cce3852e9d Mon Sep 17 00:00:00 2001 From: Berend Wouters Date: Fri, 7 Apr 2023 23:26:10 +0200 Subject: [PATCH 2/4] fix: Recreate event slots when updating event --- Singer.API/Services/EventService.cs | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Singer.API/Services/EventService.cs b/Singer.API/Services/EventService.cs index 73f46adf0..c22f2713d 100644 --- a/Singer.API/Services/EventService.cs +++ b/Singer.API/Services/EventService.cs @@ -35,6 +35,43 @@ public EventService(ApplicationDbContext context, IMapper mapper) : base(context .Include(x => x.EventSlots); + public override async Task UpdateAsync(Guid id, UpdateEventDTO newValue) + { + if (newValue == null) + throw new BadInputException("The value to create cannot be null", ErrorMessages.NoDataPassed); + + var singerEvent = await Context.Events + .Include(x => x.EventSlots) + .SingleOrDefaultAsync(x => x.Id == id); + if (singerEvent == null) + { + throw new BadInputException($"No event found with id {id}", ErrorMessages.NotFoundError); + } + // add slots for all the days in the event + UpdateEventSlots(singerEvent, newValue); + await Context.SaveChangesAsync(); + + var returnEntity = await GetOneAsync(singerEvent.Id).ConfigureAwait(false); + + // return the new updated entity + return returnEntity; + } + + private void UpdateEventSlots(Event singerEvent, UpdateEventDTO newValue) + { + // Updating event slots doesn't take repeatsettings into account, so only "GenerateEventSlotsUntilIncluding" is used + // This is the only supported implementation in the frontend right now, so it's not really an issues + var numberOfEventSlots = + EventSlot.GenerateEventSlotsUntilIncluding( + newValue.StartDateTime, + newValue.EndDateTime, + newValue.EndDateTime, // Hardcoded values since the other values aren't used in the frontend either + TimeUnit.Day); // Hardcoded values since the other values aren't used in the frontend either + singerEvent.EventSlots.Clear(); + + singerEvent.EventSlots = numberOfEventSlots.ToList(); + } + public override async Task CreateAsync(CreateEventDTO dto) { if (dto == null) From 0cd384daf820a82aa1ff8134c0986ce10fe87400 Mon Sep 17 00:00:00 2001 From: Berend Wouters Date: Sat, 8 Apr 2023 00:19:50 +0200 Subject: [PATCH 3/4] fix: recreate event slots --- Singer.API/ClientApp/package-lock.json | 4 ++-- Singer.API/ClientApp/package.json | 2 +- .../Extensions/EntityFrameworkCoreExtensions.cs | 2 +- Singer.API/Models/Event.cs | 2 +- Singer.API/Services/EventService.cs | 13 +++++++------ Tests/ModelTests/EventSlotTests.cs | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Singer.API/ClientApp/package-lock.json b/Singer.API/ClientApp/package-lock.json index 125280caa..a50929a2b 100644 --- a/Singer.API/ClientApp/package-lock.json +++ b/Singer.API/ClientApp/package-lock.json @@ -1,12 +1,12 @@ { "name": "Singer", - "version": "0.1.0-issue-fix-date-time.1583", + "version": "0.1.0-issue-fix-date-time.1585", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "Singer", - "version": "0.1.0-issue-fix-date-time.1583", + "version": "0.1.0-issue-fix-date-time.1585", "hasInstallScript": true, "dependencies": { "@angular/animations": "^14.3.0", diff --git a/Singer.API/ClientApp/package.json b/Singer.API/ClientApp/package.json index e48156ab4..56c95f8dd 100644 --- a/Singer.API/ClientApp/package.json +++ b/Singer.API/ClientApp/package.json @@ -1,6 +1,6 @@ { "name": "Singer", - "version": "0.1.0-issue-fix-date-time.1583", + "version": "0.1.0-issue-fix-date-time.1585", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/Singer.API/Helpers/Extensions/EntityFrameworkCoreExtensions.cs b/Singer.API/Helpers/Extensions/EntityFrameworkCoreExtensions.cs index 7f49aad55..f689a5452 100644 --- a/Singer.API/Helpers/Extensions/EntityFrameworkCoreExtensions.cs +++ b/Singer.API/Helpers/Extensions/EntityFrameworkCoreExtensions.cs @@ -25,7 +25,7 @@ public static WebApplicationBuilder AddApplicationDbContext(this WebApplicationB } builder.Services.AddDbContext(options => - options.UseLazyLoadingProxies().UseSqlServer(connectionString, opt => opt.EnableRetryOnFailure())); + options.UseSqlServer(connectionString, opt => opt.EnableRetryOnFailure())); return builder; } diff --git a/Singer.API/Models/Event.cs b/Singer.API/Models/Event.cs index bef63a450..1795d842a 100644 --- a/Singer.API/Models/Event.cs +++ b/Singer.API/Models/Event.cs @@ -29,6 +29,6 @@ public Event() public DateTime DayCareBeforeStartDateTime { get; set; } public bool HasDayCareAfter { get; set; } public DateTime DayCareAfterEndDateTime { get; set; } - public virtual IList EventSlots { get; set; } + public IList EventSlots { get; set; } public bool IsArchived { get; set; } } diff --git a/Singer.API/Services/EventService.cs b/Singer.API/Services/EventService.cs index c22f2713d..35bc0d7f3 100644 --- a/Singer.API/Services/EventService.cs +++ b/Singer.API/Services/EventService.cs @@ -48,7 +48,10 @@ public override async Task UpdateAsync(Guid id, UpdateEventDTO newValu throw new BadInputException($"No event found with id {id}", ErrorMessages.NotFoundError); } // add slots for all the days in the event - UpdateEventSlots(singerEvent, newValue); + var updatedEventSlots = UpdateEventSlots(newValue); + Context.RemoveRange(singerEvent.EventSlots); + singerEvent.EventSlots = updatedEventSlots.ToList(); + Context.Update(singerEvent); await Context.SaveChangesAsync(); var returnEntity = await GetOneAsync(singerEvent.Id).ConfigureAwait(false); @@ -57,19 +60,17 @@ public override async Task UpdateAsync(Guid id, UpdateEventDTO newValu return returnEntity; } - private void UpdateEventSlots(Event singerEvent, UpdateEventDTO newValue) + private IEnumerable UpdateEventSlots(UpdateEventDTO newValue) { // Updating event slots doesn't take repeatsettings into account, so only "GenerateEventSlotsUntilIncluding" is used // This is the only supported implementation in the frontend right now, so it's not really an issues - var numberOfEventSlots = + var eventSlots = EventSlot.GenerateEventSlotsUntilIncluding( newValue.StartDateTime, newValue.EndDateTime, newValue.EndDateTime, // Hardcoded values since the other values aren't used in the frontend either TimeUnit.Day); // Hardcoded values since the other values aren't used in the frontend either - singerEvent.EventSlots.Clear(); - - singerEvent.EventSlots = numberOfEventSlots.ToList(); + return eventSlots; } public override async Task CreateAsync(CreateEventDTO dto) diff --git a/Tests/ModelTests/EventSlotTests.cs b/Tests/ModelTests/EventSlotTests.cs index e64263d16..2a39abce3 100644 --- a/Tests/ModelTests/EventSlotTests.cs +++ b/Tests/ModelTests/EventSlotTests.cs @@ -44,7 +44,7 @@ public void GenerateEventSlotsUntil() public void GenerateEventSlotsUntilFromMidnightToMidnight() { var start = DateTime.Parse("2018-12-31T00:00:00+00:00"); - var end = DateTime.Parse("2019-01-01T00:00:00+00:00"); + var end = DateTime.Parse("2019-01-15T00:00:00+00:00"); var until = DateTime.Parse("2019-01-15"); var slots = EventSlot.GenerateEventSlotsUntilIncluding(start, end, until, TimeUnit.Day).ToList(); From 10186e23d773ed3f307fba8a87661efafe401cc2 Mon Sep 17 00:00:00 2001 From: Berend Wouters Date: Sat, 8 Apr 2023 00:21:34 +0200 Subject: [PATCH 4/4] fix: recreate event slots --- Singer.API/ClientApp/package-lock.json | 4 ++-- Singer.API/ClientApp/package.json | 2 +- Tests/ModelTests/EventSlotTests.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Singer.API/ClientApp/package-lock.json b/Singer.API/ClientApp/package-lock.json index a50929a2b..9874e374f 100644 --- a/Singer.API/ClientApp/package-lock.json +++ b/Singer.API/ClientApp/package-lock.json @@ -1,12 +1,12 @@ { "name": "Singer", - "version": "0.1.0-issue-fix-date-time.1585", + "version": "0.1.0-issue-fix-date-time.1586", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "Singer", - "version": "0.1.0-issue-fix-date-time.1585", + "version": "0.1.0-issue-fix-date-time.1586", "hasInstallScript": true, "dependencies": { "@angular/animations": "^14.3.0", diff --git a/Singer.API/ClientApp/package.json b/Singer.API/ClientApp/package.json index 56c95f8dd..da0d2955d 100644 --- a/Singer.API/ClientApp/package.json +++ b/Singer.API/ClientApp/package.json @@ -1,6 +1,6 @@ { "name": "Singer", - "version": "0.1.0-issue-fix-date-time.1585", + "version": "0.1.0-issue-fix-date-time.1586", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/Tests/ModelTests/EventSlotTests.cs b/Tests/ModelTests/EventSlotTests.cs index 2a39abce3..e64263d16 100644 --- a/Tests/ModelTests/EventSlotTests.cs +++ b/Tests/ModelTests/EventSlotTests.cs @@ -44,7 +44,7 @@ public void GenerateEventSlotsUntil() public void GenerateEventSlotsUntilFromMidnightToMidnight() { var start = DateTime.Parse("2018-12-31T00:00:00+00:00"); - var end = DateTime.Parse("2019-01-15T00:00:00+00:00"); + var end = DateTime.Parse("2019-01-01T00:00:00+00:00"); var until = DateTime.Parse("2019-01-15"); var slots = EventSlot.GenerateEventSlotsUntilIncluding(start, end, until, TimeUnit.Day).ToList();