-
Clone repository with command
git clone <alamat_repo>
-
Move to directory traveloka-ocr-api
cd traveloka-ocr-api
-
Install dependencies using command
npm install
-
Rename .env-example to .env
Make sure that .env has content like this:# server configuration (dev) HOST=localhost PORT=5000 # node-postgres configuration (prod) PGUSER= PGHOST= PGPASSWORD= PGDATABASE= PGPORT=5432 # JWT token ACCESS_TOKEN_KEY= REFRESH_TOKEN_KEY= ACCESS_TOKEN_AGE= # Google Auth CLIENT_ID= CLIENT_SECRET=
-
migrate to the db
npm run migrate up
-
Running the server
npm run start-dev
- Access & Refresh Token
- In terminal/cmd type
node
then enter - Type this code to generate token
require('crypto').randomBytes(64).toString('hex')
- Copy the output and paste to the .env->ACCESS_TOkEN
- Repeat the sintax above to generate the second token, copy output and paste to .env->REFRESH_TOKEN
- In terminal/cmd type
- Follow tutorial in this link :) LINK TUTORIAL
- Open the spreadshet
- Go to flights and airlines tab and download as .csv format files
- Open cmd as administrator (Run as Administrator)
- Login postgres as developer
- type this code to copy dataset on the table airlines
\copy table_name from '~address local storage.csv~' with (DELIMITER ',', FORMAT CSV, HEADER)
example :\copy airlines from 'D:\Project\Bangkit\dataset\airlines.csv' with (DELIMITER ',', FORMAT CSV, HEADER)
- Do the same on the table flights
---- Manual (Use JWT) ----
-
Register
- method:
POST
- endpoint:
/users
- body request:
"name": string | required "email": string, email, unique | required "password": string | required "foto_profil": img | nullable
- body response:
"status": "success", "message": "user added successfully", "data": { "user_id": "users-randomidstring" }
- method:
-
Login
- method:
POST
, - endpoint:
/authentications
- body request:
"email": string, email | required "password": string | required
- body response:
"status": "success", "message": "Authentication success", "data": { "accessToken": "eyJhbG...", "refreshToken": "eyJhb..." }
- method:
-
Update Access Token
- method:
PUT
, - endpoint:
/authentications
, - body request:
"refreshToken": token | required
- body response:
"status": "success", "message": "Access Token berhasil diperbarui", "data": { "accessToken": "eyJhbGciOiJIUzI1..." }
- method:
-
Logout
- method:
DELETE
, - endpoint:
/authentications
, - body request:
"refreshToken": token | required
- body response:
"status": "success", "message": "Authentications has been removed"
- method:
---- Google ----
- Login
- method:
GET
, - endpoint:
/auth/google
- login with pop up google account
- body response:
"status": "success", "message": "Authentication success", "data": { "accessToken": "eyJhbG...", "refreshToken": "eyJhb..." }
- method:
- Update access token & logout Same as JWT Auth
- body response:
"statusCode": 401, "error": "Unauthorized", "message": "Token maximum age exceeded", "attributes": { "error": "Token maximum age exceeded" }
- body response:
"statusCode": 401, "error": "Unauthorized", "message": "Missing authentication"
-
Profile
-
Profile
- method:
GET
- endpoint:
/users
- authorization:
- type:
Bearer Token
, - token:
accessToken
- type:
- body response:
"status": "success", "data": { "user": { "id": "users-randomidstring", "name": "user name", "email": "[email protected]", "password": "$2b$10$tVdv2...", "foto_profil": null or "/users/images/users-asd.../foto-profil.png" } }
- method:
-
Edit Profile
- method:
PUT
- endpoint:
/users
- authorization:
- type:
Bearer Token
, - token:
accessToken
- type:
- header: multipart/form-data
- body request :
"name": "Budi", "email": "[email protected]" "foto_profile": "download.jpg" | file,
- body response:
"status": "success", "message": "Success updated profile", "data": { "imageUri": "http://localhost:5000/users/images/users-bzY7GwfQnsZk84tM/1654058695056download.jpg" }
- method:
-
Get Flights
- method:
GET
- endpoint:
/flights
- authorization:
- type:
Bearer Token
, - token:
accessToken
- type:
- body response:
"status": "success", "data": { "flights": [ { "id": "19629969", "airline": "Sriwijaya", "icon": "https://ik.imagekit.io/tvlk...", "depart_time": "14:20", "arrival_time": "20:50", "departure": "Jakarta", "destination": "Bali", "price": 2374000 }, {...} ] }
- method:
-
Get Flights using Filters
- method:
GET
- endpoint:
/flights?departure=jakarta&destination=bali
will be filter from jakarta to bali - authorization:
- type:
Bearer Token
, - token:
accessToken
- type:
- body response:
"status": "success", "data": { "flights": [ { "id": "19629969", "airline": "Sriwijaya", "icon": "https://ik.imagekit.io/tvlk...", "depart_time": "14:20", "arrival_time": "20:50", "departure": "Jakarta", "destination": "Bali", "price": 2374000 }, {...} ] }
- method:
-
Post Booking
- method:
POST
- endpoint:
/flights/booking
- authorization:
- type:
Bearer Token
, - token:
accessToken
- type:
- body request:
*note: id request is id flight
"id": 6552627,
- body response:
"status": "success", "message": "Booking success", "data": { "bookingId": "booking-M3dw..." }
- method:
-
Get All Booking History
- method:
GET
- endpoint:
/flights/booking
- authorization:
- type:
Bearer Token
, - token:
accessToken
- type:
- body response:
pending
"status": "success", "message": "Booking success", "data": { "bookings": [ { "id": "booking-Jij8v2tmajLkfcgj", "departure": "Jakarta", "destination": "Bali", "booking_code": 596253936, "price": 2374000, "status": "pending", }, {...} ] }
success
"status": "success", "message": "Booking success", "data": { "bookings": [ { "id": "booking-Jij8v2tmajLkfcgj", "departure": "Jakarta", "destination": "Bali", "booking_code": 596253936, "price": 2374000, "status": "success", }, {...} ] }
canceled
= after 2 minutes pendings will become canceled"status": "success", "message": "Booking success", "data": { "bookings": [ { "id": "booking-Jij8v2tmajLkfcgj", "departure": "Jakarta", "destination": "Bali", "booking_code": 596253936, "price": 2374000, "status": "canceled", }, {...} ] }
- method:
-
Get Detail Booking History
- method:
GET
- endpoint:
/flights/booking/{id}
- authorization:
- type:
Bearer Token
, - token:
accessToken
- type:
- body response:
Status same as get all booking"status": "success", "message": "Booking success", "data": { "id": "booking--O25hiweBPPwF188", "depart_time": "7:45", "arrival_time": "9:00", "departure": "Makassar", "destination": "Balikpapan", "status": "success", "price": 819200, "booking_code": 632467104, "passenger_name": "SURIAMAN", "passenger_title": "Mr", "airline": "Batik", "icon": "https://ik.imagekit.io/tvlk/image/imageResource/2019/12/13/1576208649600-12471f9b7ffa159361f7bbbfb63065ee.png" }
- method:
-
Update Booking Status (success)
- method:
PUT
- endpoint:
/flights/booking/{id}
- authorization:
- type:
Bearer Token
, - token:
accessToken
- type:
- body request:
{ "title": "Mr", (required) "name": "SURIAMAN" (required) }
- body response:
"status": "success", "message": "Booking updated", "data": { "bookingId": "booking-Jij8..." }
- method:
-
Delete All Booking
- method:
DELETE
- endpoint:
/flights/booking
- authorization:
- type:
Bearer Token
, - token:
accessToken
- type:
- body response:
"status": "success", "message": "Bookings has been deleted",
- method:
-
Delete All Booking but bookings history doesn't exist
- method:
DELETE
- endpoint:
/flights/booking
- authorization:
- type:
Bearer Token
, - token:
accessToken
- type:
- body response:
status code =400
"status": "fail", "message": "Booking data does not exist",
- method:
-
Delete Booking by Id Booking
- method:
DELETE
- endpoint:
/flights/booking/{id}
- authorization:
- type:
Bearer Token
, - token:
accessToken
- type:
- body response:
"status": "success", "message": "A booking history has been deleted",
- method:
- method:
POST
- endpoint:
/ktp
- authorization:
- type:
Bearer Token
, - token:
accessToken
- type:
- header: multipart/form-data
- body request:
* file: `image/jpg` or `image/jpeg` or `image/png` |file * data: { "class": { "NIK": { "Xmin": 117, "Ymin": 89, "Xmax": 392, "Ymax": 135 }, "name": {...}, "sex": {...}, "married": {...}, "nationality": {...} } }
- body response:
"status": "Success", "message": "KTP image successfully added", "data": { "imageId": "wPnJ9TehHkm1JaZ4" }
-
Get retrieved data from database
- method:
GET
- endpoint:
/ktpresult
- body response:
"status": "success", "data": { "title": "Ms", "name": "Artia...", "nationality": "Indonesia", "nik": "111111111111111", "sex": "Female", "married": "Single" }
- method:
-
Update retrieved data to database
- method:
PUT
- endpoint:
/ktpresult
- body request:
*note: body request is from GET /ktpresult output + data that edited by user manually
{ "title": "Ms", "name": "Artia...", "nationality": "Indonesia", "nik": "111111111111111", "sex": "Female", "married": "Single" }
- body response:
"status": "success", "data": [ { "title": "Ms", "name": "Artia...", "nationality": "Indonesia", "nik": "111111111111111", "sex": "Female", "married": "Single" } ]
- method: