Skip to content

Commit

Permalink
Solos, remove skillsets, and much more... :)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoerlitz committed Nov 10, 2023
1 parent c35903c commit cbef768
Show file tree
Hide file tree
Showing 36 changed files with 641 additions and 304 deletions.
60 changes: 60 additions & 0 deletions db/migrations/20221115171243-create-user-solos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const { DataType } = require("sequelize-typescript");

const UserSolosModelAttributes = {
id: {
type: DataType.INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_id: {
unique: true,
type: DataType.INTEGER,
allowNull: false,
references: {
model: "users",
key: "id",
},
onUpdate: "cascade",
onDelete: "cascade",
},
created_by: {
type: DataType.INTEGER,
allowNull: true,
references: {
model: "users",
key: "id",
},
onUpdate: "cascade",
onDelete: "set null",
},
solo_used: {
type: DataType.INTEGER,
default: 0,
allowNull: false,
},
extension_count: {
type: DataType.INTEGER,
default: 0,
allowNull: false,
},
current_solo_start: {
type: DataType.DATE,
allowNull: true,
},
current_solo_end: {
type: DataType.DATE,
allowNull: true,
},
createdAt: DataType.DATE,
updatedAt: DataType.DATE,
};

module.exports = {
async up(queryInterface) {
await queryInterface.createTable("user_solos", UserSolosModelAttributes);
},

async down(queryInterface) {
await queryInterface.dropTable("user_solos");
},
};

This file was deleted.

10 changes: 0 additions & 10 deletions db/migrations/20221115171247-create-courses-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@ const DataModelAttributes = {
onUpdate: "cascade",
onDelete: "cascade",
},
skill_template_id: {
type: DataType.INTEGER,
allowNull: true,
references: {
model: "course_skill_templates",
key: "id",
},
onUpdate: "cascade",
onDelete: "set null",
},
createdAt: DataType.DATE,
updatedAt: DataType.DATE,
deletedAt: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const { DataType } = require("sequelize-typescript");

const ratingEnum = ["s1", "s2", "s3", "c1", "c3"];

const DataModelAttributes = {
id: {
type: DataType.INTEGER,
Expand All @@ -28,22 +26,27 @@ const DataModelAttributes = {
onUpdate: "cascade",
onDelete: "cascade",
},
solo: {
type: DataType.BOOLEAN,
defaultValue: false,
allowNull: false,
},
solo_rating: {
type: DataType.ENUM(...ratingEnum),
created_by: {
type: DataType.INTEGER,
allowNull: true,
defaultValue: "s1",
},
solo_expires: {
type: DataType.DATE,
references: {
model: "users",
key: "id",
},
onUpdate: "cascade",
onDelete: "set null",
},
solo_extension_count: {
solo_id: {
type: DataType.INTEGER,
defaultValue: 0,
allowNull: true,
references: {
model: "user_solos",
key: "id",
},
onUpdate: "cascade",
onDelete: "set null",
// The solo is only ever deleted IFF a rating change has taken place.
// Therefore, we can just set it null to indicate that the solo is over.
},
createdAt: DataType.DATE,
updatedAt: DataType.DATE,
Expand Down
5 changes: 0 additions & 5 deletions db/migrations/20221115171257-create-training-logs-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ const DataModelAttributes = {
allowNull: false,
default: [],
},
log_public: {
type: DataType.BOOLEAN,
allowNull: false,
defaultValue: true,
},
author_id: {
type: DataType.INTEGER,
allowNull: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ const DataModelAttributes = {
onUpdate: "cascade",
onDelete: "set null",
},
skill_set: {
type: DataType.JSON,
allowNull: true,
defaultValue: null,
},
completed: {
type: DataType.BOOLEAN,
allowNull: false,
Expand Down

This file was deleted.

27 changes: 18 additions & 9 deletions src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import UserInformationAdminController from "./controllers/user/UserInformationAd
import UserNoteAdminController from "./controllers/user/UserNoteAdminController";
import UserController from "./controllers/user/UserAdminController";
import TrainingRequestAdminController from "./controllers/training-request/TrainingRequestAdminController";
import SkillTemplateAdministrationController from "./controllers/skill-template/SkillTemplateAdminController";
import TrainingTypeAdministrationController from "./controllers/training-type/TrainingTypeAdminController";
import FastTrackAdministrationController from "./controllers/fast-track/FastTrackAdminController";
import LogTemplateAdministrationController from "./controllers/log-template/LogTemplateAdminController";
Expand All @@ -33,6 +32,8 @@ import TrainingLogController from "./controllers/training-log/TrainingLogControl
import ActionRequirementAdministrationController from "./controllers/action-requirement/ActionRequirementAdministrationController";
import EndorsementGroupAdminController from "./controllers/endorsement-group/EndorsementGroupAdminController";
import UserCourseProgressAdministrationController from "./controllers/user-course-progress/UserCourseProgressAdministrationController";
import SoloAdminController from "./controllers/solo/SoloAdminController";
import UserEndorsementAdminController from "./controllers/user/UserEndorsementAdminController";

const routerGroup = (callback: (router: Router) => void) => {
const router = Router();
Expand Down Expand Up @@ -188,6 +189,7 @@ router.use(
r.delete("/training", TrainingSessionAdminController.deleteTrainingSession);
r.get("/:uuid", TrainingSessionAdminController.getByUUID);
r.patch("/:uuid", TrainingSessionAdminController.updateByUUID);
r.get("/:uuid/mentors", TrainingSessionAdminController.getAvailableMentorsByUUID);

r.get("/training-types/:uuid", TrainingSessionAdminController.getCourseTrainingTypes);
r.get("/log-template/:uuid", TrainingSessionAdminController.getLogTemplate);
Expand Down Expand Up @@ -220,7 +222,6 @@ router.use(
r.use(
"/course",
routerGroup((r: Router) => {
// TODO: CLEANUP THE TOP 2
r.get("/mentorable", CourseAdministrationController.getMentorable);
r.get("/editable", CourseAdministrationController.getEditable);
// -----------------------
Expand Down Expand Up @@ -251,13 +252,6 @@ router.use(
})
);

r.use(
"/skill-template",
routerGroup((r: Router) => {
r.get("/", SkillTemplateAdministrationController.getAll);
})
);

r.use(
"/training-type",
routerGroup((r: Router) => {
Expand Down Expand Up @@ -293,6 +287,21 @@ router.use(
})
);

r.use(
"/endorsement",
routerGroup((r: Router) => {
r.post("/", UserEndorsementAdminController.addEndorsement);
})
);

r.use(
"/solo",
routerGroup((r: Router) => {
r.post("/", SoloAdminController.createSolo);
r.patch("/", SoloAdminController.updateSolo);
})
);

r.use(
"/mentor-group",
routerGroup((r: Router) => {
Expand Down
12 changes: 6 additions & 6 deletions src/controllers/_validators/_GenericValidator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import ValidationHelper, {ValidationOptions} from "../../utility/helper/ValidationHelper";
import {ValidationException} from "../../exceptions/ValidationException";
import ValidationHelper, { ValidationOptions } from "../../utility/helper/ValidationHelper";
import { ValidationException } from "../../exceptions/ValidationException";

function validateCID(data: any, key: string = "cid") {
const validation = ValidationHelper.validate([
{
name: key,
validationObject: data[key],
toValidate: [{ val: ValidationOptions.NON_NULL }, {val: ValidationOptions.NUMBER}],
}
toValidate: [{ val: ValidationOptions.NON_NULL }, { val: ValidationOptions.NUMBER }],
},
]);

if (validation.invalid) {
Expand All @@ -16,5 +16,5 @@ function validateCID(data: any, key: string = "cid") {
}

export default {
validateCID
}
validateCID,
};
19 changes: 12 additions & 7 deletions src/controllers/course/CourseAdministrationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ interface ICourseBody {
self_enrol_enabled: boolean;
training_type_id: string;
mentor_group_id: string;
skill_template_id?: string;
}

/**
Expand All @@ -48,7 +47,6 @@ async function createCourse(request: Request, response: Response, next: NextFunc
return;
}

const skillTemplateID = isNaN(Number(body.skill_template_id)) || body.skill_template_id == "-1" ? null : Number(body.skill_template_id);
const t = await sequelize.transaction();

try {
Expand All @@ -62,7 +60,6 @@ async function createCourse(request: Request, response: Response, next: NextFunc
is_active: body.active,
self_enrollment_enabled: body.self_enrol_enabled,
initial_training_type: Number(body.training_type_id),
skill_template_id: skillTemplateID,
},
{
transaction: t,
Expand All @@ -80,6 +77,16 @@ async function createCourse(request: Request, response: Response, next: NextFunc
}
);

await TrainingTypesBelongsToCourses.create(
{
course_id: course.id,
training_type_id: Number(body.training_type_id),
},
{
transaction: t,
}
);

await t.commit();
response.status(HttpStatusCode.Created).send({ uuid: course.uuid });
} catch (e) {
Expand Down Expand Up @@ -108,7 +115,6 @@ async function updateCourse(request: Request, response: Response, next: NextFunc
return;
}

const skillTemplateID = isNaN(Number(body.skill_template_id)) || body.skill_template_id == "-1" ? null : Number(body.skill_template_id);
await Course.update(
{
name: body.name_de,
Expand All @@ -118,7 +124,6 @@ async function updateCourse(request: Request, response: Response, next: NextFunc
is_active: body.active,
self_enrollment_enabled: body.self_enrol_enabled,
initial_training_type: Number(body.training_type_id),
skill_template_id: skillTemplateID,
},
{
where: {
Expand All @@ -145,7 +150,7 @@ async function getAllCourses(request: Request, response: Response) {

/**
* Gets basic course information based on the provided course UUID.
* This includes the initial training type alongside the skill template used for this course (or null, if this is not set)
* This includes the initial training type used for this course
* @param request
* @param response
*/
Expand All @@ -156,7 +161,7 @@ async function getCourse(request: Request, response: Response) {
where: {
uuid: params.course_uuid,
},
include: [Course.associations.training_type, Course.associations.skill_template],
include: [Course.associations.training_type],
});

if (course == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/course/CourseInformationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async function getCourseTrainingInformationByUUID(request: Request, response: Re
include: [
{
association: TrainingSession.associations.training_logs,
attributes: ["uuid", "log_public", "id"],
attributes: ["uuid", "id"],
through: { attributes: [] },
},
{
Expand Down
Loading

0 comments on commit cbef768

Please sign in to comment.