Skip to content
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

Help request notifications/fixed #59

Merged
merged 11 commits into from
Sep 23, 2024
Merged
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
60 changes: 60 additions & 0 deletions backend/middlewares/validators/helpRequestValidators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Request, Response, NextFunction } from "express";
import { validatePrimitive, getApiValidationError } from "./util";

export const createHelpRequestDtoValidator = async (
req: Request,
res: Response,
next: NextFunction,
) => {
if (!validatePrimitive(req.body.message, "string")) {
return res.status(400).send(getApiValidationError("message", "string"));
}
if (!validatePrimitive(req.body.learner, "string")) {
return res.status(400).send(getApiValidationError("learner", "string"));
}
if (!validatePrimitive(req.body.facilitator, "string")) {
return res.status(400).send(getApiValidationError("facilitator", "string"));
}
if (!validatePrimitive(req.body.unit, "string")) {
return res.status(400).send(getApiValidationError("unit", "string"));
}
if (!validatePrimitive(req.body.module, "string")) {
return res.status(400).send(getApiValidationError("module", "string"));
}
if (!validatePrimitive(req.body.page, "string")) {
return res.status(400).send(getApiValidationError("page", "string"));
}
return next();
};

export const updateHelpRequestDtoValidator = async (
req: Request,
res: Response,
next: NextFunction,
) => {
if (
req.body.unit !== undefined &&
!validatePrimitive(req.body.unit, "string")
) {
return res.status(400).send(getApiValidationError("unit", "string"));
}
if (
req.body.module !== undefined &&
!validatePrimitive(req.body.module, "string")
) {
return res.status(400).send(getApiValidationError("module", "string"));
}
if (
req.body.page !== undefined &&
!validatePrimitive(req.body.page, "string")
) {
return res.status(400).send(getApiValidationError("page", "string"));
}
if (
req.body.completed !== undefined &&
!validatePrimitive(req.body.completed, "boolean")
) {
return res.status(400).send(getApiValidationError("completed", "boolean"));
}
return next();
};
22 changes: 22 additions & 0 deletions backend/middlewares/validators/notificationValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Request, Response, NextFunction } from "express";
import { validatePrimitive, getApiValidationError } from "./util";

export const getNotificationtDtoValidator = async (
req: Request,
res: Response,
next: NextFunction,
) => {
if (
req.body.skip !== undefined &&
!validatePrimitive(req.body.skip, "integer")
) {
return res.status(400).send(getApiValidationError("skip", "integer"));
}
if (
req.body.limit !== undefined &&
!validatePrimitive(req.body.limit, "integer")
) {
return res.status(400).send(getApiValidationError("limit", "integer"));
}
return next();
};
37 changes: 37 additions & 0 deletions backend/models/coursemodule.mgmodel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import mongoose, { Schema, Document, ObjectId } from "mongoose";

export interface CourseModule extends Document {
id: string;
displayIndex: number;
title: string;
pages: [ObjectId];
}

export const CourseModuleSchema: Schema = new Schema({
title: {
type: String,
required: true,
},
displayIndex: {
type: Number,
required: true,
},
pages: [
{
type: Schema.Types.ObjectId,
ref: "CoursePage",
},
],
});

/* eslint-disable no-param-reassign */
CourseModuleSchema.set("toJSON", {
virtuals: true,
versionKey: false,
transform: (_doc: Document, ret: Record<string, unknown>) => {
// eslint-disable-next-line no-underscore-dangle
delete ret._id;
},
});

export default mongoose.model<CourseModule>("CourseModule", CourseModuleSchema);
75 changes: 75 additions & 0 deletions backend/models/coursepage.mgmodel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import mongoose, { Schema, Document } from "mongoose";

export type ElementSkeleton = {
id: string;
x: number;
y: number;
w: number;
h: number;
content: string;
};

const ElementSkeletonSchema: Schema = new Schema({
x: {
type: Number,
required: true,
},
y: {
type: Number,
required: true,
},
w: {
type: Number,
required: true,
},
h: {
type: Number,
required: true,
},
content: {
type: String,
required: true,
},
});

export type PageType = "Lesson" | "Activity";

export interface CoursePage extends Document {
id: string;
title: string;
displayIndex: number;
type: PageType;
layout: [ElementSkeleton];
}

export const CoursePageSchema: Schema = new Schema({
title: {
type: String,
required: true,
},
displayIndex: {
type: Number,
required: true,
},
type: {
type: String,
required: true,
enum: ["Lesson", "Activity"],
},
layout: {
type: [ElementSkeletonSchema],
required: true,
},
});

/* eslint-disable no-param-reassign */
CoursePageSchema.set("toJSON", {
virtuals: true,
versionKey: false,
transform: (_doc: Document, ret: Record<string, unknown>) => {
// eslint-disable-next-line no-underscore-dangle
delete ret._id;
},
});

export default mongoose.model<CoursePage>("CoursePage", CoursePageSchema);
98 changes: 17 additions & 81 deletions backend/models/courseunit.mgmodel.ts
Original file line number Diff line number Diff line change
@@ -1,85 +1,10 @@
import mongoose, { Schema, Document } from "mongoose";
import mongoose, { Schema, Document, ObjectId } from "mongoose";

export type ElementSkeleton = {
id: string;
x: number;
y: number;
w: number;
h: number;
content: string;
};

const ElementSkeletonSchema: Schema = new Schema({
x: {
type: Number,
required: true,
},
y: {
type: Number,
required: true,
},
w: {
type: Number,
required: true,
},
h: {
type: Number,
required: true,
},
content: {
type: String,
required: true,
},
});

export type PageType = "Lesson" | "Activity";

export type Page = {
id: string;
title: string;
type: PageType;
layout: [ElementSkeleton];
};

const PageSchema: Schema = new Schema({
title: {
type: String,
required: true,
},
type: {
type: String,
required: true,
enum: ["Lesson", "Activity"],
},
layout: {
type: [ElementSkeletonSchema],
required: true,
},
});

export type Module = {
id: string;
title: string;
pages: [Page];
};

const ModuleSchema: Schema = new Schema({
title: {
type: String,
required: true,
},
pages: {
type: [PageSchema],
required: true,
},
});

// Course Unit
export interface CourseUnit extends Document {
id: string;
displayIndex: number;
title: string;
modules: [Module];
modules: [ObjectId];
}

const CourseUnitSchema: Schema = new Schema({
Expand All @@ -91,10 +16,21 @@ const CourseUnitSchema: Schema = new Schema({
type: String,
required: true,
},
modules: {
type: [ModuleSchema],
required: true,
default: [],
modules: [
{
type: Schema.Types.ObjectId,
ref: "CourseModule",
},
],
});

/* eslint-disable no-param-reassign */
CourseUnitSchema.set("toJSON", {
virtuals: true,
versionKey: false,
transform: (_doc: Document, ret: Record<string, unknown>) => {
// eslint-disable-next-line no-underscore-dangle
delete ret._id;
},
});

Expand Down
45 changes: 33 additions & 12 deletions backend/models/helprequest.mgmodel.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import mongoose, { Schema, Document } from "mongoose";
import mongoose, { Schema, Document, ObjectId } from "mongoose";

export interface HelpRequest extends Document {
id: string;
id: ObjectId;
message: string;
learner: string;
facilitator: string;
unit: string;
module: string;
page: string;
learner: ObjectId;
facilitator: ObjectId;
unit: ObjectId;
module: ObjectId;
page: ObjectId;
completed: boolean;
createdAt: Date;
}

const HelpRequestSchema: Schema = new Schema(
Expand All @@ -17,27 +19,46 @@ const HelpRequestSchema: Schema = new Schema(
required: true,
},
learner: {
type: String,
type: Schema.Types.ObjectId,
ref: "User",
required: true,
},
facilitator: {
type: String,
type: Schema.Types.ObjectId,
ref: "User",
required: true,
},
unit: {
type: String,
type: Schema.Types.ObjectId,
ref: "CourseUnit",
required: true,
},
module: {
type: String,
type: Schema.Types.ObjectId,
ref: "CourseModule",
required: true,
},
page: {
type: String,
type: Schema.Types.ObjectId,
ref: "CoursePage",
required: true,
},
completed: {
type: Boolean,
default: false,
},
},
{ timestamps: { createdAt: true, updatedAt: false } },
);

/* eslint-disable no-param-reassign */
HelpRequestSchema.set("toJSON", {
virtuals: true,
versionKey: false,
transform: (_doc: Document, ret: Record<string, unknown>) => {
// eslint-disable-next-line no-underscore-dangle
delete ret._id;
},
});

export default mongoose.model<HelpRequest>("HelpRequest", HelpRequestSchema);
Loading
Loading