Despacho Backend uses Mongoose ODM to define and interact with two core collections in MongoDB:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fredy-rizo/despacho-backend/llms.txt
Use this file to discover all available pages before exploring further.
LawyerUser, which represents authenticated lawyer accounts, and FormReserve, which holds client appointment reservation requests. Both schemas use Mongoose’s built-in timestamps option to automatically track document creation and modification times. Understanding these models is essential for working with the API’s request and response shapes.
Both schemas are created with
{ timestamps: true }. Mongoose automatically adds and manages the createdAt and updatedAt fields on every document — you do not need to set these manually when creating or updating records.LawyerUser model
TheLawyerUser model (src/models/LawyerUser.js) represents a law firm staff member who can log in and manage client reservations. A new LawyerUser is created via POST /api/lawyer/user/create and receives the default role of Admin on registration.
Fields
Stores the most recently issued JWT for this user. Updated on every successful login via
LawyerUser.updateOne(). Defaults to an empty string before the first login.The lawyer’s unique email address. Used as the login identifier. Stored as provided (the controller calls
.toLowerCase() during lookup to ensure case-insensitive matching).The bcrypt-hashed password. The raw password is never stored —
encryptPassword() hashes it at cost factor 10 before the document is saved.An array of role objects. Each object has a human-readable
name and a numeric string value. Defaults to [{ name: "Admin", value: "1" }] on account creation. See the Roles section for the full role reference.Automatically set by Mongoose when the document is first inserted.
Automatically updated by Mongoose every time the document is modified.
Schema source
Helper functions
FormReserve model
TheFormReserve model (src/models/FormReserve.js) represents a single appointment request submitted by a prospective client. Reservations begin with reservation_accepted: false and are updated to true when a lawyer confirms the appointment.
Fields
The client’s full name as submitted in the reservation form.
The client’s email address. Used for contact and notification purposes.
The client’s phone number stored as a numeric value.
The legal service area the client is requesting. Must be one of the six allowed values — any other string will fail Mongoose validation. Defaults to
"" if omitted (though the controller enforces this field as required).Allowed values:"Derecho civil""Derecho familiar""Derecho mercantil""Derecho penal""Derecho laboral""Derecho inmobiliario"
The client’s requested appointment date. Stored as a string (e.g.,
"2024-03-15").The client’s requested appointment time. Stored as a string (e.g.,
"10:00").An optional free-text field for any extra context or notes the client wants to include with their request.
Tracks whether a lawyer has accepted and confirmed the reservation. Set to
true when the lawyer calls POST /api/form/reserve/accept/:reserveId/reserve. Drives the filtering logic in the listing endpoints.Automatically set by Mongoose when the document is first inserted.
Automatically updated by Mongoose every time the document is modified.
Schema source
Allowed values for required_service
| Value | Area of Law |
|---|---|
Derecho civil | Civil law |
Derecho familiar | Family law |
Derecho mercantil | Commercial / mercantile law |
Derecho penal | Criminal law |
Derecho laboral | Labor / employment law |
Derecho inmobiliario | Real estate law |
MongoDB connection
Database connectivity is handled by theMongooseDB() function in src/database/DB/mongooseDB.js. It reads the connection string from the MONGODB_URL environment variable (defined in src/config.js via dotenv) and establishes the connection using mongoose.connect().
strictQuery: true is set globally, which means Mongoose will filter out any query fields that are not defined in the schema rather than passing them through to MongoDB. This prevents accidental queries against undefined fields.