Developer Guide - ngankhanh98/nklbank-server GitHub Wiki
Đây là danh sách API
Mục lục
- 1. Phân hệ customer
- 2. Phân hệ employee
- 4. Phân hệ quản trị viên - administrator
1. Phân hệ customer
1.1 Đăng nhập
POST - /api/auth
Parameters
| Name | Type | In | Description |
|---|---|---|---|
| username | string | body | |
| password | string | body |
Default response
res.status(200).json({ accessToken, refreshToken });
Example
{
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im5nYW5raGFuaCIsImlhdCI6MTU5MTYwOTkxNCwiZXhwIjoxNTkxNjEwNTE0fQ.0qErq3xIwbWKXWn_Dl7ueowfpN51VNr0YyipXIfI4aY",
"refreshToken": "hZ5PahVJp2gOL4sV3Aoh5A24k6qGRF51yMGDovFA5pp9ZKT1ImlASS3mqEemQEg56xx7yWix8IeHAGqY"
}
Fail response
res.status(403).json({data: "Wrong username"});
res.status(403).json({data: "Wrong password"});
res.status(401).json({data: error.message}); // lỗi trong quá trình query
1.0 Xem thông tin cá nhân
GET - http://localhost:3000/api/customer/
req.headers:
req.headers["x-access-token"] = accessToken;
Ví dụ
"x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im5nYW5raGFuaCIsImlhdCI6MTU5MTYwOTkxNCwiZXhwIjoxNTkxNjEwNTE0fQ.0qErq3xIwbWKXWn_Dl7ueowfpN51VNr0YyipXIfI4aY"
response (succeed)
res.status(200).json({ username, password, fullname, email });
Ví dụ
{
"username": "ngankhanh",
"password": "$2a$08$Y7ByEvhbQBt4LsO/95znouhmE..W3C0rb7kG0Dua2a5HhxTBvtGbS",
"fullname": "NGUYEN THI NGAN KHANH",
"email": "[email protected]"
}
1.2 Liệt kê danh sách tài khoản của người dùng
1.2.1 Liệt kê tất cả mọi loại tài khoản
GET - http://localhost:3000/api/customer/accounts
req.headers:
req.headers["x-access-token"] = accessToken;
Ví dụ
"x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im5nYW5raGFuaCIsImlhdCI6MTU5MTYwOTkxNCwiZXhwIjoxNTkxNjEwNTE0fQ.0qErq3xIwbWKXWn_Dl7ueowfpN51VNr0YyipXIfI4aY"
response (succeed)
res
.status(200)
.json({
account_number,
account_balance,
type,
customer_username,
close_date,
open_date,
});
Ví dụ
[
{
"account_number": "69324",
"account_balance": "20000",
"type": 1,
"customer_username": "ngankhanh",
"open_date": "0000-00-00 00:00:00",
"close_date": "0000-00-00 00:00:00"
}
]
response (fail)
res.status(401).json(error);
1.2.2 Liệt kê tài khoản theo loại tài khoản
GET - http://localhost:3000/api/customer/accounts/:type (type = 0 || type =1)
req.headers:
req.headers["x-access-token"] = accessToken;
Ví dụ
"x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im5nYW5raGFuaCIsImlhdCI6MTU5MTYwOTkxNCwiZXhwIjoxNTkxNjEwNTE0fQ.0qErq3xIwbWKXWn_Dl7ueowfpN51VNr0YyipXIfI4aY"
response (succeed)
res
.status(200)
.json({
account_number,
account_balance,
type,
customer_username,
close_date,
open_date,
});
Ví dụ
[
{
"account_number": "23424",
"account_balance": "9654",
"type": 1,
"customer_username": "ngankhanh",
"open_date": "0000-00-00 00:00:00",
"close_date": "0000-00-00 00:00:00"
},
{
"account_number": "65635",
"account_balance": "20394",
"type": 1,
"customer_username": "ngankhanh",
"open_date": "0000-00-00 00:00:00",
"close_date": "0000-00-00 00:00:00"
},
{
"account_number": "69324",
"account_balance": "120000",
"type": 1,
"customer_username": "ngankhanh",
"open_date": "0000-00-00 00:00:00",
"close_date": "0000-00-00 00:00:00"
}
]
response (fail)
res.status(401).json(error);
1.3 Thiết lập danh sách người nhận
POST - http://localhost:3000/api/customer/add-beneficiary
req.headers:
req.headers["x-access-token"] = accessToken;
Ví dụ
"x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im5nYW5raGFuaCIsImlhdCI6MTU5MTYwOTkxNCwiZXhwIjoxNTkxNjEwNTE0fQ.0qErq3xIwbWKXWn_Dl7ueowfpN51VNr0YyipXIfI4aY"
req.body
const { account_number, name, bank } = req.body;
// name: optional, không nhập thì hệ thống từ tìm
// bank: (null, 'mpbank', 's2qbank')
Ví dụ
{
"account_number": "00051027",
"bank":"s2qbank",
"name": "USER 2"
}
response (succeed)
res.status(200).json(ret);
Ví dụ
{
"fieldCount": 0,
"affectedRows": 1,
"insertId": 0,
"serverStatus": 2,
"warningCount": 0,
"message": "",
"protocol41": true,
"changedRows": 0
}
response (fail)
res.status(401).json(error);
res.status(403).json({"msg":"Not found such beneficiary account"});
1.4 Chuyển khoản
1.4.1 Chuyển khoản nội bộ
POST - http://localhost:3000/api/customer/intrabank-transfer-money
req.headers:
req.headers["x-access-token"] = accessToken;
req.body
{
"depositor": "75675",
"receiver": "69324",
"amount": 20000,
"note": "pay debt",
"charge_include": false
}
response
res.status(403).json({ msg: "Account balance not enough" });
res.status(403).json({ msg: "Receiver account not found" });
res.status(200).json({
msg: `Transfer money succeed. Transaction stored at transaction_id = ${transaction_id}`,
});
1.4.1.1 Gửi otp đến email của user đã đăng kí
GET - http://localhost:3000/api/auth/otp
req.headers:
req.headers["x-access-token"] = accessToken;
1.4.1.1 Xác thực OTP
POST - http://localhost:3000/api/auth/otp
req.headers:
req.headers["x-access-token"] = accessToken;
req.body:
{
"otp": "13123"
}
1.4.2 Chuyển khoản liên ngân hàng
POST - http://localhost:3000/api/customer/interbank-transfer-money
req.headers:
req.headers["x-access-token"] = accessToken;
req.body:
{
"depositor": "28349",
"receiver": "1592399787",
"amount": 20000,
"note": "thanks for helping me out",
"charge_include": true,
"partner_bank": "s2qbank"
}
response (error)
res.status(403).json({ msg: "Account balance not enough" });
res.status(403).json({ msg: "Receiver account not found" });
response (success)
{
"transaction_id": 123,
"depositor": "28349",
"receiver": "1592399787",
"amount": 20000,
"net_receiving": 20000,
"note": "thanks for helping me out",
"partner_bank": "s2qbank",
"charge_include": true,
"fee": 4000
}
1.5 Quản lý nhắc nợ
1.5.1 Tạo nhắc nợ
POST - api/customer/debts
req.headers
req.headers["x-access-token"] = accessToken;
req.body
{
"creditor":"12345",
"payer":"28349",
"amount": 10000,
"description": "trả tiền tao"
}
response (success)
{
"fieldCount": 0,
"affectedRows": 1,
"insertId": 3,
"serverStatus": 2,
"warningCount": 1,
"message": "",
"protocol41": true,
"changedRows": 0
}
1.5.2 Xem danh sách nợ
GET - api/customer/debts
req.headers:
req.headers["x-access-token"] = accessToken;
response (success)
{
"creditors": [
{
"id": 5,
"creditor": "69324",
"payer": "28349",
"amount": 10000,
"paid": 0,
"description": "trả tiền tao"
}
],
"payers": []
}
1.5.3 Huỷ nhắc nợ
1.5.4 Thanh toán nhắc nợ
1.6 Xem lịch sử giao dịch của 1 tài khoản
1.6.1 Giao dịch chuyển tiền
GET- http://localhost:3000/api/customer/transactions/transfer?account_number="12345"
req.headers:
req.headers["x-access-token"] = accessToken;
response
[
{
"id": 1,
"depositor": "75675",
"receiver": "69324",
"partner_bank": null,
"amount": "20000",
"note": "pay debt, thanks",
"charge_include": 0
},
..
]
1.6.2 Giao dịch nhận tiền
GET- http://localhost:3000/api/customer/transactions/receiver?account_number="12345"
req.headers:
req.headers["x-access-token"] = accessToken;
response
[
{
"id": 1,
"depositor": "75675",
"receiver": "69324",
"partner_bank": null,
"amount": "20000",
"note": "pay debt, thanks",
"charge_include": 0
},
..
]
1.7 Đổi mật khẩu
PUT- http://localhost:3000/api/customer/passwords/ibanking
req.headers:
req.headers["x-access-token"] = accessToken;
req.body
{
"oldPassword": "admin",
"newPassword": "notadmin",
}
response
{
"fieldCount": 0,
"affectedRows": 1,
"insertId": 0,
"serverStatus": 2,
"warningCount": 0,
"message": "(Rows matched: 1 Changed: 1 Warnings: 0",
"protocol41": true,
"changedRows": 1
}
1.8 Quên mật khẩu
2. Phân hệ employee
2.1 Tạo tài khoản khách hàng
POST - api/employee/add-customer
req.body
{
"username": "maichitho",
"fullname": "mai chi tho",
"email": "[email protected]",
"password": "maichitho",
"phone":"040293482"
}
response(success)
{
"db": {
"fieldCount": 0,
"affectedRows": 1,
"insertId": 0,
"serverStatus": 2,
"warningCount": 0,
"message": "",
"protocol41": true,
"changedRows": 0
},
"customer": {
"username": "maichitho",
"password": null,
"fullname": "MAI CHI THO",
"email": "[email protected]",
"phone": "040293482"
},
"account": {
"0": {
"account_number": "752607562766",
"account_balance": "0",
"type": 0,
"customer_username": "maichitho",
"open_date": "0000-00-00 00:00:00",
"close_date": "0000-00-00 00:00:00"
}
}
}
2.2 Nạp tiền vào 1 tài-khoản bất kỳ
POST - /api/employee/intrabank-deposit
req.body
{
"receiver": "282543697473",
"amount": 20000
}
response fail
res.status(401).json({ msg: "Account not existed" })
throw new createError(401, 'Draw transaction failed')
throw new createError(401, 'Draw money failed')
response success (current balance increased)
{
"account_number": "282543697473",
"account_balance": "100000"
}
2.3 Xem lịch sử giao dịch của 1 tài khoản khách hàng
Xem lịch sử nhận tiền (tự nộp tiền & được người khác chuyển tiền)
GET - api/employee/history-deposit/:account
res.json
[
{
"id": 143,
"depositor": "82729",
"receiver": "93454",
"partner_bank": "nklbank",
"amount": "100000",
"note": "test",
"charge_include": 1,
"timestamp": "2020-06-17T08:30:52.000Z",
"keyID": null,
"pay_debt": -1
}
]
Xem lịch sử chuyển tiền (khong bao gom thanh toan no)
GET - api/employee/history-transfer/:account
response
[
{
"id": 178,
"depositor": "28349",
"receiver": "752607562766",
"partner_bank": "nklbank",
"amount": "10000",
"note": "test nua",
"charge_include": 0,
"timestamp": "2020-06-18T03:53:22.000Z",
"keyID": null,
"pay_debt": -1
},
{
"id": 177,
"depositor": "28349",
"receiver": "752607562766",
"partner_bank": "nklbank",
"amount": "10000",
"note": "test",
"charge_include": 0,
"timestamp": "2020-06-18T03:50:40.000Z",
"keyID": null,
"pay_debt": -1
}
]
Xem lịch sử thanh toán nợ (mình thanh toán nợ của mình)
GET - api/employee/history-paydebt/:account
response
[
{
"id": 176,
"depositor": "28349",
"receiver": "752607562766",
"partner_bank": "nklbank",
"amount": "10000",
"note": "nhi test",
"charge_include": 1,
"timestamp": "2020-06-18T03:47:45.000Z",
"keyID": null,
"pay_debt": 5 // this is `id` in table `debt`
}
]
4. Phân hệ quản trị viên - administrator
4.1 Quản lý danh sách nhân viên
4.1.1 Thêm nhân viên
POST - api/admin/personnel
req.headers:
req.headers["x-access-token"] = accessToken;
req.body
{
"username": "luuadmin",
"fullname": "Hoang Luu",
"password": "luuadmin",
"email": "[email protected]",
"phone":"040293482",
"admin": "1", // không có thì mặc định là 0
}
response(success)
res.sendStatus(200)
OK
4.1.2 Xem danh sách nhân viên
GET- api/admin/personnel
req.headers:
req.headers["x-access-token"] = accessToken;
response(success)
[
{
"id": 1,
"fullname": "NGUYEN NGUYEN HOANG LUU",
"username": "luuadmin1",
"password": "$2a$08$82X7Qkqrx1p/ArQCNtJsPOdFHGVn2V4hprZ7FA9MluOjirH2k0rIC",
"email": "[email protected]",
"phone": "08382633577",
"admin": 1
},
{
"id": 7,
"fullname": "NGUYEN HOANG HOANG LUU",
"username": "luuadmin3",
"password": "$2a$08$xFlpa/rODnhAXvTNtxjbFurHHfMlFiMr7IV9l8uqnF8vFvaF8s.Ci",
"email": "[email protected]",
"phone": "08382633577",
"admin": 0
},
{
"id": 8,
"fullname": "NGUYEN HOANG HOANG LUU",
"username": "luuadmin2",
"password": "$2a$08$Gj7iIIevQGoaHDCzhUgfS.7q5Jug6UXyEH8o3W3ZGrQtci504Uo8e",
"email": "[email protected]",
"phone": "08382633577",
"admin": 0
}
]
4.1.3 Xóa nhân viên
DELETE- api/admin/personnel/{id}
req.headers:
req.headers["x-access-token"] = accessToken;
response(success)
OK
4.2 Xem danh sách giao dịch trong tháng với các ngân hàng khác
4.2.1.a Đăng nhập
POST - api/auth/personnel req.body
{
"username": "luuadmin2",
"password": "luuadmin2"
}```
#### 4.2 Xem danh sách giao dịch với ngân hàng khác theo ngày
GET- api/admin/transactions/filter
**req.query**:
```json
"from": DateString
"to": DateString
req.headers:
req.headers["x-access-token"] = accessToken;
response(success)
[
{
"id": 100,
"depositor": "3234",
"receiver": "23424",
"partner_bank": "nklbank",
"amount": "2001",
"note": "thanks for helping me out",
"charge_include": 1,
"timestamp": "2020-06-12T16:11:15.000Z",
"keyID": "ebf559b848f3067d",
"pay_debt": -1
},
{
"id": 102,
"depositor": "69324",
"receiver": "23424",
"partner_bank": "nklbank",
"amount": "20000",
"note": "NGAN KHANH tra tien",
"charge_include": 1,
"timestamp": "2020-06-13T01:27:43.000Z",
"keyID": null,
"pay_debt": -1
},
...