From e41f61f37115864f9c1e7cb571d379e16983416d Mon Sep 17 00:00:00 2001 From: Blake Rand Date: Thu, 2 Mar 2023 14:23:08 -0500 Subject: [PATCH] Added ability to add atrributes to problems --- src/api/controllers/problem.controller.ts | 7 +++++++ src/api/models/problem.model.ts | 20 ++++++++++++++++++++ src/api/validation/problem.validation.ts | 15 +++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/api/controllers/problem.controller.ts b/src/api/controllers/problem.controller.ts index a6336466..6e23613e 100644 --- a/src/api/controllers/problem.controller.ts +++ b/src/api/controllers/problem.controller.ts @@ -148,6 +148,10 @@ const createProblem = async ( statement: req.body.statement, title: req.body.title, hidden: req.body.hidden, + author: req.body.author, + difficulty: req.body.difficulty, + dateCreated: Date(), + lastModified: Date(), language: req.body.language, dueDate: req.body.dueDate, code: req.body.code, @@ -201,6 +205,9 @@ const updateProblem = async ( statement: req.body.statement, title: req.body.title, hidden: req.body.hidden, + author: req.body.author, + difficulty: req.body.difficulty, + lastModified: Date(), language: req.body.language, dueDate: req.body.dueDate, code: req.body.code, diff --git a/src/api/models/problem.model.ts b/src/api/models/problem.model.ts index 13eb4574..98ca8e3c 100644 --- a/src/api/models/problem.model.ts +++ b/src/api/models/problem.model.ts @@ -12,6 +12,10 @@ interface ProblemInterface { hidden: boolean; language: string; dueDate: Date; + author: string; + difficulty: string; + dateCreated: Date; + lastModified: Date; code: { header: string; body: string; @@ -41,6 +45,22 @@ const problemSchema = new Schema( type: Boolean, required: true }, + author: { + type: String, + required: false + }, + difficulty: { + type: String, + required: false + }, + dateCreated: { + type: Date, + required: false + }, + lastModified: { + type: Date, + required: false + }, language: { type: String, required: true diff --git a/src/api/validation/problem.validation.ts b/src/api/validation/problem.validation.ts index 6fb775c9..35b26f00 100644 --- a/src/api/validation/problem.validation.ts +++ b/src/api/validation/problem.validation.ts @@ -32,10 +32,16 @@ const problemValidation = (data: any): ValidationResult => { hidden: boolean().required(), language: string().required(), dueDate: date().iso().required(), + author: string().allow(''), + difficulty: string().allow(''), + dateCreated: date().iso(), + lastModified: date().iso(), + footer: string().allow(''), code: { header: string().allow('').required(), body: string().allow('').required(), - footer: string().allow('').required() + footer: string().allow('').required(), + solution: string().allow('') }, fileExtension: string().valid('.java', '.cpp', '.h').min(1).required(), testCases: array().items({ @@ -61,10 +67,15 @@ const problemValidationWithoutModuleId = (data: any): ValidationResult => { hidden: boolean().required(), language: string().required(), dueDate: date().iso().required(), + author: string(), + difficulty: string(), + dateCreated: date().iso(), + lastModified: date().iso(), code: { header: string().allow('').required(), body: string().allow('').required(), - footer: string().allow('').required() + footer: string().allow('').required(), + solution: string().allow('') }, fileExtension: string().valid('.java', '.cpp', '.h').min(1).required(), testCases: array().items({