Skip to content

A Travel Agency ticketing system API. Realtime seats update using SSE, locking seat system using Redis and payment using Xendit

Notifications You must be signed in to change notification settings

NovqiGarrix/travel-ticketing-api

Repository files navigation

Description

A Travel Agency ticketing system API. Realtime seats update using SSE, locking seat system using Redis and payment using Xendit. All of the APIs are following the specification from OpenAPISpec.yml.

Usage Flow

How you might use the API:
Travel Ticketing API Usage Flow

Project setup

Xendit

We use Xendit as our payment gateway, that so, you need to create an account, a test one. You do not need to verify your documents, but you have to choose the type of business you're in in the registration process. Just choose whatever business you might involve in the future. After that create your API key here: https://dashboard.xendit.co/settings/developers#api-keys. Choose write permission for the first permission. Setup 2FA, and copy your secret key into the .env file See Environment Variables step. You also need the Webhook Token Verification. Copy it and put in .env file.

Install Dependencies

$ pnpm install

Setup database

Create a new database. Here we're using PostgreSQL. Setup env variables (check Environment Variables step). After that run:

$ pnpm dlx drizzle-kit migrate

After that we need to populate the database:

$ bun run seed/index.ts

Unfortunately, you need to install Bun in order to run this command. Bun is required because it can compiles TypeScript out of the box. Node.js, since v22 can also run TypeScript code, but by striping the types, in easy words, it did not compile the code. So, we have to deal with a bunch of build errors. See it yourself:

$ node --experimental-strip-types seed/index.ts

Environment Variables

Create .env file and fill out all the neccesary variables from .env.example.

! Not sponsored, but I love their product

In this project, we use Postgres as our primary database to store our travels, schedules, orders, etc.. and Redis to temporary lock a seat while waiting for payment. For testing and development, you can use Docker (I provided the docker compose file, you can run the services using docker compose start -d). But for production, you can use Neon or Supabase for Postgres, and for Redis, you can use Upstash. It's free btw, good for hobby/personal projects.

Again, I'm not sponsored, but I love their product

Redis Setup

Every locked seats in Redis has TTL expiration (which is 10 minutes). Since we're using SSE for realtime seats update, we need to inform the client the seats are unlocked (after the TTL expired). To do that, we need to set up our Redis to send events when a key is expired. Log in to your Redis using CLI and run this command:

CONFIG SET notify-keyspace-events Ex

Compile and run the project

# development
$ pnpm run start

# watch mode
$ pnpm run start:dev

# production mode
$ pnpm run start:prod

Run tests

You need to create a new database for testing. After that run these migrations command:

$ NODE_ENV=testing npx drizzle-kit migrate
$ NODE_ENV=testing bun run seed/index.ts
# unit tests
$ pnpm run test

# e2e tests
$ pnpm run test:e2e

# test coverage
$ pnpm run test:cov

License

Nest is MIT licensed.

About

A Travel Agency ticketing system API. Realtime seats update using SSE, locking seat system using Redis and payment using Xendit

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published