Skip to content

Commit

Permalink
refactor: rename week resevation types
Browse files Browse the repository at this point in the history
  • Loading branch information
FerranAD committed Dec 13, 2023
1 parent cc29f6b commit 175807f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {OccupationService} from '../../services/occupation/occupation.service';
import {of} from 'rxjs';
import {RefugeReservationService} from "../../services/reservations/refuge-reservation.service";
import {GetUserResponse} from "../../schemas/user/fetch/get-refuge-schema";
import {WeekReservations} from "../../schemas/reservations/reservation";

@Component({
selector: 'app-reservations-chart',
Expand All @@ -21,6 +22,8 @@ import {GetUserResponse} from "../../schemas/user/fetch/get-refuge-schema";
export class ReservationsChartComponent implements OnInit, AfterViewInit {
@Input({required: true}) refuge!: Refuge;
@ViewChild('verticalBarChart') verticalBarChart?: BarVerticalComponent;

chartReservations: WeekReservations = [];
testDate1 = new Date('2023-10-14');
testDate2 = new Date('2023-10-15');

Expand Down Expand Up @@ -87,7 +90,7 @@ export class ReservationsChartComponent implements OnInit, AfterViewInit {

this.reservationService.getWeekReservationsForRefuge(this.refuge.id, 0).subscribe({
next: (response) => {
console.log("correct" + response);
this.chartReservations = response;
},
error: (err) => {
console.log("error" + err);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {HttpErrorResponse} from '@angular/common/http';
import {isMatching} from 'ts-pattern';
import {ReservationsWeek, ReservationsWeekPattern} from './reservation';
import {WeekReservations, ReservationsWeekPattern} from './reservation';
import {P} from 'ts-pattern/dist';
import {ResourceErrors} from '../errors/resource';
import {ServerErrors} from '../errors/server';
Expand All @@ -9,7 +9,7 @@ import {getErrorFrom} from '../errors/all-errors';

export type CorrectGetWeekReservations = {
status: 'ok';
week: ReservationsWeek;
week: WeekReservations;
};

export const CorrectGetWeekReservationsPattern: P.Pattern<CorrectGetWeekReservations> =
Expand Down
6 changes: 3 additions & 3 deletions app/src/app/schemas/reservations/reservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export type ReservationWithId = Reservation & { id: string };

export type Reservations = ReservationWithId[];

export type ReservationsWeek = WeekReservation[];
export type WeekReservations = ChartReservation[];

export type WeekReservation = {
export type ChartReservation = {
night: Night;
count: number;
}

export const ReservationsWeekPattern: P.Pattern<WeekReservation> = {};
export const ReservationsWeekPattern: P.Pattern<ChartReservation> = {};

export const ReservationPattern: P.Pattern<Reservation> = {};
4 changes: 2 additions & 2 deletions app/src/app/services/reservations/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CorrectGetReservationsPattern,
GetReservations,
} from '../../schemas/reservations/get-reservations-refuge-user';
import {Reservations, ReservationsWeek} from '../../schemas/reservations/reservation';
import {Reservations, WeekReservations} from '../../schemas/reservations/reservation';
import { isMatching } from 'ts-pattern';
import {
CorrectGetWeekReservations,
Expand All @@ -26,7 +26,7 @@ export function toReservations(

export function toReservationsWeek(
getWeekReservations: Observable<GetWeekReservations>,
): Observable<ReservationsWeek> {
): Observable<WeekReservations> {
return getWeekReservations.pipe(
map((reservations) => {
if (isMatching(CorrectGetWeekReservationsPattern, reservations))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
of,
retry,
} from 'rxjs';
import {Reservations, ReservationsWeek, WeekReservation} from '../../schemas/reservations/reservation';
import {Reservations, WeekReservations, ChartReservation} from '../../schemas/reservations/reservation';
import {toReservations, toReservationsWeek} from './common';
import {
fromError as fromReservationsError,
Expand All @@ -35,7 +35,7 @@ export class RefugeReservationService {
getWeekReservationsForRefuge(
refugeId: string,
offset: number,
): Observable<ReservationsWeek> {
): Observable<WeekReservations> {
const today = new Date();
const night = nightFromDate(today)
return toReservationsWeek(
Expand All @@ -49,7 +49,7 @@ export class RefugeReservationService {
offset: number,
): Observable<GetWeekReservations> {
const uri = this.getUriForWeekRefugeAndNight(refugeId, night, offset);
return this.http.get<ReservationsWeek>(uri).pipe(
return this.http.get<WeekReservations>(uri).pipe(
map((reservations) => fromWeekReservationsResponse(reservations)),
catchError((err: HttpErrorResponse) => of(fromWeekReservationsError(err))),
retry(3),
Expand Down

0 comments on commit 175807f

Please sign in to comment.