Skip to content

Commit

Permalink
feat: add order carriage number
Browse files Browse the repository at this point in the history
  • Loading branch information
stardustmeg committed Sep 3, 2024
1 parent b2a2280 commit ee2abb5
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 18 deletions.
6 changes: 4 additions & 2 deletions src/app/orders/components/order/order.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
Seat: <b>{{ order.seatNumber }}</b>
</div>
<div class="carriage-type">
Carriage type: <b>{{ order.carriage }}</b>
Carriage type: <b>{{ order.carriage?.carriageName }}</b>
</div>
<div class="carriage-type">
Carriage №: <b>{{ order.carriage?.carriageOrder }}</b>
</div>
// TBD: display carriage number
<div class="price">
Price: <b>{{ order.price | currency: 'USD' : 'symbol' : '1.0-0' }}</b>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/orders/components/order/order.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { Subscription } from 'rxjs';
import { User } from '@/app/api/models/order';
import { OrdersService } from '@/app/api/ordersService/orders.service';
import { ProfileService } from '@/app/api/profileService/profile.service';
import { UserOrder } from '@/app/orders/models/userOrder.model';
import POSITION_DIRECTION from '@/app/shared/directives/position/constants/position.constants';
import { UserOrder } from '@/app/shared/models/userOrder.model';
import { ModalService } from '@/app/shared/services/modal/modal.service';
import { USER_MESSAGE } from '@/app/shared/services/userMessage/constants/user-messages';
import { UserMessageService } from '@/app/shared/services/userMessage/user-message.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { PaginatorModule, PaginatorState } from 'primeng/paginator';

import { User } from '@/app/api/models/order';
import { OrdersService } from '@/app/api/ordersService/orders.service';
import { UserOrder } from '@/app/shared/models/userOrder.model';
import { UserOrderService } from '@/app/shared/services/data/userOrder/user-order.service';
import { UserOrder } from '@/app/orders/models/userOrder.model';

import { UserOrderService } from '../../services/userOrder/user-order.service';
import { OrderComponent } from '../order/order.component';

@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TrainCarriage } from '@/app/shared/models/trainCarriage.model';

export interface UserOrder {
orderId: number;
rideId: number;
Expand All @@ -11,6 +13,6 @@ export interface UserOrder {
tripEndStationId: number;
tripDepartureDate: string;
tripArrivalDate: string;
carriage: string;
carriage: TrainCarriage | null;
price: number;
}
2 changes: 1 addition & 1 deletion src/app/orders/pages/orders/orders.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { CarriageService } from '@/app/api/carriagesService/carriage.service';
import { OrdersService } from '@/app/api/ordersService/orders.service';
import { StationsService } from '@/app/api/stationsService/stations.service';
import { AuthService } from '@/app/auth/services/auth-service/auth.service';
import { UserOrderService } from '@/app/shared/services/data/userOrder/user-order.service';

import { OrdersListComponent } from '../../components/orders-list/orders-list.component';
import { UserOrderService } from '../../services/userOrder/user-order.service';

const imgUrl = '/img/png/no-results.webp';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { inject, Injectable, signal } from '@angular/core';

import { Order } from '@/app/api/models/order';
import { OrdersService } from '@/app/api/ordersService/orders.service';
import { UserOrder } from '@/app/shared/models/userOrder.model';

import { TripCarriagesService } from '../tripCarriages/trip-carriages.service';
import { TripDatesService } from '../tripDates/trip-dates.service';
import { TripPriceService } from '../tripPrice/trip-price.service';
import { TripStationsService } from '../tripStations/trip-stations.service';
import { UserOrder } from '@/app/orders/models/userOrder.model';
import { TripCarriagesService } from '@/app/shared/services/data/tripCarriages/trip-carriages.service';
import { TripDatesService } from '@/app/shared/services/data/tripDates/trip-dates.service';
import { TripPriceService } from '@/app/shared/services/data/tripPrice/trip-price.service';
import { TripStationsService } from '@/app/shared/services/data/tripStations/trip-stations.service';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -48,11 +47,10 @@ export class UserOrderService {
);
const freeSeatsMap = this.tripCarriagesService.calculateFreeSeats(trainCarriages);
const carriageInfo = this.tripCarriagesService.createCarriageInfo(carriages, aggregatedPriceMap, freeSeatsMap);
const carriage = this.tripCarriagesService.findUserCarriage(seatId, trainCarriages) ?? '';
const price = this.tripPriceService.getCarriagePrice(carriage, carriageInfo);
const carriage = this.tripCarriagesService.findCarriageBySeat(seatId, trainCarriages) ?? null;
const price = this.tripPriceService.getCarriagePrice(carriage!.carriageName, carriageInfo);
return {
orderId: id,

rideId,
routeId,
seatNumber: seatId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CarriageInfo } from '@/app/shared/models/carriageInfo.model';
import { CarriageNameMap } from '@/app/shared/models/carriageNameMap.model';
import { FreeSeatsMap } from '@/app/shared/models/freeSeatsMap.model';
import { PriceMap } from '@/app/shared/models/priceMap.model';
import { TrainCarriage } from '@/app/shared/models/trainCarriage.model';
import { TrainCarriages } from '@/app/shared/models/trainCarriages.model';
import { TripIndices } from '@/app/shared/models/tripIndices.model';

Expand Down Expand Up @@ -136,10 +137,10 @@ export class TripCarriagesService {
return freeSeatsMap;
}

public findUserCarriage(seatNumber: number, trainCarriages: TrainCarriages): string {
public findCarriageBySeat(seatNumber: number, trainCarriages: TrainCarriages): TrainCarriage | null {
const carriage = Object.values(trainCarriages).find(
(crg) => seatNumber >= crg.firstSeat && seatNumber <= crg.lastSeat,
);
return carriage ? carriage.carriageName : '';
return carriage || null;
}
}

1 comment on commit ee2abb5

@stardustmeg
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.