Skip to content

API dengan Express.js dan JWT untuk Web Task SEA COMFEST

Notifications You must be signed in to change notification settings

novandikp/api-dokter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Dokter

API FOR WEB

Build Status

Api dokter merupakan api dari aplikasi webdokter yang dibuat untuk memenuhi tugas dari web task untuk Software Enginering Academy Comfest

Deskripsi

  • API telah terproteksi dengan JWT (JSON Web Token)
  • API telah diberi CORS
  • API dibuat menggunakan Express.js

Instalasi

Api dokter membutuhkan Node

Install semua despedensi untuk menjalankan

cd apidokter
yarn install
yarn start

Akun admin

username : admin123 password : admin123

Pemakaian API

Auth

Login

url : "/auth/login"

Request Method :POST Sample Body

{
  "username": "username",
  "password": "password"
}

Sample Response

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluMTIzIiwicm9sZSI6MSwicHJvamVjdCI6IkFwbGlrYXNpRG9rdGVyIiwiaWF0IjoxNjI1Mjk4NjcxfQ.6Pdz2HICtjXm04FHrZ_Zh1y7vgd0-rFfJdMf5Cxbpn0",
  "role": 1,
  "name": "Admina Saja"
}

Register

url : "/auth/register" Request Method :POST Sample Body

{
  "username": "username",
  "password": "password",
  "firstName": "firstname",
  "lastName": "lastname",
  "email": "email@email.com"
}

Sample Response

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluMTIzIiwicm9sZSI6MSwicHJvamVjdCI6IkFwbGlrYXNpRG9rdGVyIiwiaWF0IjoxNjI1Mjk4NjcxfQ.6Pdz2HICtjXm04FHrZ_Zh1y7vgd0-rFfJdMf5Cxbpn0",
  "status": true,
  "data": {
    "username": "username",
    "password": "password",
    "firstName": "firstname",
    "lastName": "lastname",
    "email": "email@email.com",
    "roles": 1
  }
}

User

GET url : "/user" Request Method : GET Header

"Authorization" : "Token"

Response

{
  "status": true,
  "data": [
    {
      "username": "novandi",
      "email": "ad@gmail.com",
      "firstname": "novandi",
      "lastname": "kevin",
      "password": "a2257cec704fa09ef1b332e92f41566e",
      "roles": "Patient",
      "id": 2
    }
  ]
}

GET BY Username url : "/user/:username" Request Method : GET Header

"Authorization" : "Token"

Response

{
  "status": true,
  "data": {
    "username": "novandi",
    "email": "ad@gmail.com",
    "firstname": "novandi",
    "lastname": "kevin",
    "password": "a2257cec704fa09ef1b332e92f41566e",
    "roles": "Patient",
    "id": 2
  }
}

INSERT url : "/user" Request Method : POST Header

"Authorization" : "Token"

Body

{
  "username": "novandi",
  "email": "ad@gmail.com",
  "firstname": "novandi",
  "lastname": "kevin",
  "password": "pass",
  "roles": "1"
}
  • Role 1 untuk pasien
  • Role 2 untuk Admin

Response

{
  "status": true,
  "data": {
    "username": "novandi",
    "email": "ad@gmail.com",
    "firstname": "novandi",
    "lastname": "kevin",
    "password": "a2257cec704fa09ef1b332e92f41566e",
    "roles": "Patient",
    "id": 2
  }
}

UPDATE url : "/user/:username" Request Method : PUT Header

"Authorization" : "Token"

Body

{
  "username": "novandi",
  "email": "ad@gmail.com",
  "firstname": "novandi",
  "lastname": "kevin",
  "password": "pass",
  "roles": "1"
}
  • Role 1 untuk pasien
  • Role 2 untuk Admin

Response

{
  "status": true,
  "data": {
    "username": "novandi",
    "email": "ad@gmail.com",
    "firstname": "novandi",
    "lastname": "kevin",
    "password": "a2257cec704fa09ef1b332e92f41566e",
    "roles": "Patient",
    "id": 2
  }
}

DELETE url : "/user/:username" Request Method : DELETE Header

"Authorization" : "Token"

Response

{
  "status": true,
  "data": {
    "username": "novandi"
  }
}

Dokter

GET url : "/dokter" Request Method : GET Header

"Authorization" : "Token"

Response

{
  "status": true,
  "data": [
    {
      "id": 4,
      "doctor": "Kevin",
      "address": "Sidoarjo",
      "phonenumber": "0888"
    }
  ]
}

GET BY ID url : "/dokter/:id" Request Method : GET Header

"Authorization" : "Token"

Response

{
  "status": true,
  "data": {
    "id": 4,
    "doctor": "Kevin",
    "address": "Sidoarjo",
    "phonenumber": "0888"
  }
}

INSERT url : "/dokter" Request Method : POST Header

"Authorization" : "Token"

Body

{
  "doctor": "Kevin",
  "address": "Sidoarjo",
  "phonenumber": "0888"
}

Response

{
  "status": true,
  "data": {
    "doctor": "Kevin",
    "address": "Sidoarjo",
    "phonenumber": "0888"
  }
}

UPDATE url : "/dokter/:id" Request Method : PUT Header

"Authorization" : "Token"

Body

{
  "doctor": "Kevin",
  "address": "Sidoarjo",
  "phonenumber": "0888"
}

Response

{
  "status": true,
  "data": {
    "doctor": "Kevin",
    "address": "Sidoarjo",
    "phonenumber": "0888"
  }
}

DELETE url : "/dokter/:id" Request Method : DELETE Header

"Authorization" : "Token"

Response

{
  "status": true,
  "data": {
    "iddoctor": "1"
  }
}

Appointment

GET url : "/appointment" Request Method : GET Header

"Authorization" : "Token"

Response

{
  "status": true,
  "data": [
    {
      "id": 1,
      "iddoctor": 13,
      "starttime": "07:00:00",
      "endtime": "12:00:00",
      "description": "Sunat",
      "duration": 10,
      "doctor": "Budi",
      "address": "Sidoarjo"
    }
  ]
}

GET BY ID url : "/appointment/:id" Request Method : GET Header

"Authorization" : "Token"

Response

{
  "status": true,
  "data": {
    "id": 1,
    "iddoctor": 13,
    "starttime": "07:00:00",
    "endtime": "12:00:00",
    "description": "Sunat",
    "duration": 10,
    "doctor": "Budi",
    "address": "Sidoarjo"
  }
}

INSERT url : "/appointment" Request Method : POST Header

"Authorization" : "Token"

Body

{
  "iddoctor": 1,
  "starttime": "19:00",
  "endtime": "20:00",
  "description": "Sunat",
  "duration": 5
}

Duration dalam hitungan menit

Response

{
  "status": true,
  "data": {
    "iddoctor": 1,
    "starttime": "19:00",
    "endtime": "20:00",
    "description": "Sunat",
    "duration": 5
  }
}

UPDATE url : "/appointment/:id" Request Method : PUT Header

"Authorization" : "Token"

Body

{
  "iddoctor": 1,
  "starttime": "19:00",
  "endtime": "20:00",
  "description": "Sunat",
  "duration": "5"
}

Response

{
  "status": true,
  "data": {
    "iddoctor": 1,
    "starttime": "19:00",
    "endtime": "20:00",
    "description": "Sunat",
    "duration": 5
  }
}

DELETE url : "/appointment/:id" Request Method : DELETE Header

"Authorization" : "Token"

Response

{
  "status": true
}

Regisrant

GET url : "/regis" Request Method : GET Header

"Authorization" : "Token"

Response

{
  "status": true,
  "data": [
    {
      "id": "5",
      "username": "novandi",
      "idappointments": 1,
      "date_regist": "2021-07-03T00:00:00.000Z",
      "date_book": "2021-07-08T00:00:00.000Z",
      "time_book": "08:00:00",
      "flagstatus": 2,
      "firstname": "novandi",
      "lastname": "kevin",
      "email": "ad@gmail.com",
      "description": "Sunat",
      "doctor": "Budi"
    }
  ]
}

GET BY USERNAME url : "/regis/username/:username" Request Method : GET Header

"Authorization" : "Token"

Response

{
  "status": true,
  "data": [
    {
      "id": "5",
      "username": "novandi",
      "idappointments": 1,
      "date_regist": "2021-07-03T00:00:00.000Z",
      "date_book": "2021-07-08T00:00:00.000Z",
      "time_book": "08:00:00",
      "flagstatus": 2,
      "firstname": "novandi",
      "lastname": "kevin",
      "email": "ad@gmail.com",
      "description": "Sunat",
      "doctor": "Budi"
    }
  ]
}

GET BY APPOINTMENT url : "/regis/appointment/:id" Request Method : GET Header

"Authorization" : "Token"

Response

{
  "status": true,
  "data": [
    {
      "id": "5",
      "username": "novandi",
      "idappointments": 1,
      "date_regist": "2021-07-03T00:00:00.000Z",
      "date_book": "2021-07-08T00:00:00.000Z",
      "time_book": "08:00:00",
      "flagstatus": 2,
      "firstname": "novandi",
      "lastname": "kevin",
      "email": "ad@gmail.com",
      "description": "Sunat",
      "doctor": "Budi"
    }
  ]
}

GET BY ID url : "/regis/:id" Request Method : GET Header

"Authorization" : "Token"

Response

{
  "status": true,
  "data": {
    "id": "5",
    "username": "novandi",
    "idappointments": 1,
    "date_regist": "2021-07-03T00:00:00.000Z",
    "date_book": "2021-07-08T00:00:00.000Z",
    "time_book": "08:00:00",
    "flagstatus": 2,
    "firstname": "novandi",
    "lastname": "kevin",
    "email": "ad@gmail.com",
    "description": "Sunat",
    "doctor": "Budi"
  }
}

INSERT url : "/dokter" Request Method : POST Header

"Authorization" : "Token"

Body

{
  "date_book": "2021-06-29",
  "date_regist": "2021-07-03",
  "flagstatus": 1,
  "idappointments": "1",
  "time_book": "09:50",
  "username": "novandi"
}

Response

{
  "status": true,
  "data": {
    "date_book": "2021-06-29",
    "date_regist": "2021-07-03",
    "flagstatus": 1,
    "idappointments": "1",
    "time_book": "09:50",
    "username": "novandi"
  }
}

UPDATE url : "/regis/:id" Request Method : PUT Header

"Authorization" : "Token"

Body

{
  "date_book": "2021-06-29",
  "date_regist": "2021-07-03",
  "flagstatus": 1,
  "idappointments": "1",
  "time_book": "09:50",
  "username": "novandi"
}

Response

{
  "status": true,
  "data": {
    "date_book": "2021-06-29",
    "date_regist": "2021-07-03",
    "flagstatus": 1,
    "idappointments": "1",
    "time_book": "09:50",
    "username": "novandi"
  }
}

DELETE url : "/regis/:id" Request Method : DELETE Header

"Authorization" : "Token"

Response

{
  "status": true
}

About

API dengan Express.js dan JWT untuk Web Task SEA COMFEST

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published