Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/project-teams/dto/set-project-interest.dto.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator';

export class SetProjectInterestDto {
@ApiProperty({
@ApiPropertyOptional({
example: 'Front-end',
description: 'Cargo da ideia em que a pessoa quer atuar',
description:
'Cargo da ideia em que a pessoa quer atuar. Sem cargo, vale como interesse geral no projeto.',
})
@IsOptional()
@IsString()
@MinLength(2)
@MaxLength(40)
role: string;
role?: string;

@ApiPropertyOptional({
example: 'Tenho 2 anos de React e tempo nos fins de semana.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,27 @@ export class ProjectIdeaRelationalRepository implements ProjectIdeaRepository {
});
const teamByIdea = new Map(teams.map((t) => [t.ideaId, t.id]));

return entities.map((entity) =>
ProjectMapper.ideaToDomain(entity, {
const authorIds = [...new Set(entities.map((entity) => entity.authorId))];
const profiles = await this.interestRepository.manager
.getRepository(GamificationProfileEntity)
.find({
where: { userId: In(authorIds) },
select: { userId: true, username: true },
});
const usernameByUser = new Map(
profiles.map((profile) => [profile.userId, profile.username]),
);

return entities.map((entity) => {
const idea = ProjectMapper.ideaToDomain(entity, {
interestCount: countByIdea.get(entity.id) ?? 0,
teamId: teamByIdea.get(entity.id) ?? null,
}),
);
});
if (idea.author) {
idea.author.username = usernameByUser.get(entity.authorId) ?? null;
}
return idea;
});
}

private async findList(
Expand Down
26 changes: 16 additions & 10 deletions src/project-teams/project-ideas.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
ProjectIdeaStatus.TEAM_FORMED,
];

/** Interesse geral no projeto, sem escolher um cargo. */
const DEFAULT_INTEREST_ROLE = 'Interessado';

@Injectable()
export class ProjectIdeasService {
constructor(
Expand Down Expand Up @@ -218,21 +221,24 @@
dto: SetProjectInterestDto,
) {
const idea = await this.findPublicDetail(id);
const roles = await this.ensureRoles(idea);
if (!roles.some((item) => item.name === dto.role)) {
throw new UnprocessableEntityException({
status: HttpStatus.UNPROCESSABLE_ENTITY,
errors: { role: 'Este cargo não existe neste projeto.' },
});
const role = dto.role?.trim() || DEFAULT_INTEREST_ROLE;
if (dto.role) {
const roles = await this.ensureRoles(idea);
if (!roles.some((item) => item.name === role)) {
throw new UnprocessableEntityException({
status: HttpStatus.UNPROCESSABLE_ENTITY,
errors: { role: 'Este cargo não existe neste projeto.' },
});
}
}

const existing = (
await this.ideaRepository.findUserInterests(id, userId)
).find((item) => item.role === dto.role);
).find((item) => item.role === role);

Check warning on line 237 in src/project-teams/project-ideas.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `.some(…)` over `.find(…)`.

See more on https://sonarcloud.io/project/issues?id=devs-tocantins_api-engajamento2&issues=AaGERwrSxLux756Iqc8b&open=AaGERwrSxLux756Iqc8b&pullRequest=114
const interest = await this.ideaRepository.upsertInterest(
id,
userId,
dto.role,
role,
dto.message?.trim() || null,
);

Expand All @@ -241,8 +247,8 @@
.create({
userId: idea.authorId,
type: NotificationType.PROJECT_IDEA_INTEREST,
title: `Nova participação em: ${idea.title}`,
body: 'Alguém entrou em um cargo do seu projeto. Veja o time na página dele.',
title: `Novo interessado em: ${idea.title}`,
body: 'Alguém quer participar do seu projeto. Veja quem tem interesse na página dele.',
relatedId: idea.id,
link: `/projetos/${idea.id}`,
payload: { ideaId: idea.id, userId },
Expand Down
Loading