diff --git a/packages/database-services/src/features/auth/TeamsManager.ts b/packages/database-services/src/features/auth/TeamsManager.ts index 156b3854..9365bbf1 100644 --- a/packages/database-services/src/features/auth/TeamsManager.ts +++ b/packages/database-services/src/features/auth/TeamsManager.ts @@ -31,17 +31,11 @@ import { UpdateTeamUser, } from '@moaitime/shared-common'; -import { calendarsManager, CalendarsManager } from '../calendars/CalendarsManager'; -import { listsManager, ListsManager } from '../tasks/ListsManager'; -import { usersManager, UsersManager } from './UsersManager'; +import { calendarsManager } from '../calendars/CalendarsManager'; +import { listsManager } from '../tasks/ListsManager'; +import { usersManager } from './UsersManager'; export class TeamsManager { - constructor( - private _usersManager: UsersManager, - private _listsManager: ListsManager, - private _calendarsManager: CalendarsManager - ) {} - // API Helpers async list(actorUserId: string) { return this.findManyByUserId(actorUserId); @@ -126,7 +120,7 @@ export class TeamsManager { actorUser: User, teamName: string ): Promise<{ team: Team; teamUser: TeamUser }> { - const maxCount = await this._usersManager.getUserLimit(actorUser, 'teamsMaxPerUserCount'); + const maxCount = await usersManager.getUserLimit(actorUser, 'teamsMaxPerUserCount'); const currentCount = await this.countByUserId(actorUser.id); if (currentCount >= maxCount) { throw new Error(`You have reached the maximum number of teams per user (${maxCount}).`); @@ -446,7 +440,7 @@ export class TeamsManager { } const usersByEmail = - emailsSet.size > 0 ? await this._usersManager.findManyByEmails([...emailsSet.values()]) : []; + emailsSet.size > 0 ? await usersManager.findManyByEmails([...emailsSet.values()]) : []; const usersByEmailMap = new Map(); for (const user of usersByEmail) { usersByEmailMap.set(user.email, user); @@ -879,9 +873,9 @@ export class TeamsManager { async getTeamUsage(team: Team): Promise { // TODO: cache! - const listsCount = await this._listsManager.countByTeamId(team.id); - const usersCount = await this._usersManager.countByTeamId(team.id); - const calendarsCount = await this._calendarsManager.countByTeamId(team.id); + const listsCount = await listsManager.countByTeamId(team.id); + const usersCount = await usersManager.countByTeamId(team.id); + const calendarsCount = await calendarsManager.countByTeamId(team.id); return { listsCount, @@ -913,4 +907,4 @@ export class TeamsManager { } } -export const teamsManager = new TeamsManager(usersManager, listsManager, calendarsManager); +export const teamsManager = new TeamsManager(); diff --git a/packages/database-services/src/features/auth/UserNotificationsManager.ts b/packages/database-services/src/features/auth/UserNotificationsManager.ts index 9387a823..2bf775f2 100644 --- a/packages/database-services/src/features/auth/UserNotificationsManager.ts +++ b/packages/database-services/src/features/auth/UserNotificationsManager.ts @@ -33,9 +33,9 @@ import { UserNotificationTypeMessages, } from '@moaitime/shared-common'; -import { contentParser, ContentParser } from '../core/ContentParser'; -import { entityManager, EntityManager } from '../core/EntityManager'; -import { usersManager, UsersManager } from './UsersManager'; +import { contentParser } from '../core/ContentParser'; +import { entityManager } from '../core/EntityManager'; +import { usersManager } from './UsersManager'; export type UserNotificationsManagerFindOptions = { from?: string; @@ -48,12 +48,6 @@ export type UserNotificationsManagerFindOptions = { }; export class UserNotificationsManager { - constructor( - private _usersManager: UsersManager, - private _entityManager: EntityManager, - private _contentParser: ContentParser - ) {} - // API Helpers async list(actorUserId: string, options?: UserNotificationsManagerFindOptions) { return this.findManyByUserIdWithDataAndMeta(actorUserId, options); @@ -87,7 +81,7 @@ export class UserNotificationsManager { throw new Error('User notification not found'); } - const user = await this._usersManager.findOneById(actorUserId); + const user = await usersManager.findOneById(actorUserId); if (!user) { throw new Error('User not found'); } @@ -278,7 +272,7 @@ export class UserNotificationsManager { rows.reverse(); } - const user = await this._usersManager.findOneById(userId); + const user = await usersManager.findOneById(userId); if (!user) { throw new Error('User not found'); } @@ -419,7 +413,7 @@ export class UserNotificationsManager { private async _parseRows(user: User, rows: UserNotification[]) { const parsedRows: UserNotificationStripped[] = []; - const objectsMap = await this._entityManager.getObjectsMap(rows); + const objectsMap = await entityManager.getObjectsMap(rows); for (const row of rows) { const content = UserNotificationTypeMessages[row.type as UserNotificationTypeEnum]; @@ -428,7 +422,7 @@ export class UserNotificationsManager { ? row.data.variables : {} ) as Record; - const parsedContent = this._contentParser.parse(content, variables, objectsMap); + const parsedContent = contentParser.parse(content, variables, objectsMap); let link = null; if (row.type === UserNotificationTypeEnum.USER_FOLLOW_REQUEST_RECEIVED) { @@ -472,8 +466,4 @@ export class UserNotificationsManager { } } -export const userNotificationsManager = new UserNotificationsManager( - usersManager, - entityManager, - contentParser -); +export const userNotificationsManager = new UserNotificationsManager(); diff --git a/packages/database-services/src/features/auth/UsersManager.ts b/packages/database-services/src/features/auth/UsersManager.ts index 1ad0fe82..c87f231f 100644 --- a/packages/database-services/src/features/auth/UsersManager.ts +++ b/packages/database-services/src/features/auth/UsersManager.ts @@ -53,21 +53,18 @@ import { } from '@moaitime/shared-common'; import { uploader } from '@moaitime/uploader'; -import { calendarsManager, CalendarsManager } from '../calendars/CalendarsManager'; -import { eventsManager, EventsManager } from '../calendars/EventsManager'; -import { focusSessionsManager, FocusSessionsManager } from '../focus/FocusSessionsManager'; -import { habitsManager, HabitsManager } from '../habits/HabitsManager'; -import { moodEntriesManager, MoodEntriesManager } from '../mood/MoodEntriesManager'; -import { notesManager, NotesManager } from '../notes/NotesManager'; -import { reportsManager, ReportsManager } from '../reports/ReportsManager'; -import { invitationsManager, InvitationsManager } from '../social/InvitationsManager'; -import { listsManager, ListsManager } from '../tasks/ListsManager'; -import { tagsManager, TagsManager } from '../tasks/TagsManager'; -import { tasksManager, TasksManager } from '../tasks/TasksManager'; -import { - userOnlineActivityEntriesManager, - UserOnlineActivityEntriesManager, -} from './UserOnlineActivityEntriesManager'; +import { calendarsManager } from '../calendars/CalendarsManager'; +import { eventsManager } from '../calendars/EventsManager'; +import { focusSessionsManager } from '../focus/FocusSessionsManager'; +import { habitsManager } from '../habits/HabitsManager'; +import { moodEntriesManager } from '../mood/MoodEntriesManager'; +import { notesManager } from '../notes/NotesManager'; +import { reportsManager } from '../reports/ReportsManager'; +import { invitationsManager } from '../social/InvitationsManager'; +import { listsManager } from '../tasks/ListsManager'; +import { tagsManager } from '../tasks/TagsManager'; +import { tasksManager } from '../tasks/TasksManager'; +import { userOnlineActivityEntriesManager } from './UserOnlineActivityEntriesManager'; export type UsersManagerFollowOptions = { limit: number; @@ -81,21 +78,6 @@ export type UsersManagerSearchOptions = UsersManagerFollowOptions & { }; export class UsersManager { - constructor( - private _calendarsManager: CalendarsManager, - private _eventsManager: EventsManager, - private _focusSessionsManager: FocusSessionsManager, - private _habitsManager: HabitsManager, - private _moodEntriesManager: MoodEntriesManager, - private _notesManager: NotesManager, - private _reportsManager: ReportsManager, - private _invitationsManager: InvitationsManager, - private _listsManager: ListsManager, - private _tagsManager: TagsManager, - private _tasksManager: TasksManager, - private _userOnlineActivityEntriesManager: UserOnlineActivityEntriesManager - ) {} - // API Helpers async view( actorUserId: string, @@ -119,7 +101,7 @@ export class UsersManager { const followersCount = canViewUserIfPrivate ? await this.countFollowers(user.id) : 0; const followingCount = canViewUserIfPrivate ? await this.countFollowing(user.id) : 0; const lastActiveAt = canViewUserIfPrivate - ? await this._userOnlineActivityEntriesManager.getLastActiveAtByUserId(user.id) + ? await userOnlineActivityEntriesManager.getLastActiveAtByUserId(user.id) : null; const experiencePoints = canViewUserIfPrivate ? await this.getExperincePointsByUserId(user.id) @@ -459,7 +441,7 @@ export class UsersManager { throw new Error(`User with username or ID "${userIdOrUsername}" was not found.`); } - const report = await this._reportsManager.insertOne({ + const report = await reportsManager.insertOne({ userId: actorUserId, targetEntity: { id: user.id, @@ -1063,17 +1045,17 @@ export class UsersManager { async getUserUsage(user: User): Promise { // TODO: cache! - const listsCount = await this._listsManager.countByUserId(user.id); - const tasksCount = await this._tasksManager.countByUserId(user.id); - const tagsCount = await this._tagsManager.countByUserId(user.id); - const habitsCount = await this._habitsManager.countByUserId(user.id); - const notesCount = await this._notesManager.countByUserId(user.id); - const moodEntriesCount = await this._moodEntriesManager.countByUserId(user.id); - const calendarsCount = await this._calendarsManager.countByUserId(user.id); - const userCalendarsCount = await this._calendarsManager.countUserCalendarsByUserId(user.id); - const eventsCount = await this._eventsManager.countByUserId(user.id); - const focusSessionsCount = await this._focusSessionsManager.countByUserId(user.id); - const userInvitationsCount = await this._invitationsManager.countByUserId(user.id); + const listsCount = await listsManager.countByUserId(user.id); + const tasksCount = await tasksManager.countByUserId(user.id); + const tagsCount = await tagsManager.countByUserId(user.id); + const habitsCount = await habitsManager.countByUserId(user.id); + const notesCount = await notesManager.countByUserId(user.id); + const moodEntriesCount = await moodEntriesManager.countByUserId(user.id); + const calendarsCount = await calendarsManager.countByUserId(user.id); + const userCalendarsCount = await calendarsManager.countUserCalendarsByUserId(user.id); + const eventsCount = await eventsManager.countByUserId(user.id); + const focusSessionsCount = await focusSessionsManager.countByUserId(user.id); + const userInvitationsCount = await invitationsManager.countByUserId(user.id); return { listsCount, @@ -1374,17 +1356,4 @@ export class UsersManager { } } -export const usersManager = new UsersManager( - calendarsManager, - eventsManager, - focusSessionsManager, - habitsManager, - moodEntriesManager, - notesManager, - reportsManager, - invitationsManager, - listsManager, - tagsManager, - tasksManager, - userOnlineActivityEntriesManager -); +export const usersManager = new UsersManager(); diff --git a/packages/database-services/src/features/calendars/CalendarEntriesManager.ts b/packages/database-services/src/features/calendars/CalendarEntriesManager.ts index 7ef0d034..23e3530a 100644 --- a/packages/database-services/src/features/calendars/CalendarEntriesManager.ts +++ b/packages/database-services/src/features/calendars/CalendarEntriesManager.ts @@ -15,19 +15,12 @@ import { Task, } from '@moaitime/shared-common'; -import { listsManager, ListsManager } from '../tasks/ListsManager'; -import { tasksManager, TasksManager, TaskWithTagsAndUsers } from '../tasks/TasksManager'; -import { calendarsManager, CalendarsManager } from './CalendarsManager'; -import { eventsManager, EventsManager, EventsManagerEvent } from './EventsManager'; +import { listsManager } from '../tasks/ListsManager'; +import { tasksManager, TaskWithTagsAndUsers } from '../tasks/TasksManager'; +import { calendarsManager } from './CalendarsManager'; +import { eventsManager, EventsManagerEvent } from './EventsManager'; export class CalendarEntriesManager { - constructor( - private _calendarsManager: CalendarsManager, - private _listsManager: ListsManager, - private _tasksManager: TasksManager, - private _eventsManager: EventsManager - ) {} - // API Helpers async list(actorUser: User, from: string, to: string) { if (!isValidDate(from)) { @@ -43,17 +36,13 @@ export class CalendarEntriesManager { async yearly(actorUserId: string, year: number) { // Calendar - const calendarIdsMap = - await this._calendarsManager.getVisibleCalendarIdsByUserIdMap(actorUserId); + const calendarIdsMap = await calendarsManager.getVisibleCalendarIdsByUserIdMap(actorUserId); const calendarIds = Array.from(calendarIdsMap.keys()); - const calendarCounts = await this._eventsManager.getCountsByCalendarIdsAndYear( - calendarIds, - year - ); + const calendarCounts = await eventsManager.getCountsByCalendarIdsAndYear(calendarIds, year); // Tasks - const listIds = await this._listsManager.getVisibleListIdsByUserId(actorUserId); - const taskCounts = await this._tasksManager.getCountsByListIdsAndYear(listIds, year); + const listIds = await listsManager.getVisibleListIdsByUserId(actorUserId); + const taskCounts = await tasksManager.getCountsByListIdsAndYear(listIds, year); // Merge const daysMap = new Map(); @@ -89,8 +78,8 @@ export class CalendarEntriesManager { timezonedTo = addDays(timezonedTo, 2); } - const calendarIdsMap = await this._calendarsManager.getVisibleCalendarIdsByUserIdMap(user.id); - const events = await this._eventsManager.findManyByCalendarIdsAndRange( + const calendarIdsMap = await calendarsManager.getVisibleCalendarIdsByUserIdMap(user.id); + const events = await eventsManager.findManyByCalendarIdsAndRange( calendarIdsMap, user.id, timezonedFrom, @@ -105,7 +94,7 @@ export class CalendarEntriesManager { const recurrenceTo = to ? new Date(`${to}T23:59:59.999`) : null; if (recurrenceFrom && recurrenceTo) { - const recurringEvents = await this._eventsManager.findManyByCalendarIdsAndRange( + const recurringEvents = await eventsManager.findManyByCalendarIdsAndRange( calendarIdsMap, user.id, timezonedFrom, @@ -139,14 +128,14 @@ export class CalendarEntriesManager { } } - const listIds = await this._listsManager.getVisibleListIdsByUserId(user.id); - const rawTasks = await this._tasksManager.findManyByListIdsAndRange( + const listIds = await listsManager.getVisibleListIdsByUserId(user.id); + const rawTasks = await tasksManager.findManyByListIdsAndRange( listIds, user.id, timezonedFrom, timezonedTo ); - const tasks = await this._tasksManager.populateTagsAndUsers(rawTasks); + const tasks = await tasksManager.populateTagsAndUsers(rawTasks); for (const task of tasks) { // We should never have a task without a due date, // but we need to apease typescript. @@ -338,9 +327,4 @@ export class CalendarEntriesManager { } } -export const calendarEntriesManager = new CalendarEntriesManager( - calendarsManager, - listsManager, - tasksManager, - eventsManager -); +export const calendarEntriesManager = new CalendarEntriesManager();