Skip to content

Conversation

@pedrolucasdourado
Copy link
Contributor

Summary

This PR implements comprehensive updates to the Donation, User and Pickup models, authentication routes, and validation schemas, adding required fields, proper validation, and automatic pickup creation.

Features Added

Donation Model & Schema

  • Added required mediaId field referencing Media model with ObjectId validation
  • Changed materialType from free string to enum: ['plastic', 'metal', 'glass', 'paper']
  • Updated userId to correctly reference User schema with mongoose.Schema.Types.ObjectId
  • Added validation for qtdMaterial (min value: 0, must be positive integer)
  • Added ecopointId field (without Ecopoint reference - to be implemented later)

Donation Route

  • Implemented JWT token verification middleware (verifyToken)
  • Added Zod schema validation for request body
  • Implemented media existence validation before creating donation
  • Automatic Pickup creation when donation is created
  • Populate media information in response
  • Enhanced error handling with detailed messages

Authentication Routes

  • Added lastLogin field update on user login (using MongoDB $currentDate for server-side timestamp)
  • createdAt field automatically set by User model default

User Model

  • Implemented complete CPF validation with check digits verification

Tests

  • Updated all donation schema tests to include required mediaId field
  • Added comprehensive BVA tests for mediaId validation:
  • Missing mediaId
  • All 29 tests passing

Documentation

  • Added TODO comment for future media category validation ("Storage")
  • Updated inline comments for clarity

Technical Details

Models Changed

  • models/Donation.js
  • models/User.js
  • models/Pickup.js (ObjectId type correction)

Routes Changed

  • routes/donation.js
  • routes/auth.js

Schemas Changed

  • schemas/donationSchemas.js

Tests Changed

  • test/donationSchemas.test.js

Future Work

  • Implement Ecopoint model and update ecopointId to reference it
  • Add update/delete routes for donations
  • Implement media existence validation before creating donation

Related Issues

Closes Issue #29, Issue #30, Issue #32


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TASK] Refatorar User Model

2 participants