feat: Implement invoice CRUD, file uploads, seed scripts, and CI/CD pipeline - #34
Merged
Merged
Conversation
- Create invoiceSchema with line items support - Add updateInvoiceSchema with status transition validation - Add query schema for pagination, filtering, and sorting
- Create base AppError class with statusCode and isOperational flag - Add NotFoundError, UnauthorizedError, ForbiddenError, ValidationError - Add ConflictError for state transition violations
- Handle AppError, ValidationError, and unexpected errors - Return structured JSON error responses - Include field-level validation errors for 400 responses
- Support validation for body, query, and params - Return structured error responses with field-level messages - Auto-assign parsed data back to request object
- Implement Bearer token verification - Add authenticate middleware for protected routes - Add authorize middleware with role-based access control - Extend Express Request type with user payload
…issions - Create invoice (freelancers only) - List invoices with pagination, filters, and search - Get invoice by ID with access control - Update invoice with status transition validation - Delete invoice (draft status only) - Enforce DRAFT→PENDING→FUNDED→IN_ESCROW→COMPLETED state machine
- POST /api/invoices - Create invoice (freelancers) - GET /api/invoices - List invoices with query filters - GET /api/invoices/:id - Get invoice by ID - PATCH /api/invoices/:id - Update invoice (freelancers) - DELETE /api/invoices/:id - Delete invoice (freelancers)
- Add lineItems field with default empty array - Support structured line item data for invoices
- Create 5 test users (freelancers, clients, admin) - Add 5 sample invoices with different statuses - Create 2 escrow records - Add sample notifications - Include line items for invoice items
- db-reset.sh: Reset database and reseed - db-migrate.sh: Run development migrations - db-deploy.sh: Deploy migrations to production
- Add multer for file upload handling - Add sharp for image resizing - Add AWS SDK for S3 integration - Add @types/multer for TypeScript support - Add DB management scripts to package.json
- S3 client configuration with presigned URL support - Avatar resize to thumbnail (64px), small (128px), medium (256px) - File type validation for images and PDFs - File size validation (10MB limit) - Presigned URL generation for direct uploads
- Upload avatar with automatic resizing - Upload invoice attachments with ownership validation - Generate presigned URLs for direct client uploads - Validate file types and sizes
- POST /api/uploads/avatar - Upload user avatar - POST /api/uploads/invoice/:invoiceId - Upload invoice attachment - GET /api/uploads/presigned-url - Get presigned upload URL
- Add AWS region, bucket, access key, secret key - Support custom S3 endpoint for MinIO compatibility - Add forcePathStyle option for local development
- AWS_REGION, AWS_S3_BUCKET - AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY - Optional AWS_S3_ENDPOINT for MinIO - Optional AWS_S3_FORCE_PATH_STYLE
- Register /api/invoices routes - Register /api/uploads routes - Add global error handler middleware
- Lint job with ESLint - Type check job with tsc - Test job with Vitest and PostgreSQL service - Build job with artifact upload - Run on push/PR to main and develop branches
- Deploy to staging on push to main - Deploy to production after staging - Run Prisma migrations before deployment - Environment-specific secrets for each stage
- Configure ESLint 9 flat config format - Add typescript-eslint for TypeScript support - Disable no-namespace rule for Express type augmentation
- Add typescript-eslint@8.34.0 for ESLint TypeScript support - Use --legacy-peer-deps due to TypeScript 6.x compatibility
- Test AppError, NotFoundError, UnauthorizedError, ForbiddenError - Test invoice create schema validation (valid and invalid) - Test file type and size validation logic - Test file key generation patterns
- Fix jwt.verify cast with unknown intermediate type - Add undefined check for token after split - Fix req.params access with explicit casting - Fix S3Client config with conditional endpoint - Fix Prisma profileImage nullable update
- Upgrade typescript-eslint to ^8.63.0 (supports TypeScript 6.x) - Regenerate package-lock.json for clean npm ci - Update CI workflow to use Node 22 (Node 20 deprecated)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves 4 open issues in the backend repository with comprehensive implementations for invoice management, file uploads, database seeding, and CI/CD automation.
closes #33 Invoice Creation and Management Endpoints ✅
src/validators/invoice.schema.ts): Input validation for create, update, and query operations with line items supportsrc/utils/AppError.ts): AppError, NotFoundError, ForbiddenError, ValidationError, ConflictErrorsrc/middleware/errorHandler.ts): Global error middleware with structured JSON responsessrc/middleware/validate.ts): Generic Zod validation for body, query, and paramssrc/middleware/auth.ts): JWT authentication and role-based authorizationsrc/controllers/invoice.controller.ts):src/routes/invoice.routes.ts): Full REST API with auth and validationprisma/schema.prisma): AddedlineItemsJSON field to Invoice modelcloses #32 Database Migration and Seeding Scripts ✅
prisma/seed.ts): 5 test users, 5 invoices with different statuses, 2 escrows, 3 notificationsscripts/db-reset.sh): Reset database and reseed for local developmentscripts/db-migrate.sh): Run development migrationsscripts/db-deploy.sh): Deploy migrations to productiondb:reset,db:migrate,db:deployscriptscloses #31 File Upload Service ✅
src/services/upload.service.ts):src/controllers/upload.controller.ts):src/routes/upload.routes.ts): REST API for file uploadssrc/config/index.ts): Added S3 configuration.env.example): Added AWS S3 settingscloses #30 CI/CD Pipeline ✅
.github/workflows/ci.yml):.github/workflows/deploy.yml):Files Changed (19)
src/validators/invoice.schema.tssrc/utils/AppError.tssrc/middleware/errorHandler.tssrc/middleware/validate.tssrc/middleware/auth.tssrc/controllers/invoice.controller.tssrc/routes/invoice.routes.tsprisma/schema.prismaprisma/seed.tsscripts/db-reset.shscripts/db-migrate.shscripts/db-deploy.shpackage.jsonsrc/services/upload.service.tssrc/controllers/upload.controller.tssrc/routes/upload.routes.tssrc/config/index.ts.env.examplesrc/index.ts.github/workflows/ci.yml.github/workflows/deploy.yml