This commit is contained in:
2025-12-16 21:05:01 +01:00
parent f61e3a4e5a
commit 7532c7ed6d
207 changed files with 7861 additions and 2606 deletions

View File

@@ -1,25 +1,29 @@
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { ITeamRepository } from '../../domain/repositories/ITeamRepository';
import type { ITeamMembershipRepository } from '../../domain/repositories/ITeamMembershipRepository';
import type { UpdateTeamCommandDTO } from '../dto/TeamCommandAndQueryDTO';
type UpdateTeamErrorCode = 'INSUFFICIENT_PERMISSIONS' | 'TEAM_NOT_FOUND';
export class UpdateTeamUseCase {
constructor(
private readonly teamRepository: ITeamRepository,
private readonly membershipRepository: ITeamMembershipRepository,
) {}
async execute(command: UpdateTeamCommandDTO): Promise<void> {
async execute(command: UpdateTeamCommandDTO): Promise<Result<void, ApplicationErrorCode<UpdateTeamErrorCode>>> {
const { teamId, updates, updatedBy } = command;
const updaterMembership = await this.membershipRepository.getMembership(teamId, updatedBy);
if (!updaterMembership || (updaterMembership.role !== 'owner' && updaterMembership.role !== 'manager')) {
throw new Error('Only owners and managers can update team info');
return Result.err({ code: 'INSUFFICIENT_PERMISSIONS' });
}
const existing = await this.teamRepository.findById(teamId);
if (!existing) {
throw new Error('Team not found');
return Result.err({ code: 'TEAM_NOT_FOUND' });
}
const updated = existing.update({
@@ -30,5 +34,7 @@ export class UpdateTeamUseCase {
});
await this.teamRepository.update(updated);
return Result.ok(undefined);
}
}