5.2 KiB
5.2 KiB
AccManager Backend Setup Guide
📋 Database Information
Server: 172.20.235.176
Database: AccManager
User: sa
Password: robotics@2020
📊 Database Structure
Tables Created
1. Users - Quản lý người dùng
UserId(INT) - Primary KeyUsername(NVARCHAR) - UniquePassword(NVARCHAR)Email(NVARCHAR)FullName(NVARCHAR)Role(NVARCHAR) - admin, user, viewerStatus(NVARCHAR) - Active/InactiveCreatedDate(DATETIME)LastLogin(DATETIME)IsActive(BIT)
2. Applications - Danh sách ứng dụng
AppId(INT) - Primary KeyName(NVARCHAR)Type(NVARCHAR) - Cloud, VCS, Collaboration, InfraStatus(NVARCHAR) - online/offlineIcon(NVARCHAR)Description(NVARCHAR)CreatedDate(DATETIME)UpdatedDate(DATETIME)
3. Accounts - Tài khoản ứng dụng
AccountId(INT) - Primary KeyUserId(INT) - Foreign KeyAppId(INT) - Foreign KeyAccountUsername(NVARCHAR)AccountPassword(NVARCHAR)Email(NVARCHAR)AccessLevel(NVARCHAR)Status(NVARCHAR)Notes(NVARCHAR)CreatedDate(DATETIME)UpdatedDate(DATETIME)
4. AuditLog - Nhật ký hoạt động
LogId(INT) - Primary KeyUserId(INT) - Foreign KeyAction(NVARCHAR) - INSERT, UPDATE, DELETETableName(NVARCHAR)RecordId(INT)OldValue(NVARCHAR)NewValue(NVARCHAR)Timestamp(DATETIME)
🔐 Default Admin Account
Username: admin
Password: admin
Role: admin
Status: Active
🚀 Installation & Setup
1. Install Node.js Dependencies
npm install
2. Run Backend Server
npm start
Server sẽ chạy tại: http://localhost:3000
3. Kiểm tra Database Connection
curl http://localhost:3000/api/health
Response:
{
"status": "OK",
"database": "Connected"
}
📡 API Endpoints
Authentication
Login
POST /api/auth/login
Content-Type: application/json
{
"username": "admin",
"password": "admin"
}
Users
Get All Users
GET /api/users
Get User Details
GET /api/users/:id
Create New User
POST /api/users
Content-Type: application/json
{
"username": "newuser",
"password": "password123",
"email": "user@example.com",
"fullname": "Full Name",
"role": "user"
}
Applications
Get All Applications
GET /api/applications
Create Application
POST /api/applications
Content-Type: application/json
{
"name": "New App",
"type": "Cloud",
"status": "online",
"icon": "cloud",
"description": "Application description"
}
Accounts
Get User Accounts
GET /api/accounts/user/:userId
Create Account
POST /api/accounts
Content-Type: application/json
{
"userId": 1,
"appId": 1,
"accountUsername": "account_user",
"accountPassword": "account_pass",
"email": "account@example.com",
"accessLevel": "Admin",
"notes": "Account notes"
}
Database Info
Get Database Statistics
GET /api/database/info
Response:
{
"success": true,
"database": "AccManager",
"server": "172.20.235.176",
"tables": [
{
"TableName": "Accounts",
"ColumnCount": 11
},
{
"TableName": "Applications",
"ColumnCount": 7
},
{
"TableName": "AuditLog",
"ColumnCount": 8
},
{
"TableName": "Users",
"ColumnCount": 10
}
],
"statistics": {
"users": 1,
"applications": 4,
"accounts": 0
}
}
🔧 Frontend Integration
Update frontend API calls to use the backend server:
// Change from localStorage to API calls
const API_URL = 'http://localhost:3000/api';
// Example: Login
async function login(username, password) {
const response = await fetch(`${API_URL}/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
});
return response.json();
}
// Example: Get user accounts
async function getAccounts(userId) {
const response = await fetch(`${API_URL}/accounts/user/${userId}`);
return response.json();
}
📝 Initial Data Created
Users
- admin (admin role)
Applications
- AWS (Cloud) - online
- GitHub (VCS) - online
- Google Workspace (Collaboration) - online
- Nginx Proxy (Infra) - offline
🐛 Troubleshooting
Connection Error
Database connection failed: Error
Solution:
- Kiểm tra SQL Server đang chạy
- Kiểm tra network connectivity đến 172.20.235.176
- Kiểm tra username/password đúng
- Kiểm tra SQL Server Authentication được enable
Port Already in Use
listen EADDRINUSE: address already in use :::3000
Solution:
# Change port in .env
PORT=3001
MSSQL Module Not Found
npm install mssql
📚 References
Status: ✓ Database created, ✓ Tables created, ✓ Admin user created, ✓ Backend ready