|
| 1 | +# NiffyInsure Backend |
| 2 | + |
| 3 | +NestJS API for Stellar-based insurance platform. |
| 4 | + |
| 5 | +## Validation |
| 6 | + |
| 7 | +Global `ValidationPipe` enabled with `whitelist: true, forbidNonWhitelisted: true`. |
| 8 | + |
| 9 | +- **Unknown fields:** Rejected (400 VALIDATION_ERROR). |
| 10 | +- **Invalid values:** Field-specific errors. |
| 11 | + |
| 12 | +### Error Shape (400 VALIDATION_ERROR) |
| 13 | +RFC7807-inspired for frontend i18n: |
| 14 | + |
| 15 | +```json |
| 16 | +{ |
| 17 | + "statusCode": 400, |
| 18 | + "error": { |
| 19 | + "type": "https://datatracker.ietf.org/doc/html/rfc7807#section-3.1", |
| 20 | + "code": "VALIDATION_ERROR", |
| 21 | + "title": "One or more validation errors occurred.", |
| 22 | + "violations": [ |
| 23 | + { |
| 24 | + "field": "user.email", |
| 25 | + "code": "isEmail", |
| 26 | + "reason": "email must be an email" |
| 27 | + } |
| 28 | + ] |
| 29 | + }, |
| 30 | + "timestamp": "2024-...", |
| 31 | + "path": "/api/..." |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +**Common codes (i18n keys):** |
| 36 | +| Code | Meaning | |
| 37 | +|------|---------| |
| 38 | +| isDefined | Field required | |
| 39 | +| min | Too small | |
| 40 | +| max | Too large | |
| 41 | +| isEmail | Invalid email | |
| 42 | +| isUUID | Invalid UUID | |
| 43 | +| matches | Regex fail (e.g. Stellar pubkey `/^G[A-Z2-7]{55}$/`) | |
| 44 | +| isEnum | Invalid enum value | |
| 45 | +| isInt/isNumber | Not number | |
| 46 | +| length/minLength/maxLength | String length | |
| 47 | +| isPositive | ≤0 | |
| 48 | + |
| 49 | +### Auth Errors (401/403) |
| 50 | +Generic `{statusCode, message}` (no violations – security: no hints). |
| 51 | + |
| 52 | +### Security |
| 53 | +- **Mass-assignment:** Whitelist blocks unexpected fields. |
| 54 | +- **Type coercion:** `transform: true` safe (string→bool/num post-validation, no injection). |
| 55 | +- **Review:** All DTOs decorated; nested `@ValidateNested/@Type`. |
| 56 | + |
| 57 | +## API |
| 58 | +See `/docs`. |
| 59 | + |
| 60 | +## Local Dev |
| 61 | +```bash |
| 62 | +cd backend |
| 63 | +npm i |
| 64 | +npm run start:dev |
| 65 | +``` |
| 66 | + |
| 67 | +## Deployment |
| 68 | +Docker: `make docker-up` |
| 69 | + |
| 70 | +See Makefile. |
| 71 | + |
0 commit comments