Get User Documents (api/documents/getUserDocuments.ts)¶
Endpoint Overview¶
Retrieves all documents for a specific user and project, including document metadata and associated client information from summaries.
Request Handlers¶
POST¶
- Body:
- Response:
- Status: 200 OK, 400 Bad Request, 405 Method Not Allowed, 500 Internal Server Error
Error Handling¶
if (!userID) {
return res.status(400).json({ error: 'userID is required.' });
}
try {
const userDocuments = await prisma.fileStore.findMany({...});
const summaries = await prisma.summary.findMany({...});
// Process and combine data
} catch (error) {
res.status(500).json({ error: `Internal server error: ${error}` });
}
Common errors: - 400: Missing userID - 405: Non-POST request method - 500: Database query failure - 500: Data processing error
Usage Example¶
const response = await fetch("/api/documents/getUserDocuments", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
userID: "123",
projectID: "proj-456"
})
});
const documents = await response.json();
Implementation Details¶
- Uses Prisma for database queries
- Joins FileStore and Summary tables
- Filters by user and project
- Maps client names to documents
- Includes document metadata
- Parses userID as integer
- Handles missing summaries
- Returns combined data
- Selects specific fields
Pages/Components Referenced By¶
- Document Table - Documents list
- Project View - Project documents
- Get User Project API - Project context
- Add Document to Project API - Document management
Notes¶
- Requires valid user authentication
- Filters by project ID
- Includes client information
- Maintains timestamps
- Returns array of documents
- Handles null client names
- Optimizes data fetching
- Uses database relations
- Supports project organization