Skip to content

Commit

Permalink
REFACTOR: Moved all the database related files into the database fold…
Browse files Browse the repository at this point in the history
…er including enums and interfaces
  • Loading branch information
mbeps committed Apr 21, 2024
1 parent c5f63da commit 15194ed
Show file tree
Hide file tree
Showing 93 changed files with 6,095 additions and 6,035 deletions.
8 changes: 4 additions & 4 deletions actions/material/addNestedSkillsMaterialList.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MaterialInterface from "@/interfaces/material/MaterialInterface";
import MaterialInterface from "@/database/Materials/MaterialInterface";
import SkillTypesEnum from "@/enums/SkillTypesEnum";
import SkillInterface from "@/interfaces/skills/SkillInterface";
import SkillKeysEnum from "@/enums/DatabaseKeysEnums/SkillKeysEnum";
import SkillInterface from "@/database/Skills/SkillInterface";
import SkillDatabaseKeys from "@/database/Skills/SkillDatabaseKeys";
import SkillCategoriesEnum from "@/enums/SkillCategoriesEnum";

/**
Expand Down Expand Up @@ -30,7 +30,7 @@ export default function addNestedSkillsMaterialList<
const material: T = materialsDatabase[materialKey];

// Use a Set to store skills to ensure uniqueness
const skillsToAddSet: Set<SkillKeysEnum> = new Set(material.skills);
const skillsToAddSet: Set<SkillDatabaseKeys> = new Set(material.skills);

// Iterate over each skill in the material's skills array
material.skills.forEach((skillSlug) => {
Expand Down
2 changes: 1 addition & 1 deletion actions/material/checkForArchivedMaterials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MaterialInterface from "@/interfaces/material/MaterialInterface";
import MaterialInterface from "@/database/Materials/MaterialInterface";

/**
* Checks if there are any archived materials in the database.
Expand Down
10 changes: 5 additions & 5 deletions actions/material/countMaterialsAttributedToSkill.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SkillKeysEnum from "@/enums/DatabaseKeysEnums/SkillKeysEnum";
import MaterialInterface from "@/interfaces/material/MaterialInterface";
import SkillInterface from "@/interfaces/skills/SkillInterface";
import SkillDatabaseKeys from "@/database/Skills/SkillDatabaseKeys";
import MaterialInterface from "@/database/Materials/MaterialInterface";
import SkillInterface from "@/database/Skills/SkillInterface";

/**
* Counts the number of materials attributed to a skill or its related skills.
Expand All @@ -12,13 +12,13 @@ import SkillInterface from "@/interfaces/skills/SkillInterface";
* @returns The number of materials attributed to the skill
*/
export default function countMaterialsAttributedToSkill(
skillKey: SkillKeysEnum,
skillKey: SkillDatabaseKeys,
skillsDatabase: Database<SkillInterface>,
materialsDatabase: Database<MaterialInterface>
): number {
// checks if the skill or its related skills are present in the material
function isSkillOrRelatedSkillPresent(
materialSkillKeys: SkillKeysEnum[]
materialSkillKeys: SkillDatabaseKeys[]
): boolean {
if (materialSkillKeys.includes(skillKey)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import UniversityModuleKeysEnum from "@/enums/DatabaseKeysEnums/UniversityModuleKeysEnum";
import UniversityCourseInterface from "@/interfaces/material/UniversityCourseInterface";
import UniversityModuleInterface from "@/interfaces/material/UniversityModuleInterface";
import CourseInterface from "@/database/Courses/CourseInterface";
import ModuleDatabaseKeys from "@/database/Modules/ModuleDatabaseKeys";
import ModuleInterface from "@/database/Modules/ModuleInterface";

export default function aggregateRelatedMaterialsForCourses(
coursesDatabase: Database<UniversityCourseInterface>,
modulesDatabase: Database<UniversityModuleInterface>
): Database<UniversityCourseInterface> {
coursesDatabase: Database<CourseInterface>,
modulesDatabase: Database<ModuleInterface>
): Database<CourseInterface> {
// Create a new object to store the updated courses with aggregated related materials
const updatedCoursesDatabase: Database<UniversityCourseInterface> = {};
const updatedCoursesDatabase: Database<CourseInterface> = {};

// Iterate over each course in the database
Object.keys(coursesDatabase).forEach((courseKey) => {
const course: UniversityCourseInterface = coursesDatabase[courseKey];
const course: CourseInterface = coursesDatabase[courseKey];

// Start with existing related materials in the course, if any
let aggregatedMaterials: string[] = course.relatedMaterials
? [...course.relatedMaterials]
: [];

// Iterate over each module key in the course
course.modules.forEach((moduleKey: UniversityModuleKeysEnum) => {
const moduleData: UniversityModuleInterface = modulesDatabase[moduleKey];
course.modules.forEach((moduleKey: ModuleDatabaseKeys) => {
const moduleData: ModuleInterface = modulesDatabase[moduleKey];
// Ensure the moduleData exists and has related materials
if (moduleData && moduleData.relatedMaterials) {
// Aggregate the related materials
Expand Down
16 changes: 8 additions & 8 deletions actions/material/course/aggregate/aggregateSkillsForCourse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SkillKeysEnum from "@/enums/DatabaseKeysEnums/SkillKeysEnum";
import UniversityCourseInterface from "@/interfaces/material/UniversityCourseInterface";
import UniversityModuleInterface from "@/interfaces/material/UniversityModuleInterface";
import SkillDatabaseKeys from "@/database/Skills/SkillDatabaseKeys";
import CourseInterface from "@/database/Courses/CourseInterface";
import ModuleInterface from "@/database/Modules/ModuleInterface";

/**
* Adds the skills a course's modules to the course's skills itself.
Expand All @@ -11,15 +11,15 @@ import UniversityModuleInterface from "@/interfaces/material/UniversityModuleInt
* @returns The courses with the aggregated skills.
*/
export default function aggregateSkillsForCourse(
course: UniversityCourseInterface,
modulesDatabase: Database<UniversityModuleInterface>
): UniversityCourseInterface {
course: CourseInterface,
modulesDatabase: Database<ModuleInterface>
): CourseInterface {
// Start with existing skills in the course, if any
let aggregatedSkills: SkillKeysEnum[] = [...course.skills];
let aggregatedSkills: SkillDatabaseKeys[] = [...course.skills];

// Iterate over each module key in the course
course.modules.forEach((moduleKey) => {
const moduleData: UniversityModuleInterface = modulesDatabase[moduleKey]; // Avoid using 'module' as a variable name
const moduleData: ModuleInterface = modulesDatabase[moduleKey]; // Avoid using 'module' as a variable name
// Ensure the moduleData exists and has skills
if (moduleData && moduleData.skills) {
// Aggregate the skills
Expand Down
24 changes: 12 additions & 12 deletions actions/material/course/aggregate/aggregateSkillsForCourses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SkillKeysEnum from "@/enums/DatabaseKeysEnums/SkillKeysEnum";
import UniversityModuleKeysEnum from "@/enums/DatabaseKeysEnums/UniversityModuleKeysEnum";
import UniversityCourseInterface from "@/interfaces/material/UniversityCourseInterface";
import UniversityModuleInterface from "@/interfaces/material/UniversityModuleInterface";
import SkillDatabaseKeys from "@/database/Skills/SkillDatabaseKeys";
import ModuleDatabaseKeys from "@/database/Modules/ModuleDatabaseKeys";
import CourseInterface from "@/database/Courses/CourseInterface";
import ModuleInterface from "@/database/Modules/ModuleInterface";

/**
* Adds the skills from a course's modules to the course's skills itself.
Expand All @@ -13,22 +13,22 @@ import UniversityModuleInterface from "@/interfaces/material/UniversityModuleInt
* @returns The courses with the aggregated skills.
*/
export default function aggregateSkillsForCourses(
coursesDatabase: Database<UniversityCourseInterface>,
modulesDatabase: Database<UniversityModuleInterface>
): Database<UniversityCourseInterface> {
coursesDatabase: Database<CourseInterface>,
modulesDatabase: Database<ModuleInterface>
): Database<CourseInterface> {
// Create a new object to store the updated courses with aggregated skills
const updatedCoursesDatabase: Database<UniversityCourseInterface> = {};
const updatedCoursesDatabase: Database<CourseInterface> = {};

// Iterate over each course in the database
Object.keys(coursesDatabase).forEach((courseKey) => {
const course: UniversityCourseInterface = coursesDatabase[courseKey];
const course: CourseInterface = coursesDatabase[courseKey];

// Start with existing skills in the course, if any
let aggregatedSkills: SkillKeysEnum[] = [...course.skills];
let aggregatedSkills: SkillDatabaseKeys[] = [...course.skills];

// Iterate over each module key in the course
course.modules.forEach((moduleKey: UniversityModuleKeysEnum) => {
const moduleData: UniversityModuleInterface = modulesDatabase[moduleKey];
course.modules.forEach((moduleKey: ModuleDatabaseKeys) => {
const moduleData: ModuleInterface = modulesDatabase[moduleKey];
// Ensure the moduleData exists and has skills
if (moduleData && moduleData.skills) {
// Aggregate the skills
Expand Down
8 changes: 4 additions & 4 deletions actions/material/course/findCourseKeyForModule.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import UniversityModuleKeysEnum from "@/enums/DatabaseKeysEnums/UniversityModuleKeysEnum";
import UniversityCourseInterface from "@/interfaces/material/UniversityCourseInterface";
import ModuleDatabaseKeys from "@/database/Modules/ModuleDatabaseKeys";
import CourseInterface from "@/database/Courses/CourseInterface";

export default function findCourseKeyForModule(
moduleKey: UniversityModuleKeysEnum,
coursesDatabase: Database<UniversityCourseInterface>
moduleKey: ModuleDatabaseKeys,
coursesDatabase: Database<CourseInterface>
): string | null {
// Iterate through the courses to find the one related to the specified module
for (const [courseKey, course] of Object.entries(coursesDatabase)) {
Expand Down
2 changes: 1 addition & 1 deletion actions/material/experience/filterRolesByType.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import stringToSlug from "@/actions/stringToSlug";
import RoleInterface from "@/database/Roles/RoleInterface";
import ExperienceTypeEnum from "@/enums/ExperienceTypeEnum";
import RoleInterface from "@/interfaces/material/RoleInterface";

/**
* Filters the roles by the type of experience, for example "work" or "volunteer".
Expand Down
2 changes: 1 addition & 1 deletion actions/material/filter/filterCertificatesByIssuer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import stringToSlug from "@/actions/stringToSlug";
import CertificateInterface from "@/interfaces/material/CertificateInterface";
import CertificateInterface from "@/database/Certificates/CertificateInterface";

/**
* Filters the certificates that match a specific issuer.
Expand Down
2 changes: 1 addition & 1 deletion actions/material/filter/filterMaterialByArchivedStatus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MaterialInterface from "@/interfaces/material/MaterialInterface";
import MaterialInterface from "@/database/Materials/MaterialInterface";

/**
* Filters the materials that match a specific archived status.
Expand Down
2 changes: 1 addition & 1 deletion actions/material/filter/filterMaterialByCategory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import stringToSlug from "@/actions/stringToSlug";
import MaterialInterface from "@/interfaces/material/MaterialInterface";
import MaterialInterface from "@/database/Materials/MaterialInterface";

/**
* Filters the materials that match a specific category.
Expand Down
6 changes: 3 additions & 3 deletions actions/material/filter/filterMaterialBySkill.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SkillKeysEnum from "@/enums/DatabaseKeysEnums/SkillKeysEnum";
import MaterialInterface from "@/interfaces/material/MaterialInterface";
import SkillDatabaseKeys from "@/database/Skills/SkillDatabaseKeys";
import MaterialInterface from "@/database/Materials/MaterialInterface";

/**
* Filters the materials that match a specific skill.
Expand All @@ -11,7 +11,7 @@ import MaterialInterface from "@/interfaces/material/MaterialInterface";
* @returns The keys of the materials that match the skill
*/
export default function filterMaterialBySkill<T extends MaterialInterface>(
skillKey: SkillKeysEnum,
skillKey: SkillDatabaseKeys,
materialKeys: string[],
materialDatabase: Database<T>
): string[] {
Expand Down
4 changes: 2 additions & 2 deletions actions/material/filter/filterMaterialBySkillCategory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import stringToSlug from "@/actions/stringToSlug";
import MaterialInterface from "@/interfaces/material/MaterialInterface";
import SkillInterface from "@/interfaces/skills/SkillInterface";
import MaterialInterface from "@/database/Materials/MaterialInterface";
import SkillInterface from "@/database/Skills/SkillInterface";

/**
* Filters the materials that match a specific skill category.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FilterOption from "@/interfaces/filters/FilterOption";
import MaterialInterface from "@/interfaces/material/MaterialInterface";
import MaterialInterface from "@/database/Materials/MaterialInterface";
import stringToSlug from "../../stringToSlug";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import stringToSlug from "@/actions/stringToSlug";
import FilterOption from "@/interfaces/filters/FilterOption";
import RoleInterface from "@/interfaces/material/RoleInterface";
import RoleInterface from "@/database/Roles/RoleInterface";

/**
* Generates the filter options based on the types of the roles.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import FilterOption from "@/interfaces/filters/FilterOption";
import MaterialInterface from "@/interfaces/material/MaterialInterface";
import MaterialInterface from "@/database/Materials/MaterialInterface";
import stringToSlug from "../../stringToSlug";
import SkillInterface from "@/interfaces/skills/SkillInterface";
import SkillInterface from "@/database/Skills/SkillInterface";

/**
* Generates the filter options based on the categories of the materials.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import FilterOption from "@/interfaces/filters/FilterOption";
import MaterialInterface from "@/interfaces/material/MaterialInterface";
import MaterialInterface from "@/database/Materials/MaterialInterface";
import stringToSlug from "../../stringToSlug";
import SkillTypesEnum from "@/enums/SkillTypesEnum";
import SkillCategoriesEnum from "@/enums/SkillCategoriesEnum";
import SkillInterface from "@/interfaces/skills/SkillInterface";
import SkillInterface from "@/database/Skills/SkillInterface";

/**
* Generates the filter options based on the categories of the materials.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import FilterOption from "@/interfaces/filters/FilterOption";
import MaterialInterface from "@/interfaces/material/MaterialInterface";
import MaterialInterface from "@/database/Materials/MaterialInterface";
import SkillCategoriesEnum from "@/enums/SkillCategoriesEnum";
import SkillInterface from "@/interfaces/skills/SkillInterface";
import SkillInterface from "@/database/Skills/SkillInterface";

/**
* Generates the filter options based on the programming languages of the materials.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import stringToSlug from "@/actions/stringToSlug";
import FilterOption from "@/interfaces/filters/FilterOption";
import CertificateInterface from "@/interfaces/material/CertificateInterface";
import CertificateInterface from "@/database/Certificates/CertificateInterface";

/**
* Generates the filter options based on the issuers of the certificates.
Expand Down
2 changes: 1 addition & 1 deletion actions/material/group/groupMaterialsByCategory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import MaterialInterface from "@/database/Materials/MaterialInterface";
import MaterialGroupInterface from "@/interfaces/material/MaterialGroupInterface";
import MaterialInterface from "@/interfaces/material/MaterialInterface";

/**
* Groups the materials by their category.
Expand Down
2 changes: 1 addition & 1 deletion actions/material/group/groupMaterialsByMaterialType.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MaterialTypeEnum from "@/enums/MaterialTypeEnum";
import MaterialGroupInterface from "@/interfaces/material/MaterialGroupInterface";
import MaterialInterface from "@/interfaces/material/MaterialInterface";
import MaterialInterface from "@/database/Materials/MaterialInterface";

/**
* Groups the materials based on the material type as defined in {@link MaterialTypeEnum}.
Expand Down
6 changes: 3 additions & 3 deletions actions/material/isSkillAssociatedWithMaterial.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SkillKeysEnum from "@/enums/DatabaseKeysEnums/SkillKeysEnum";
import MaterialInterface from "@/interfaces/material/MaterialInterface";
import SkillDatabaseKeys from "@/database/Skills/SkillDatabaseKeys";
import MaterialInterface from "@/database/Materials/MaterialInterface";

/**
* Checks whether a skill is associated with any material.
Expand All @@ -9,7 +9,7 @@ import MaterialInterface from "@/interfaces/material/MaterialInterface";
* @returns Whether the skill is associated with any material
*/
export default function isSkillAssociatedWithMaterial(
skillKey: SkillKeysEnum,
skillKey: SkillDatabaseKeys,
materialsDatabase: Database<MaterialInterface>
): boolean {
// Loop through the materialsMap
Expand Down
8 changes: 4 additions & 4 deletions actions/skills/filter/filterCategoriesFromSkills.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SkillCategoriesEnum from "@/enums/SkillCategoriesEnum";
import SkillKeysEnum from "@/enums/DatabaseKeysEnums/SkillKeysEnum";
import SkillInterface from "@/interfaces/skills/SkillInterface";
import SkillDatabaseKeys from "@/database/Skills/SkillDatabaseKeys";
import SkillInterface from "@/database/Skills/SkillInterface";

/**
* Filter out skills that belong to the specified categories.
Expand All @@ -12,9 +12,9 @@ import SkillInterface from "@/interfaces/skills/SkillInterface";
export default function filterCategoriesFromSkills(
skillsDatabase: Database<SkillInterface>,
ignoredCategories: SkillCategoriesEnum[]
): SkillKeysEnum[] {
): SkillDatabaseKeys[] {
return Object.keys(skillsDatabase).filter((skillKey) => {
const skill: SkillInterface = skillsDatabase[skillKey];
return !ignoredCategories.includes(skill.category);
}) as SkillKeysEnum[];
}) as SkillDatabaseKeys[];
}
16 changes: 8 additions & 8 deletions actions/skills/filter/filterSkillsByCategory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SkillCategoriesEnum from "@/enums/SkillCategoriesEnum";
import SkillKeysEnum from "@/enums/DatabaseKeysEnums/SkillKeysEnum";
import SkillInterface from "@/interfaces/skills/SkillInterface";
import SkillDatabaseKeys from "@/database/Skills/SkillDatabaseKeys";
import SkillInterface from "@/database/Skills/SkillInterface";

/**
* Filters skills which belong to a specific category.
Expand All @@ -12,12 +12,12 @@ import SkillInterface from "@/interfaces/skills/SkillInterface";
* @returns The filtered skill keys which belong to the specific category
*/
export default function filterSkillsByCategory(
skillKeys: SkillKeysEnum[],
skillKeys: SkillDatabaseKeys[],
skillsDatabase: Database<SkillInterface>,
specificCategory: SkillCategoriesEnum
): SkillKeysEnum[] {
): SkillDatabaseKeys[] {
// Initialize an empty array for the filtered skill slugs
const filteredSkillSlugs: SkillKeysEnum[] = [];
const filteredSkillSlugs: SkillDatabaseKeys[] = [];

// Iterate over the skill slugs array
skillKeys.forEach((skillKey) => {
Expand All @@ -42,12 +42,12 @@ export default function filterSkillsByCategory(
* @returns The filtered skill keys which do not belong to the excluded category
*/
export function filterSkillSlugsExcludingCategory(
skillKeys: SkillKeysEnum[],
skillKeys: SkillDatabaseKeys[],
skillsDatabase: Database<SkillInterface>, // Assuming this is passed into the function
excludedCategory: SkillCategoriesEnum
): SkillKeysEnum[] {
): SkillDatabaseKeys[] {
// Initialize an empty array for the skill slugs that do not match the excluded category
const nonMatchingSkillSlugs: SkillKeysEnum[] = [];
const nonMatchingSkillSlugs: SkillDatabaseKeys[] = [];

// Iterate over the skill slugs array
skillKeys.forEach((skillKey) => {
Expand Down
Loading

0 comments on commit 15194ed

Please sign in to comment.