Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Members #5

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
11 changes: 0 additions & 11 deletions .env.template
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverter a remoção do .env.template para que sirva de guia a quem posteriormente for executar o projeto localmente.

This file was deleted.

3 changes: 2 additions & 1 deletion src/api-docs/openAPIDocumentGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { OpenAPIRegistry, OpenApiGeneratorV3 } from "@asteasolutions/zod-to-open

import { candidateRegistry } from "@/api/candidate/candidateRouter";
import { healthCheckRegistry } from "@/api/healthCheck/healthCheckRouter";
import { memberRegistry } from "@/api/member/memberRouter";

export function generateOpenAPIDocument() {
const registry = new OpenAPIRegistry([healthCheckRegistry, candidateRegistry]);
const registry = new OpenAPIRegistry([healthCheckRegistry, candidateRegistry, memberRegistry]);
const generator = new OpenApiGeneratorV3(registry.definitions);

return generator.generateDocument({
Expand Down
4 changes: 3 additions & 1 deletion src/api/candidate/candidateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ export class CandidateService {
await this.candidateRepository.updateAsync(id, newCandidateData);
return ServiceResponse.success("Candidate successfully updated.", null, StatusCodes.OK);
} catch (ex) {
const errorMessage = `Error while updating the candidate with id ${id} and their new data ${newCandidateData}:, ${(ex as Error).message}`;
const errorMessage = `Error while updating the candidate with id ${id} and their new data ${newCandidateData}:, ${
(ex as Error).message
}`;
logger.error(errorMessage);
return ServiceResponse.failure(
"An error occurred while updating the candidate.",
Expand Down
36 changes: 36 additions & 0 deletions src/api/member/memberController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { memberService } from "@/api/member/memberService";

import { handleServiceResponse } from "@/common/utils/httpHandlers";
import type { Request, RequestHandler, Response } from "express";

class MemberController {
public createMember: RequestHandler = async (req: Request, res: Response) => {
const serviceResponse = await memberService.create(req.body);
return handleServiceResponse(serviceResponse, res);
};

public getMembers: RequestHandler = async (req: Request, res: Response) => {
const ServerResponse = await memberService.findAll();
return handleServiceResponse(ServerResponse, res);
};

public getMember: RequestHandler = async (req: Request, res: Response) => {
const id = Number.parseInt(req.params.id, 10);
const ServiceResponse = await memberService.findById(id);
return handleServiceResponse(ServiceResponse, res);
};

public updateMember: RequestHandler = async (req: Request, res: Response) => {
const id = Number.parseInt(req.params.id, 10);
const ServiceResponse = await memberService.update(id, req.body);
return handleServiceResponse(ServiceResponse, res);
};

public deleteMember: RequestHandler = async (req: Request, res: Response) => {
const id = Number.parseInt(req.params.id, 10);
const serviceResponse = await memberService.delete(id);
return handleServiceResponse(serviceResponse, res);
};
}

export const memberController = new MemberController();
109 changes: 109 additions & 0 deletions src/api/member/memberModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { commonValidations, commonValidationsMembers } from "@/common/utils/commonValidation";
import { z } from "zod";

export type Member = z.infer<typeof MemberSchema>;
export const MemberSchema = z.object({
id: z.number(),
name: z.string().max(50),
professional_profile_url: z.array(
z.object({
platform: z.string().max(50),
url: z.string().url(),
}),
),
stack: z.enum(["frontend", "backend", "full-stack", "UX Designer"]),
community_level: z.string().max(50),
current_squad: z.string().max(50),
skills: z.array(z.string()),
projects: z.array(
z.object({
project_cover: z.string(),
project_name: z.string().max(50),
description: z.string().max(500),
technologies_used: z.array(z.string()),
project_url: z.string().url(),
}),
),
softskills: z.array(z.string()),
});

export type CreateMemberDto = z.infer<typeof CreateMemberDtoSchema>;
export const CreateMemberDtoSchema = z.object({
name: z.string().max(50),
professional_profile_url: z.array(
z.object({
platform: z.string().max(50),
url: z.string().url(),
}),
),
stack: z.enum(["frontend", "backend", "full-stack", "UX Designer"]),
community_level: z.string().max(50),
current_squad: z.string().max(50),
skills: z.array(z.string()),
projects: z.array(
z.object({
project_cover: z.string(),
project_name: z.string().max(50),
description: z.string().max(500),
technologies_used: z.array(z.string()),
project_url: z.string().url(),
}),
),
softskills: z.array(z.string()),
});

export type UpdateMemberDto = z.infer<typeof UpdateMemberDtoSchema>;
export const UpdateMemberDtoSchema = z.object({
name: z.string().max(50),
professional_profile_url: z.array(
z.object({
platform: z.string().max(50),
url: z.string().url(),
}),
),
stack: z.enum(["frontend", "backend", "full-stack", "UX Designer"]),
community_level: z.string().max(50),
current_squad: z.string().max(50),
skills: z.array(z.string()),
projects: z.array(
z.object({
project_cover: z.string(),
project_name: z.string().max(50),
description: z.string().max(500),
technologies_used: z.array(z.string()),
project_url: z.string().url(),
}),
),
softskills: z.array(z.string()),
});

export const CreateMemberSchema = z.object({
body: z.object({
name: commonValidationsMembers.name,
professional_profile_url: commonValidationsMembers.professional_profile_url,
stack: commonValidationsMembers.stack,
community_level: commonValidationsMembers.community_level,
current_squad: commonValidationsMembers.current_squad,
skills: commonValidationsMembers.skills,
projects: commonValidationsMembers.projects,
softskills: commonValidationsMembers.softskills,
}),
});

export const GetMemberSchema = z.object({
params: z.object({ id: commonValidationsMembers.id }),
});

export const UpdateMemberSchema = z.object({
params: z.object({ id: commonValidationsMembers.id }),
body: z.object({
name: commonValidationsMembers.name,
professional_profile_url: commonValidationsMembers.professional_profile_url,
stack: commonValidationsMembers.stack,
community_level: commonValidationsMembers.community_level,
current_squad: commonValidationsMembers.current_squad,
skills: commonValidationsMembers.skills,
projects: commonValidationsMembers.projects,
softskills: commonValidationsMembers.softskills,
}),
});
91 changes: 91 additions & 0 deletions src/api/member/memberRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import type { CreateMemberDto, Member, UpdateMemberDto } from "@/api/member/memberModel";

export let members: Member[] = [
{
id: 1,
name: "Alice",
professional_profile_url: [
{ platform: "GitHub", url: "<https://github.com/johndoe>" },
{ platform: "LinkedIn", url: "<https://linkedin.com/in/johndoe>" },
],
stack: "backend",
community_level: "code wizard",
current_squad: "X-mens",
skills: ["HTML", "CSS", "JavaScript", "React", "Node.js", "Git", "Docker"],
projects: [
{
project_cover: "https://project1.pg",
project_name: "Personal Portfolio",
description: "A personal portfolio website built with React and hosted on GitHub.",
technologies_used: ["React", "CSS", "JavaScript"],
project_url: "<https://github.com/johndoe/portfolio>",
},
{
project_cover: "https://project1.pg",
project_name: "E-commerce Website",
description: "An online store platform with payment integration, built with Node.js and MongoDB.",
technologies_used: ["Node.js", "Express", "MongoDB"],
project_url: "<https://github.com/johndoe/ecommerce>",
},
],
softskills: ["Communication", "Problem-solving", "Teamwork", "Adaptability", "Time management"],
},
{
id: 2,
name: "Pedro",
professional_profile_url: [
{ platform: "GitHub", url: "<https://github.com/johndoe>" },
{ platform: "LinkedIn", url: "<https://linkedin.com/in/johndoe>" },
],
stack: "full-stack",
community_level: "code wizard",
current_squad: "marvels",
skills: ["HTML", "CSS", "JavaScript", "React", "Node.js", "Git", "Docker", "Prisma", "NestJS"],
projects: [
{
project_cover: "https://project1.pg",
project_name: "Personal Portfolio",
description: "A personal portfolio website built with React and hosted on GitHub.",
technologies_used: ["React", "CSS", "JavaScript"],
project_url: "<https://github.com/johndoe/portfolio>",
},
{
project_cover: "https://project1.pg",
project_name: "E-commerce Website",
description: "An online store platform with payment integration, built with Node.js and MongoDB.",
technologies_used: ["Node.js", "Express", "MongoDB"],
project_url: "<https://github.com/johndoe/ecommerce>",
},
],
softskills: ["Communication", "Problem-solving", "Teamwork", "Adaptability", "Time management"],
},
];

export class MemberRepository {
async createAsync(memberToBeCreated: CreateMemberDto): Promise<Member> {
const newMember: Member = {
id: Date.now(),
...memberToBeCreated,
};
members.push(newMember);
return newMember;
}

async findAllAsync(): Promise<Member[] | null> {
return members;
}

async findByIdAsync(id: number): Promise<Member | null> {
return members.find((member) => member.id === id) || null;
}

async updateAsync(id: number, newMemberData: UpdateMemberDto) {
members = members.map((member) =>
member.id === id ? { ...member, ...newMemberData, updatedAt: new Date() } : member,
);
}

async deleteAsync(id: number) {
members = members.filter((member) => member.id !== id);
}
}
Loading
Loading