travelmarine-backend/src/reservations/reservations.service.ts

79 lines
1.5 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { ReservationItemDto } from './reservation-item.dto';
export interface Reservation extends ReservationItemDto {
id: number;
}
@Injectable()
export class ReservationsService {
private reservations: Reservation[] = [
{
id: 1,
yachtId: 1,
reservatorId: 1,
startUtc: 1733097600,
endUtc: 1733133600,
},
{
id: 2,
yachtId: 3,
reservatorId: 2,
startUtc: 1733212800,
endUtc: 1733436000,
},
{
id: 3,
yachtId: 5,
reservatorId: 1,
startUtc: 1733860800,
endUtc: 1734048000,
},
{
id: 4,
yachtId: 7,
reservatorId: 2,
startUtc: 1734216000,
endUtc: 1734472800,
},
{
id: 5,
yachtId: 9,
reservatorId: 1,
startUtc: 1734705600,
endUtc: 1734883200,
},
{
id: 6,
yachtId: 11,
reservatorId: 2,
startUtc: 1735113600,
endUtc: 1735336800,
},
];
private idCounter = 7;
createReservation(dto: ReservationItemDto): Reservation {
const reservation = {
id: this.idCounter++,
...dto,
};
this.reservations.push(reservation);
return reservation;
}
getReservationsByUserId(userId: number): Reservation[] {
return this.reservations.filter((r) => r.reservatorId === userId);
}
getReservationsByYachtId(yachtId: number): Reservation[] {
return this.reservations.filter((r) => r.yachtId === yachtId);
}
getAllReservations(): Reservation[] {
return this.reservations;
}
}