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
72 changes: 72 additions & 0 deletions src/database/migrations/1787300000000-ProjectIdeaRoles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

const LABELS: Record<string, string> = {
FRONTEND: 'Front-end',
BACKEND: 'Back-end',
DATABASE: 'Banco de dados',
REQUIREMENTS_ANALYST: 'Analista de requisitos',
UX_DESIGNER: 'UX/UI Designer',
QA: 'QA / Testes',
DEVOPS: 'DevOps',
MOBILE: 'Mobile',
PROJECT_MANAGER: 'Gerente de projeto',
};

export class ProjectIdeaRoles1787300000000 implements MigrationInterface {
name = 'ProjectIdeaRoles1787300000000';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "project_idea_role" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "ideaId" uuid NOT NULL, "name" character varying(40) NOT NULL, "position" integer NOT NULL DEFAULT 0, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_project_idea_role_id" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE UNIQUE INDEX "IDX_project_idea_role_ideaId_name" ON "project_idea_role" ("ideaId", "name")`,
);
await queryRunner.query(
`ALTER TABLE "project_idea_role" ADD CONSTRAINT "FK_project_idea_role_ideaId" FOREIGN KEY ("ideaId") REFERENCES "project_idea"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);

// O cargo da participação passa a ser o nome do cargo da ideia.
const cases = Object.entries(LABELS)
.map(([key, label]) => `WHEN '${key}' THEN '${label}'`)
.join(' ');
await queryRunner.query(
`ALTER TABLE "project_idea_interest" ALTER COLUMN "role" TYPE character varying(40) USING (CASE "role"::text ${cases} ELSE "role"::text END)`,
);

// Cada pessoa pode participar de vários cargos da mesma ideia.
await queryRunner.query(
`DROP INDEX IF EXISTS "public"."IDX_project_idea_interest_ideaId_userId"`,
);
await queryRunner.query(
`CREATE UNIQUE INDEX "IDX_project_idea_interest_ideaId_userId_role" ON "project_idea_interest" ("ideaId", "userId", "role")`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX IF EXISTS "public"."IDX_project_idea_interest_ideaId_userId_role"`,
);
// Mantém só uma participação por pessoa e descarta cargos personalizados.
const reverse = Object.entries(LABELS)
.map(([key, label]) => `WHEN '${label}' THEN '${key}'`)
.join(' ');
await queryRunner.query(
`DELETE FROM "project_idea_interest" WHERE "role" NOT IN (${Object.values(
LABELS,
)
.map((label) => `'${label}'`)
.join(', ')})`,
);
await queryRunner.query(
`DELETE FROM "project_idea_interest" a USING "project_idea_interest" b WHERE a."ideaId" = b."ideaId" AND a."userId" = b."userId" AND a."createdAt" > b."createdAt"`,
);
await queryRunner.query(
`ALTER TABLE "project_idea_interest" ALTER COLUMN "role" TYPE "public"."project_role_enum" USING (CASE "role" ${reverse} END)::"public"."project_role_enum"`,
);
await queryRunner.query(
`CREATE UNIQUE INDEX "IDX_project_idea_interest_ideaId_userId" ON "project_idea_interest" ("ideaId", "userId")`,
);
await queryRunner.query(`DROP TABLE "project_idea_role"`);
}
}
18 changes: 16 additions & 2 deletions src/project-teams/domain/project-idea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export class ProjectIdeaInterest {
@ApiProperty({ type: () => ProjectUserSummary, nullable: true })
user?: ProjectUserSummary | null;

@ApiProperty({ enum: ProjectRole })
role: ProjectRole;
@ApiProperty({ type: String, description: 'Nome do cargo na ideia' })
role: string;

@ApiProperty({ type: String, nullable: true })
message: string | null;
Expand All @@ -90,3 +90,17 @@ export class SuggestedVacancy {
@ApiProperty({ type: String })
reason: string;
}

export class ProjectIdeaRole {
@ApiProperty({ type: String })
id: string;

@ApiProperty({ type: String })
ideaId: string;

@ApiProperty({ type: String })
name: string;

@ApiProperty({ type: Number })
position: number;
}
13 changes: 13 additions & 0 deletions src/project-teams/domain/project-role.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,16 @@ export enum ProjectRole {
MOBILE = 'MOBILE',
PROJECT_MANAGER = 'PROJECT_MANAGER',
}

/** Nomes (pt-BR) usados como cargos padrão de uma ideia. */
export const PROJECT_ROLE_LABELS: Record<ProjectRole, string> = {
[ProjectRole.FRONTEND]: 'Front-end',
[ProjectRole.BACKEND]: 'Back-end',
[ProjectRole.DATABASE]: 'Banco de dados',
[ProjectRole.REQUIREMENTS_ANALYST]: 'Analista de requisitos',
[ProjectRole.UX_DESIGNER]: 'UX/UI Designer',
[ProjectRole.QA]: 'QA / Testes',
[ProjectRole.DEVOPS]: 'DevOps',
[ProjectRole.MOBILE]: 'Mobile',
[ProjectRole.PROJECT_MANAGER]: 'Gerente de projeto',
};
3 changes: 3 additions & 0 deletions src/project-teams/domain/project-user-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export class ProjectUserSummary {
@ApiProperty({ type: String, nullable: true })
lastName: string | null;

@ApiProperty({ type: String, nullable: true })
username?: string | null;

@ApiProperty({ type: () => FileType, nullable: true })
photo?: FileType | null;
}
10 changes: 10 additions & 0 deletions src/project-teams/dto/create-project-idea-role.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, MaxLength, MinLength } from 'class-validator';

export class CreateProjectIdeaRoleDto {
@ApiProperty({ example: 'Mentor' })
@IsString()
@MinLength(2)
@MaxLength(40)
name: string;
}
14 changes: 7 additions & 7 deletions src/project-teams/dto/set-project-interest.dto.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsOptional, IsString, MaxLength } from 'class-validator';
import { ProjectRole } from '../domain/project-role.enum';
import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator';

export class SetProjectInterestDto {
@ApiProperty({
enum: ProjectRole,
example: ProjectRole.FRONTEND,
description: 'Cargo em que a pessoa gostaria de atuar',
example: 'Front-end',
description: 'Cargo da ideia em que a pessoa quer atuar',
})
@IsEnum(ProjectRole)
role: ProjectRole;
@IsString()
@MinLength(2)
@MaxLength(40)
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
@@ -1,8 +1,11 @@
import { NullableType } from '../../../utils/types/nullable.type';
import { IPaginationOptions } from '../../../utils/types/pagination-options';
import { ProjectIdea, ProjectIdeaInterest } from '../../domain/project-idea';
import {
ProjectIdea,
ProjectIdeaInterest,
ProjectIdeaRole,
} from '../../domain/project-idea';
import { ProjectIdeaStatus } from '../../domain/project-idea-status.enum';
import { ProjectRole } from '../../domain/project-role.enum';

export type ProjectIdeaUpdate = Partial<
Pick<
Expand Down Expand Up @@ -52,21 +55,41 @@ export abstract class ProjectIdeaRepository {
abstract upsertInterest(
ideaId: ProjectIdea['id'],
userId: number,
role: ProjectRole,
role: string,
message: string | null,
): Promise<ProjectIdeaInterest>;

/** Sem `role`, remove a participação da pessoa em todos os cargos. */
abstract removeInterest(
ideaId: ProjectIdea['id'],
userId: number,
role?: string,
): Promise<void>;

abstract findInterest(
ideaId: ProjectIdea['id'],
userId: number,
): Promise<NullableType<ProjectIdeaInterest>>;

abstract findUserInterests(
ideaId: ProjectIdea['id'],
userId: number,
): Promise<ProjectIdeaInterest[]>;

abstract findInterests(
ideaId: ProjectIdea['id'],
): Promise<ProjectIdeaInterest[]>;

abstract findRoles(ideaId: ProjectIdea['id']): Promise<ProjectIdeaRole[]>;

abstract addRoles(
ideaId: ProjectIdea['id'],
names: string[],
): Promise<ProjectIdeaRole[]>;

/** Remove o cargo e as participações nele. Retorna false se não existir. */
abstract removeRole(
ideaId: ProjectIdea['id'],
roleId: ProjectIdeaRole['id'],
): Promise<boolean>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import {
} from 'typeorm';
import { EntityRelationalHelper } from '../../../../../utils/relational-entity-helper';
import { UserEntity } from '../../../../../users/infrastructure/persistence/relational/entities/user.entity';
import { ProjectRole } from '../../../../domain/project-role.enum';
import { ProjectIdeaEntity } from './project-idea.entity';

@Entity({ name: 'project_idea_interest' })
@Index(['ideaId', 'userId'], { unique: true })
@Index(['ideaId', 'userId', 'role'], { unique: true })
export class ProjectIdeaInterestEntity extends EntityRelationalHelper {
@PrimaryGeneratedColumn('uuid')
id: string;
Expand All @@ -32,8 +31,8 @@ export class ProjectIdeaInterestEntity extends EntityRelationalHelper {
@JoinColumn({ name: 'userId' })
user: UserEntity;

@Column({ type: 'enum', enum: ProjectRole, enumName: 'project_role_enum' })
role: ProjectRole;
@Column({ type: 'varchar', length: 40 })
role: string;

@Column({ type: 'text', nullable: true, default: null })
message: string | null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
Column,
CreateDateColumn,
Entity,
Index,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { EntityRelationalHelper } from '../../../../../utils/relational-entity-helper';
import { ProjectIdeaEntity } from './project-idea.entity';

@Entity({ name: 'project_idea_role' })
@Index(['ideaId', 'name'], { unique: true })
export class ProjectIdeaRoleEntity extends EntityRelationalHelper {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ type: 'uuid' })
ideaId: string;

@ManyToOne(() => ProjectIdeaEntity, { eager: false, onDelete: 'CASCADE' })
@JoinColumn({ name: 'ideaId' })
idea: ProjectIdeaEntity;

@Column({ type: 'varchar', length: 40 })
name: string;

@Column({ type: 'int', default: 0 })
position: number;

@CreateDateColumn()
createdAt: Date;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UserEntity } from '../../../../../users/infrastructure/persistence/rela
import {
ProjectIdea,
ProjectIdeaInterest,
ProjectIdeaRole,
} from '../../../../domain/project-idea';
import {
ProjectTeam,
Expand All @@ -11,6 +12,7 @@ import {
} from '../../../../domain/project-team';
import { ProjectUserSummary } from '../../../../domain/project-user-summary';
import { ProjectIdeaEntity } from '../entities/project-idea.entity';
import { ProjectIdeaRoleEntity } from '../entities/project-idea-role.entity';
import { ProjectIdeaInterestEntity } from '../entities/project-idea-interest.entity';
import { ProjectTeamEntity } from '../entities/project-team.entity';

Expand Down Expand Up @@ -49,6 +51,15 @@ export class ProjectMapper {
return idea;
}

static ideaRoleToDomain(raw: ProjectIdeaRoleEntity): ProjectIdeaRole {
const role = new ProjectIdeaRole();
role.id = raw.id;
role.ideaId = raw.ideaId;
role.name = raw.name;
role.position = raw.position;
return role;
}

static interestToDomain(raw: ProjectIdeaInterestEntity): ProjectIdeaInterest {
const interest = new ProjectIdeaInterest();
interest.id = raw.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { ProjectIdeaRepository } from '../project-idea.repository';
import { ProjectTeamRepository } from '../project-team.repository';
import { ProjectIdeaEntity } from './entities/project-idea.entity';
import { ProjectIdeaRoleEntity } from './entities/project-idea-role.entity';
import { ProjectIdeaInterestEntity } from './entities/project-idea-interest.entity';
import { ProjectTeamEntity } from './entities/project-team.entity';
import { ProjectTeamMemberEntity } from './entities/project-team-member.entity';
Expand All @@ -15,6 +16,7 @@ import { ProjectTeamRelationalRepository } from './repositories/project-team.rep
TypeOrmModule.forFeature([
ProjectIdeaEntity,
ProjectIdeaInterestEntity,
ProjectIdeaRoleEntity,
ProjectTeamEntity,
ProjectTeamVacancyEntity,
ProjectTeamMemberEntity,
Expand Down
Loading
Loading