-
Notifications
You must be signed in to change notification settings - Fork 3
F25/nathanael/onboarding: Complete onboarding task implementation #140
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
backend/typescript/middlewares/validators/teamMemberValidators.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { Request, Response, NextFunction } from "express"; | ||
| import { getApiValidationError, validatePrimitive } from "./util"; | ||
|
|
||
| /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
| /* eslint-disable-next-line import/prefer-default-export */ | ||
| export const createTeamMemberDtoValidator = async ( | ||
| req: Request, | ||
| res: Response, | ||
| next: NextFunction, | ||
| ) => { | ||
| if (!validatePrimitive(req.body.firstName, "string")) { | ||
| return res.status(400).send(getApiValidationError("firstName", "string")); | ||
| } | ||
| if (!validatePrimitive(req.body.lastName, "string")) { | ||
| return res.status(400).send(getApiValidationError("lastName", "string")); | ||
| } | ||
| if (!validatePrimitive(req.body.teamRole, "string")) { | ||
| return res.status(400).send(getApiValidationError("teamRole", "string")); | ||
| } | ||
| return next(); | ||
| }; |
1 change: 0 additions & 1 deletion
1
...typescript/migrations/2024.11.21T16.49.50.add-constraint-behaviour-level-details-table.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
backend/typescript/migrations/2025.09.24T01.30.28.create-table-team-members.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { DataType } from "sequelize-typescript"; | ||
| import { Migration } from "../umzug"; | ||
| import { teamRoleValues } from "../types"; | ||
|
|
||
| const TABLE_NAME = "team_members"; | ||
|
|
||
| export const up: Migration = async ({ context: sequelize }) => { | ||
| await sequelize.getQueryInterface().createTable(TABLE_NAME, { | ||
| id: { | ||
| type: DataType.INTEGER, | ||
| allowNull: false, | ||
| primaryKey: true, | ||
| autoIncrement: true, | ||
| }, | ||
| first_name: { | ||
| type: DataType.STRING, | ||
| allowNull: false, | ||
| }, | ||
| last_name: { | ||
| type: DataType.STRING, | ||
| allowNull: false, | ||
| }, | ||
| team_role: { | ||
| type: DataType.ENUM, | ||
| values: teamRoleValues as unknown as string[], | ||
| allowNull: false, | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| export const down: Migration = async ({ context: sequelize }) => { | ||
| await sequelize.getQueryInterface().dropTable(TABLE_NAME); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { | ||
| Column, | ||
| DataType, | ||
| Model, | ||
| Table, | ||
| AllowNull, | ||
| } from "sequelize-typescript"; | ||
| import { TeamRole, teamRoleValues } from "../types"; | ||
|
|
||
| @Table({ timestamps: false, tableName: "team_members" }) | ||
| export default class TeamMember extends Model { | ||
| @Column({ type: DataType.STRING, allowNull: false }) | ||
| first_name!: string; | ||
|
|
||
| @Column({ type: DataType.STRING, allowNull: false }) | ||
| last_name!: string; | ||
|
|
||
| @AllowNull(false) | ||
| @Column({ type: DataType.ENUM, values: teamRoleValues, allowNull: false }) | ||
| team_role!: TeamRole; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { Router } from "express"; | ||
| import TeamMemberService from "../services/implementations/teamMemberService"; | ||
| import { getErrorMessage } from "../utilities/errorUtils"; | ||
| import { CreateTeamMemberDTO } from "../types"; | ||
| import { createTeamMemberDtoValidator } from "../middlewares/validators/teamMemberValidators"; | ||
|
|
||
| const teamMemberRouter: Router = Router(); | ||
| const teamMemberService = new TeamMemberService(); | ||
|
|
||
| teamMemberRouter.get("/", async (req, res) => { | ||
| try { | ||
| const teamMembers = await teamMemberService.getTeamMembers(); | ||
| res.status(200).json(teamMembers); | ||
| } catch (error: unknown) { | ||
| res.status(500).json({ error: getErrorMessage(error) }); | ||
| } | ||
| }); | ||
|
|
||
| teamMemberRouter.post("/", createTeamMemberDtoValidator, async (req, res) => { | ||
| const data: CreateTeamMemberDTO = req.body; | ||
| try { | ||
| const newTeamMember = await teamMemberService.createTeamMember(data); | ||
| res.status(201).json(newTeamMember); | ||
| } catch (error: unknown) { | ||
| res.status(500).json({ error: getErrorMessage(error) }); | ||
| } | ||
| }); | ||
|
|
||
| export default teamMemberRouter; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
backend/typescript/services/implementations/teamMemberService.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import PgTeamMember from "../../models/teamMember.model"; | ||
| import ITeamMemberService from "../interfaces/teamMemberService"; | ||
| import { TeamMemberDTO, CreateTeamMemberDTO } from "../../types"; | ||
| import { getErrorMessage } from "../../utilities/errorUtils"; | ||
| import logger from "../../utilities/logger"; | ||
|
|
||
| const Logger = logger(__filename); | ||
|
|
||
| class TeamMemberService implements ITeamMemberService { | ||
| /* eslint-disable class-methods-use-this */ | ||
| async getTeamMembers(): Promise<TeamMemberDTO[]> { | ||
| try { | ||
| const teamMembers: Array<PgTeamMember> = await PgTeamMember.findAll(); | ||
| return teamMembers.map((teamMember) => ({ | ||
| id: String(teamMember.id), | ||
| firstName: teamMember.first_name, | ||
| lastName: teamMember.last_name, | ||
| teamRole: teamMember.team_role, | ||
| })); | ||
| } catch (error: unknown) { | ||
| Logger.error( | ||
| `Failed to get team members. Reason = ${getErrorMessage(error)}`, | ||
| ); | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| async createTeamMember( | ||
| teamMember: CreateTeamMemberDTO, | ||
| ): Promise<TeamMemberDTO> { | ||
| let newTeamMember: PgTeamMember | null; | ||
| try { | ||
| newTeamMember = await PgTeamMember.create({ | ||
| first_name: teamMember.firstName, | ||
| last_name: teamMember.lastName, | ||
| team_role: teamMember.teamRole, | ||
| }); | ||
| } catch (error: unknown) { | ||
| Logger.error( | ||
| `Failed to create team member. Reason = ${getErrorMessage(error)}`, | ||
| ); | ||
| throw error; | ||
| } | ||
| return { | ||
| id: String(newTeamMember.id), | ||
| firstName: newTeamMember.first_name, | ||
| lastName: newTeamMember.last_name, | ||
| teamRole: newTeamMember.team_role, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| export default TeamMemberService; |
20 changes: 20 additions & 0 deletions
20
backend/typescript/services/interfaces/teamMemberService.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { CreateTeamMemberDTO, TeamMemberDTO } from "../../types"; | ||
|
|
||
| interface ITeamMemberService { | ||
| /** | ||
| * Get all team member information | ||
| * @returns array of TeamMemberDTO | ||
| * @throws Error if team member retrieval fails | ||
| */ | ||
| getTeamMembers(): Promise<TeamMemberDTO[]>; | ||
|
|
||
| /** | ||
| * Create a team member | ||
| * @param teamMember the team member to be created | ||
| * @returns a TeamMemberDTO with the created team member's information | ||
| * @throws Error if team member creation fails | ||
| */ | ||
| createTeamMember(teamMember: CreateTeamMemberDTO): Promise<TeamMemberDTO>; | ||
| } | ||
|
|
||
| export default ITeamMemberService; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { TeamMember, TeamRole } from "../types/TeamMembersTypes"; | ||
| import baseAPIClient from "./BaseAPIClient"; | ||
|
|
||
| // Fetch all team members | ||
| const get = async (): Promise<TeamMember[] | null> => { | ||
| try { | ||
| const { data } = await baseAPIClient.get("team-members/"); | ||
| return data; | ||
| } catch (error: unknown) { | ||
| // eslint-disable-next-line no-console | ||
| console.error("Error fetching team members:", error); | ||
| return null; | ||
| } | ||
| }; | ||
|
|
||
| // Add a new team member | ||
| const create = async ( | ||
| firstName: string, | ||
| lastName: string, | ||
| teamRole: TeamRole, | ||
| ): Promise<TeamMember[] | null> => { | ||
| try { | ||
| const { data } = await baseAPIClient.post("team-members/", { | ||
| firstName, | ||
| lastName, | ||
| teamRole, | ||
| }); | ||
| return data; | ||
| } catch (error: unknown) { | ||
| // eslint-disable-next-line no-console | ||
| console.error("Error creating team member:", error); | ||
| return null; | ||
| } | ||
| }; | ||
|
|
||
| export default { get, create }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import React, { useEffect, useState } from "react"; | ||
| import { | ||
| Table, | ||
| Thead, | ||
| Tbody, | ||
| Tr, | ||
| Th, | ||
| Td, | ||
| TableContainer, | ||
| VStack, | ||
| Button, | ||
| } from "@chakra-ui/react"; | ||
| import TeamMembersAPIClient from "../../APIClients/TeamMembersAPIClient"; | ||
| import { TeamMember } from "../../types/TeamMembersTypes"; | ||
|
|
||
| const TeamMembersPage = (): React.ReactElement => { | ||
| const [teamMembers, setTeamMembers] = useState<TeamMember[]>([]); | ||
|
|
||
| // Fetch team members | ||
| const getTeamMembers = async () => { | ||
| const teamMembersData = await TeamMembersAPIClient.get(); | ||
| if (teamMembersData) { | ||
| setTeamMembers(teamMembersData); | ||
| } | ||
| }; | ||
|
|
||
| // Add a hardcoded team member | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great understanding of the task |
||
| const addTeamMember = async () => { | ||
| await TeamMembersAPIClient.create("Jerry", "Cheng", "PL"); | ||
| await getTeamMembers(); // refresh the table after adding | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| getTeamMembers(); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <VStack spacing="24px" style={{ margin: "24px auto" }}> | ||
| <h1>Team Members Page</h1> | ||
| <TableContainer> | ||
| <Table colorScheme="blue"> | ||
| <Thead> | ||
| <Tr> | ||
| <Th>First Name</Th> | ||
| <Th>Last Name</Th> | ||
| <Th>Team Role</Th> | ||
| </Tr> | ||
| </Thead> | ||
| <Tbody> | ||
| {teamMembers.map((teamMember, index) => ( | ||
| <Tr key={index}> | ||
| <Td>{teamMember.firstName}</Td> | ||
| <Td>{teamMember.lastName}</Td> | ||
| <Td>{teamMember.teamRole}</Td> | ||
| </Tr> | ||
| ))} | ||
| </Tbody> | ||
| </Table> | ||
| </TableContainer> | ||
| <Button colorScheme="blue" onClick={addTeamMember}> | ||
| + Add a Jerry | ||
| </Button> | ||
| </VStack> | ||
| ); | ||
| }; | ||
|
|
||
| export default TeamMembersPage; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
watch out for linting warnings