UserService Class
TheUserService class provides methods for interacting with user data stored in MongoDB. It uses Mongoose for database operations and is injected with the User model from the DELTA_DISPATCH database.
Source: src/app/user/user.service.ts
Constructor
The service is initialized with dependency injection:Mongoose model for User collection, injected from the DELTA_DISPATCH database connection
Methods
findOneDni()
Finds a single user by their DNI (national identity document number). Source:src/app/user/user.service.ts:14
Parameters
The user’s DNI number to search for
Returns
Returns the user document if found, or
null if no user exists with the given DNIExample
Implementation Details
The method uses Mongoose’sfindOne() query to search for a user where user_dni matches the provided DNI:
User Schema
The User model is defined insrc/app/user/schema/user.schema.ts and includes the following key fields:
Authentication Fields
User’s national identity document number (used for authentication)
Username for login
Hashed password
User’s email address
Profile Fields
User’s first name
User’s last name
User’s full name
User’s cellphone number
URL or path to user’s photo
Color associated with the user (for UI purposes)
Authorization Fields
User’s role in the system
User’s job position
Whether the user has root privileges
Whether the user has admin privileges
Whether the user is an inspector (for cadastre module)
Module Access Permissions
Access to citizen security module
Access to cadastre module
Access to revenue module
Access to inspections module
Access to forms/records module
State Fields
Whether the user account is active
Whether the user is currently available
Date when the user was deactivated
Additional Fields
Name of the workgroup the user belongs to
Token for push notifications
Internal user code
When the user account was created
When the user account was last updated
MongoDB Connection
The UserService connects to MongoDB using theDELTA_DISPATCH_DB_NAME connection name. This connection is configured through the DatabaseModule: