-
Notifications
You must be signed in to change notification settings - Fork 2
/
api-service.md
179 lines (124 loc) · 4.88 KB
/
api-service.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
## Back-end service (NestJS)
<a href="./api-service.md">
<img alt="Translation" src="https://img.shields.io/badge/Bahasa_Indonesia-blue?style=for-the-badge&logo=googletranslate&logoColor=blue&labelColor=white">
</a>
<a href="./api-service.en.md">
<img alt="Translation" src="https://img.shields.io/badge/English-blue?style=for-the-badge&logo=googletranslate&logoColor=blue&labelColor=white">
</a>
<a href="./api-service.zh-CN.md">
<img alt="Translation" src="https://img.shields.io/badge/简体中文-blue?style=for-the-badge&logo=googletranslate&logoColor=blue&labelColor=white">
</a>
<a href="./api-service.ja.md">
<img alt="Translation" src="https://img.shields.io/badge/日本語-blue?style=for-the-badge&logo=googletranslate&logoColor=blue&labelColor=white">
</a>
<a href="./api-service.ar.md">
<img alt="Translation" src="https://img.shields.io/badge/Arabic_عربي-blue?style=for-the-badge&logo=googletranslate&logoColor=blue&labelColor=white">
</a>
<a href="./api-service.pt.md">
<img alt="Translation" src="https://img.shields.io/badge/Português-blue?style=for-the-badge&logo=googletranslate&logoColor=blue&labelColor=white">
</a>
<a href="./api-service.es.md">
<img alt="Translation" src="https://img.shields.io/badge/Español-blue?style=for-the-badge&logo=googletranslate&logoColor=blue&labelColor=white">
</a>
<a href="./api-service.fr.md">
<img alt="Translation" src="https://img.shields.io/badge/Français-blue?style=for-the-badge&logo=googletranslate&logoColor=blue&labelColor=white">
</a>
<a href="./api-service.vi.md">
<img alt="Translation" src="https://img.shields.io/badge/Tiếng_Việt-blue?style=for-the-badge&logo=googletranslate&logoColor=blue&labelColor=white">
</a>
<a href="./api-service.hi.md">
<img alt="Translation" src="https://img.shields.io/badge/Hindi_हिंदी-blue?style=for-the-badge&logo=googletranslate&logoColor=blue&labelColor=white">
</a>
Sudah termasuk aplikasi admin panel didalamnya
```
apps/api
apps/admin-panel
```
### Persyaratan Sistem
Pastikan sistem Anda memenuhi persyaratan berikut sebelum memulai instalasi:
- Node.js v18 or higher
- PostgreSQL 15 or higher
- Redis v5 or higher
### Langkah-langkah Instalasi
1. Clone/extract Repository
2. Install dependencies:
```bash
npm i
```
#### Setup environment
- Rename `.env.example` to `.env`
#### Setup database
- Atur `DATABASE_URL` di `.env`
```sh
DATABASE_URL="postgresql:https://<username>:<password>@<host>:5432/<db-name>?schema=public"
# example
DATABASE_URL="postgresql:https://postgres:postgre123@localhost:5432/backtix?schema=public"
```
- Jalankan migrasi untuk membuat tabel yang diperlukan
```bash
npx prisma migrate deploy
```
- Jalankan database seeder untuk membuat user `superadmin`
```bash
npm run db:seed
```
#### Setup **Google sign in** server & client ID
- Buat project baru di [Google Cloud Console](https://console.cloud.google.com/projectcreate)
- Setelah selesai membuat projek, pilih `APIs & Services`, lalu pilih `OAuth consent screen` disebelah kiri
- Masukkan nama aplikasi, email dan `Developer contact information`
![Cloud Console](/assets/Screenshot_1.png)
- **Server** client ID
- Pilih `Credentials` di sidebar kiri, klik `CREATE CREDENTIALS`, pilih `OAuth client ID`
![Cloud Console](/assets/Screenshot_2.png)
- Pilih `Web application` application type, beri nama lalu save/create
![Cloud Console](/assets/Screenshot_3.png)
- Salin `Client ID` dan `Client secret` ke file `.env`
```sh
# google oauth
SERVER_GOOGLE_CLIENT_ID=
SERVER_GOOGLE_CLIENT_SECRET=
```
- **Web app** client ID
- `CREATE CREDENTIALS` kembali, pilih `OAuth client ID`
- Pilih `Web application` application type, beri nama dan `Authorized JavaScript origins` seperti di gambar (jika menggunakan localhost), lalu save/create
![Cloud Console](/assets/Screenshot_4.png)
- Salin `Client ID` dan `Client secret` ke file `.env`
```sh
# optional web only
WEB_APP_GOOGLE_CLIENT_ID=
WEB_APP_GOOGLE_CLIENT_SECRET=
```
- Klik `DOWNLOAD JSON` dan simpan Client ID. Web Client ID akan digunakan di flutter mobile app.
#### Setup midtrans server & client key
- Pergi ke [Dashboard Midtrans](https://dashboard.midtrans.com/), pilih environment `sandbox`(recommended) atau `production`
- Masuk ke `Settings` > `Access Keys`, lalu salin client dan server key ke file `.env`
```sh
# sandbox
MIDTRANS_URL=https://app.sandbox.midtrans.com/snap/v1/transactions
# production
MIDTRANS_URL=https://app.midtrans.com/snap/v1/transactions
MIDTRANS_SERVER_KEY=
MIDTRANS_CLIENT_KEY=
```
- Configurasi variabel `.env` lainnya sesuai kebutuhan.
### How to run
1. Generate `metadata`:
```bash
npm run metadata --workspace=@backtix-service/api
```
2. Run app
```bash
npm run start
```
- Development mode
```bash
npm run start:dev
```
2. Swagger API docs
- Buka https://localhost:3000/api/docs (sesuaikan base url)
3. Test (optional)
```bash
npm test
```
### Screenshots
![Swagger API Docs](/assets/swagger.png)