Class: UsersService
Service responsible for handling user-related business logic in the Expensify application.
This service provides methods for managing user profiles and retrieving financial data associated with users, including balance information, financial summaries, and transaction statistics. It implements caching strategies to optimize performance for frequently accessed data.
Constructors
new UsersService()
new UsersService(
drizzleService,cacheManager):UsersService
Creates an instance of the UsersService.
Parameters
drizzleService
Service for database operations using Drizzle ORM
cacheManager
Cache
Cache manager for storing and retrieving cached data
Returns
Methods
invalidateUserStatsCache()
invalidateUserStatsCache(
userId):Promise<void>
Invalidates all cached data for a specific user. This should be called whenever user data is modified to ensure fresh data is fetched.
Parameters
userId
string
The ID of the user whose cache should be invalidated
Returns
Promise<void>
findById()
findById(
id):Promise<any>
Finds a user by their ID.
Parameters
id
string
The ID of the user to find
Returns
Promise<any>
The user object if found, or undefined if not found
findByLogin()
findByLogin(
login):Promise<any>
Finds a user by their login (either email or username).
Parameters
login
string
The email or username to search for
Returns
Promise<any>
The user object if found, or undefined if not found
findByEmail()
findByEmail(
Promise<any>
Finds a user by their email address.
Parameters
email
string
The email address to search for
Returns
Promise<any>
The user object if found, or undefined if not found
updateUser()
updateUser(
id,updatedUser):Promise<any>
Updates a user's profile information.
Parameters
id
string
The ID of the user to update
updatedUser
The new user data to apply
Returns
Promise<any>
The updated user object
Throws
NotFoundException if the user is not found
deleteUser()
deleteUser(
id):Promise<any>
Deletes a user account.
Parameters
id
string
The ID of the user to delete
Returns
Promise<any>
Throws
NotFoundException if the user is not found
getCurrentBalance()
getCurrentBalance(
userId):Promise<BalanceDto>
Retrieves the current balance for a user.
Parameters
userId
string
The ID of the user to get the balance for
Returns
Promise<BalanceDto>
A BalanceDto containing total inflows, expenses, and net balance
getMonthlyBalance()
getMonthlyBalance(
userId,year):Promise<any>
Retrieves the monthly balance breakdown for a specific year.
Parameters
userId
string
The ID of the user to get the monthly balance for
year
number
The year for which to retrieve monthly balance data
Returns
Promise<any>
An array of monthly balance records for the specified year
getFinancialSummary()
getFinancialSummary(
userId):Promise<FinancialSummaryDto>
Retrieves a comprehensive financial summary for a user.
Parameters
userId
string
The ID of the user to get the financial summary for
Returns
Promise<FinancialSummaryDto>
A FinancialSummaryDto containing current balance and statistical analysis
getTopTags()
getTopTags(
userId):Promise<any>
Retrieves a summary of the top tags used by a user.
Parameters
userId
string
The ID of the user to get the tag summary for
Returns
Promise<any>
An object containing arrays of top inflow and expense tags with amounts
getBalanceHistory()
getBalanceHistory(
userId):Promise<BalanceHistoryItemDto[]>
Retrieves the complete balance history for a user.
Parameters
userId
string
The ID of the user to get the balance history for
Returns
Promise<BalanceHistoryItemDto[]>
An array of balance history records with cumulative totals