Skip to content

Cutshadows/itinerary-app

Repository files navigation

Nest Logo

Kevin McCallister Itinerary Node.js

NPM Version NPM Version

Description

TypeScript itinerary Kevin McCallister (Lost in Europe).

REST API

 (POST) api/itinerary
 (GET) api/itinerary/:id

Project setup

we init installing all dependencies of our project.

npm install

Compile and run the project

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Run tests

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Explanation

1 - I decided to manage the ticket list through strategies

 src/itinerary
 └── strategies
 ├── airplane.strategy.ts
 ├── boat.strategy.ts
 ├── bus.strategy.ts
 ├── train.strategy.ts
 ├── tram.strategy.ts
 └── transport-interface.strategy.ts

The excuse of use Strategies for this was

  • Clean separation of logic.
  • Easier maintenance and extensibility
  • Dynamic, flexible behavior.
  • Better testing and reuse.

In addition create a context that Is used in the separation of ticket to create the arrange list (sorted)

src/itinerary
├── itinerary.context.ts
curl --location 'localhost:3030/api/itinerary' \
--header 'Content-Type: application/json' \
--data '[
    {
        "from": "Ski Arlberg",
        "to": "St. Anton am Arlberg Bahnhof",
        "type": "other",
        "isOrigin": true
    },
    {
        "from": "Bologna Guglielmo Marconi Airport",
        "fligthNumber": "AF1229",
        "to": "Paris CDG Airport",
        "gate": 22,
        "seat": "10A",
        "type": "airplane",
        "observation": "Self-check-in luggage at counter"
    },
    {
        "from": "St. Anton am Arlberg Bahnhof",
        "to": "Innsbruck Hbf",
        "type": "train",
        "trainNumber": "RJX 765",
        "platform": "3",
        "seat": "17C"
    },
    {
        "from": "Innsbruck Hbf",
        "to": "Innsbruck Airport",
        "type": "tram",
        "tramNumber": "S5"
    },
    {
        "from": "Innsbruck Airport",
        "fligthNumber": "AA904",
        "to": "Venezia Airport",
        "gate": 10,
        "seat": "18A",
        "type": "airplane",
        "observation": "Self-check-in luggage at counter"
    },
    {
        "from": "Paris CDG Airport",
        "fligthNumber": "AF136",
        "to": "Chicago O'\''Hare",
        "gate": 32,
        "seat": "10A",
        "type": "airplane",
        "observation": "Luggage will transfer automatically from the last flight"
    },
    {
        "from": "Chicago O'\''Hare",
        "to": "last destination reached",
        "type": "other"
    }

]'

I added Factory because it can easily work between different strategies

Output Itinerary

{
    "id": "itinerary-5ad1b",
    "createdAt": "2025-05-08T20:56:16.454Z",
    "sortedList": [
        "Take taxi from Ski Arlberg to St. Anton am Arlberg Bahnhof.",
        "Board RJX 765, Platform 3 from St. Anton am Arlberg Bahnhof to Innsbruck Hbf.seat number 17C.",
        "Board S5, from Innsbruck Hbf to Innsbruck Airport.",
        "From Innsbruck Airport, board the flight undefined to Venezia Airport.From gate 10, seat 18A. Self-check-in luggage at counter.",
        "Take the transfer undefined, from Venezia Airport to Bologna Guglielmo Marconi Airport.",
        "From Bologna Guglielmo Marconi Airport, board the flight undefined to Paris CDG Airport.From gate 22, seat 10A. Self-check-in luggage at counter.",
        "From Paris CDG Airport, board the flight undefined to Chicago O'Hare.From gate 32, seat 10A. Luggage will transfer automatically from the last flight.",
        "Take taxi from Chicago O'Hare to last destination reached."
    ]
}

MongoDB

I decided to move forward through a document database like MongoDB because, I believe it's the best way to manage a dynamic @body ( ticketsDto) in my personal opinion. It could allow extensibility if we add a new ticket type with a different transportType. I configured with typeOrm

#//!bash
# configuration in app.module
 TypeOrmModule.forRoot({
      type: 'mongodb',
      username: process.env.MONGO_INITDB_ROOT_USERNAME,
      password: process.env.MONGO_INITDB_ROOT_PASSWORD,
      url: process.env.MONGO_URL,
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: true,
      database: process.env.MONGO_DATABASE,
    }),

#configuration in itinerary.module
imports: [TypeOrmModule.forFeature([Itinerary])],
# Ensure TypeOrmModule is properly imported

Test coverture

File                        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------------------------|---------|----------|---------|---------|-------------------
All files                   |   64.12 |    44.73 |    65.3 |   61.29 |

Stay in touch

License

Nest is MIT licensed.


About

itinerary-app looked up the route of the tickets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published