-
Install dependencies:
cd apps/backend-services npm install -
Create a
.envfile (optional, defaults are used if not provided):PORT=3002 NODE_ENV=development FRONTEND_URL=http://localhost:5173 DATABASE_API_URL=http://localhost:3001/api/documents
# From the backend services directory
npm run start:dev
# Or from the root directory
npm run dev:backend-servicesThe service will start on http://localhost:3002 (or the port specified in .env).
# Create a simple test file
echo "This is a test PDF content" > test.pdf
# Encode to base64 (Linux/Mac)
FILE_BASE64=$(base64 -i test.pdf)
# Or using cat (works on all platforms)
FILE_BASE64=$(cat test.pdf | base64)curl -X POST http://localhost:3002/api/upload \
-H "Content-Type: application/json" \
-d '{
"title": "Test Document",
"file": "'"$FILE_BASE64"'",
"file_type": "pdf",
"original_filename": "test.pdf",
"metadata": {
"source": "test",
"department": "IT"
}
}'- Create a new POST request to
http://localhost:3002/api/upload - Set headers:
Content-Type: application/json - Use this body structure:
{ "title": "Test Document", "file": "base64-encoded-file-content-here", "file_type": "pdf", "original_filename": "test.pdf", "metadata": { "key": "value" } }
Success Response (201 Created):
{
"success": true,
"document": {
"id": "doc_1234567890_abc123",
"title": "Test Document",
"original_filename": "test.pdf",
"file_type": "pdf",
"file_size": 1024,
"status": "pending",
"created_at": "2024-01-01T00:00:00.000Z"
}
}Error Response (400 Bad Request):
{
"statusCode": 400,
"message": ["file must be a string", "file_type must be one of the following values: pdf, image, scan"],
"error": "Bad Request"
}-
Service Logs: You should see:
- Database API call logs (stubbed)
- Queue message publish logs (stubbed)
- File storage confirmation
-
File System: Check the
data/directory. -
Response: Verify the response contains a document ID and correct metadata.
{
"title": "PDF Document",
"file": "base64-content",
"file_type": "pdf"
}{
"title": "Image Document",
"file": "base64-content",
"file_type": "image"
}{
"title": "Scanned Document",
"file": "base64-content",
"file_type": "scan"
}curl -X POST http://localhost:3002/api/upload \
-H "Content-Type: application/json" \
-d '{"title": "Test"}'curl -X POST http://localhost:3002/api/upload \
-H "Content-Type: application/json" \
-d '{
"title": "Test",
"file": "base64content",
"file_type": "invalid"
}'curl -X POST http://localhost:3002/api/upload \
-H "Content-Type: application/json" \
-d '{
"title": "Test",
"file": "",
"file_type": "pdf"
}'The service logs all stubbed operations. Check the console output for:
DatabaseService.createDocument (STUBBED)- Database API call logs
These show what would be sent to the real services.