refactor(core): Decouple lifecycle events from internal hooks (no-changelog) (#10305)

This commit is contained in:
Iván Ovejero
2024-08-07 16:09:42 +02:00
committed by GitHub
parent b232831f18
commit 9b977e80f6
11 changed files with 129 additions and 119 deletions

View File

@@ -10,7 +10,6 @@ import type { User } from '@db/entities/User';
import type { SettingsRepository } from '@db/repositories/settings.repository';
import type { UserRepository } from '@db/repositories/user.repository';
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import type { InternalHooks } from '@/InternalHooks';
import { License } from '@/License';
import type { OwnerRequest } from '@/requests';
import type { UserService } from '@/services/user.service';
@@ -21,7 +20,6 @@ import { badPasswords } from '@test/testData';
describe('OwnerController', () => {
const configGetSpy = jest.spyOn(config, 'getEnv');
const internalHooks = mock<InternalHooks>();
const authService = mock<AuthService>();
const userService = mock<UserService>();
const userRepository = mock<UserRepository>();
@@ -29,7 +27,7 @@ describe('OwnerController', () => {
mockInstance(License).isWithinUsersLimit.mockReturnValue(true);
const controller = new OwnerController(
mock(),
internalHooks,
mock(),
settingsRepository,
authService,
userService,

View File

@@ -13,13 +13,13 @@ import { PostHogClient } from '@/posthog';
import { UserService } from '@/services/user.service';
import { Logger } from '@/Logger';
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import { InternalHooks } from '@/InternalHooks';
import { EventService } from '@/events/event.service';
@RestController('/owner')
export class OwnerController {
constructor(
private readonly logger: Logger,
private readonly internalHooks: InternalHooks,
private readonly eventService: EventService,
private readonly settingsRepository: SettingsRepository,
private readonly authService: AuthService,
private readonly userService: UserService,
@@ -85,7 +85,7 @@ export class OwnerController {
this.authService.issueCookie(res, owner, req.browserId);
this.internalHooks.onInstanceOwnerSetup({ user_id: owner.id });
this.eventService.emit('instance-owner-setup', { userId: owner.id });
return await this.userService.toPublic(owner, { posthog: this.postHog, withScopes: true });
}