Skip to content
Closed
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
23 changes: 23 additions & 0 deletions backend/typescript/middlewares/validators/teamMemberValidators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// validate paramters passed to the POST endpoint
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 */
// does it exist and is it a string? return 400 bad request
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();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { DataTypes } from "sequelize";
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: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
first_name: {
type: DataTypes.STRING,
allowNull: false,
},
last_name: {
type: DataTypes.STRING,
allowNull: false,
},
team_role: {
type: DataTypes.ENUM(...teamRoleValues),
allowNull: false,
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: new Date(),
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: new Date(),
},
});
};

export const down: Migration = async ({ context: sequelize }) => {
await sequelize.getQueryInterface().dropTable(TABLE_NAME);
};
5 changes: 3 additions & 2 deletions backend/typescript/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from "path";
import { Sequelize } from "sequelize-typescript";
import User from "./user.model";
import TeamMember from "./teamMember.model";
// import defineRelationships from "./modelRelationships";

const DATABASE_URL =
Expand All @@ -14,8 +15,8 @@ const sequelize = new Sequelize(DATABASE_URL, {
models: [path.join(__dirname, "/*.model.ts")],
});

sequelize.addModels([User]);
sequelize.addModels([User, TeamMember]);

// defineRelationships();

export { sequelize, User };
export { sequelize, User, TeamMember };
23 changes: 23 additions & 0 deletions backend/typescript/models/teamMember.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// model is how backend code represents a database table
import {
Table,
Column,
Model,
DataType,
AllowNull,
} from "sequelize-typescript";
import { TeamRole, teamRoleValues } from "../types";

@Table({ timestamps: false, tableName: "team_members"}) // lets sequelize know to not auto create a created_at and updated_at field
export default class TeamMember extends Model {
@Column({ type: DataType.STRING, allowNull: false})
first_name!: string; //! to ensure the property is not nullable

@Column({type: DataType.STRING, allowNull: false})
last_name! : string;

@AllowNull(false)
@Column({ type: DataType.ENUM, values: teamRoleValues, allowNull: false})
team_role!: TeamRole;
}

Loading