Skip to content

Commit

Permalink
Merge pull request #151 from Carifio24/expected-class-size
Browse files Browse the repository at this point in the history
Add expected size to class
  • Loading branch information
Carifio24 authored Oct 16, 2024
2 parents d8ae1fc + c54272c commit 72ff314
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export async function signUpStudent(options: SignUpStudentOptions): Promise<Sign
export const CreateClassSchema = S.struct({
educator_id: S.number,
name: S.string,
expected_size: S.number.pipe(S.int()),
});

export type CreateClassOptions = S.Schema.To<typeof CreateClassSchema>;
Expand Down
7 changes: 6 additions & 1 deletion src/models/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class Class extends Model<InferAttributes<Class>, InferCreationAttributes
declare code: string;
declare asynchronous: CreationOptional<boolean>;
declare test: CreationOptional<boolean>;
declare expected_size: CreationOptional<number>;
}

export function initializeClassModel(sequelize: Sequelize) {
Expand Down Expand Up @@ -61,7 +62,11 @@ export function initializeClassModel(sequelize: Sequelize) {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: 0
}
},
expected_size: {
type: DataTypes.INTEGER.UNSIGNED,
allowNull: false,
},
}, {
sequelize,
});
Expand Down
1 change: 1 addition & 0 deletions src/sql/create_class_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CREATE TABLE Classes (
asynchronous tinyint(1) NOT NULL DEFAULT 0,
test tinyint(1) NOT NULL DEFAULT 0,
updated datetime DEFAULT NULL,
expected_size int(11) UNSIGNED NOT NULL,

PRIMARY KEY(id),
INDEX(educator_id),
Expand Down
2 changes: 1 addition & 1 deletion tests/educators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { Express } from "express";

import { authorize, getTestDatabaseConnection } from "./utils";
import { setupApp } from "../src/app";
import { Class, Educator, Student, StudentsClasses } from "../src/models";
import { Educator } from "../src/models";
import { createApp } from "../src/server";
import { v4 } from "uuid";

Expand Down
2 changes: 2 additions & 0 deletions tests/students.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ async function setupStudentInClasses() {
name: v4(),
educator_id: educator.id,
code: v4(),
expected_size: 1,
});
const class2 = await Class.create({
name: v4(),
educator_id: educator.id,
code: v4(),
expected_size: 1,
});
const student = await Student.create({
email: v4(),
Expand Down

0 comments on commit 72ff314

Please sign in to comment.