Commit 12e80745 authored by janithgamage1.ed's avatar janithgamage1.ed

fix : update

Desc : update project
parent 3feec0c2
...@@ -2,22 +2,25 @@ import Curriculum from '../models/curriculum.model.js'; ...@@ -2,22 +2,25 @@ import Curriculum from '../models/curriculum.model.js';
export const getAllCurriculums = async (req, res) => { export const getAllCurriculums = async (req, res) => {
try { try {
const curriculums = await Curriculum.find(); const curriculums = await Curriculum.find().populate("tutorials");
res.status(200).json(curriculums); res.status(200).json(curriculums);
} catch (error) { } catch (error) {
res.status(500).json({ message: error.message }); res.status(500).json({ message: error.message });
} }
} };
export const getCurriculumById = async (req, res) => { export const getCurriculumById = async (req, res) => {
const { id } = req.params; const { id } = req.params;
try { try {
const curriculum = await Curriculum.findById(id); const curriculum = await Curriculum.findById(id).populate("tutorials");
if (!curriculum) {
return res.status(404).json({ message: 'Curriculum not found' });
}
res.status(200).json(curriculum); res.status(200).json(curriculum);
} catch (error) { } catch (error) {
res.status(404).json({ message: 'Curriculum not found' }); res.status(500).json({ message: error.message });
} }
} };
export const createCurriculum = async (req, res) => { export const createCurriculum = async (req, res) => {
const curriculumData = req.body; const curriculumData = req.body;
......
import mongoose from "mongoose"; import mongoose from "mongoose";
const commonFields = {
createdBy: String,
updatedBy: String,
createdAt: {
type: Date,
default: new Date(),
},
updatedAt: {
type: Date,
default: new Date(),
},
};
const taskItemSchema = new mongoose.Schema({
title: String,
description: String,
howToDo: String,
referenceImage: String,
referenceVideo: String,
// Additional fields for task items
});
const tutorialSchema = new mongoose.Schema({ const tutorialSchema = new mongoose.Schema({
tutorialCode: String, tutorialCode: String,
tutorialTitle: String, tutorialTitle: String,
tutorialDescription: String,
tutorialImage: String, tutorialImage: String,
taskItems: [taskItemSchema], // Embed task items as subdocuments
// Additional fields for tutorial content // Additional fields for tutorial content
}); });
const curriculumSchema = new mongoose.Schema({ const curriculumSchema = new mongoose.Schema({
curriculumCode: String, curriculumCode: String,
curriculumLevel: String, curriculumLevel: String,
curriculumName: String, curriculumTitle: String,
curriculumDescription: String,
curriculumImage: String, curriculumImage: String,
tutorials: [tutorialSchema], // Embed tutorials as subdocuments tutorials: [{
type: mongoose.Schema.Types.ObjectId,
ref: "Tutorial",
}],
// Additional fields for curriculum details // Additional fields for curriculum details
status: { status: {
type: Number, type: Number,
default: 1, // Default status as active (1) default: 1, // Default status as active (1)
}, },
createdBy: String, ...commonFields
updatedBy: String,
createdAt: {
type: Date,
default: new Date(),
},
updatedAt: {
type: Date,
default: new Date(),
},
}); });
const Curriculum = mongoose.model("Curriculum", curriculumSchema); const Curriculum = mongoose.model("Curriculum", curriculumSchema);
......
import mongoose from "mongoose"; import mongoose from "mongoose";
const commonFields = {
createdBy: String,
updatedBy: String,
createdAt: {
type: Date,
default: new Date(),
},
updatedAt: {
type: Date,
default: new Date(),
},
};
const taskItemSchema = new mongoose.Schema({ const taskItemSchema = new mongoose.Schema({
title: String, title: String,
description: String, description: String,
...@@ -10,8 +23,12 @@ const taskItemSchema = new mongoose.Schema({ ...@@ -10,8 +23,12 @@ const taskItemSchema = new mongoose.Schema({
}); });
const tutorialSchema = new mongoose.Schema({ const tutorialSchema = new mongoose.Schema({
tutorialCode: String, tutorialCode: {
type: String,
unique: true, // Ensures unique values for tutorialCode
},
tutorialTitle: String, tutorialTitle: String,
tutorialDescription: String,
tutorialImage: String, tutorialImage: String,
taskItems: [taskItemSchema], // Embed task items as subdocuments taskItems: [taskItemSchema], // Embed task items as subdocuments
// Additional fields for tutorial details // Additional fields for tutorial details
...@@ -19,16 +36,7 @@ const tutorialSchema = new mongoose.Schema({ ...@@ -19,16 +36,7 @@ const tutorialSchema = new mongoose.Schema({
type: Number, type: Number,
default: 1, // Default status as active (1) default: 1, // Default status as active (1)
}, },
createdBy: String, ...commonFields
updatedBy: String,
createdAt: {
type: Date,
default: new Date(),
},
updatedAt: {
type: Date,
default: new Date(),
},
}); });
const Tutorial = mongoose.model("Tutorial", tutorialSchema); const Tutorial = mongoose.model("Tutorial", tutorialSchema);
......
...@@ -157,7 +157,7 @@ const List = () => { ...@@ -157,7 +157,7 @@ const List = () => {
}, },
{ {
Header: 'Curriculum Name', Header: 'Curriculum Name',
accessor: 'curriculumName' accessor: 'curriculumTitle'
}, },
{ {
Header: 'Status', Header: 'Status',
......
...@@ -24,7 +24,8 @@ export interface curriculumProps { ...@@ -24,7 +24,8 @@ export interface curriculumProps {
_id: number | string | undefined; _id: number | string | undefined;
curriculumCode: String; curriculumCode: String;
curriculumLevel: String; curriculumLevel: String;
curriculumName: String; curriculumTitle: String;
curriculumDescription: String;
curriculumImage: String; curriculumImage: String;
tutorials: tutorialItemProps[]; tutorials: tutorialItemProps[];
status: Number; status: Number;
...@@ -38,6 +39,7 @@ export interface tutorialItemProps { ...@@ -38,6 +39,7 @@ export interface tutorialItemProps {
_id: number | string | undefined; _id: number | string | undefined;
tutorialCode: String; tutorialCode: String;
tutorialTitle: String; tutorialTitle: String;
tutorialDescription: String;
tutorialImage: String; tutorialImage: String;
status: Number; status: Number;
createdBy: String; createdBy: String;
......
...@@ -152,7 +152,7 @@ const List = () => { ...@@ -152,7 +152,7 @@ const List = () => {
accessor: 'tutorialCode' accessor: 'tutorialCode'
}, },
{ {
Header: 'Tutorial Title', Header: 'Tutorial Name',
accessor: 'tutorialTitle' accessor: 'tutorialTitle'
}, },
{ {
......
...@@ -51,7 +51,8 @@ export interface Props { ...@@ -51,7 +51,8 @@ export interface Props {
_id: number | string | undefined; _id: number | string | undefined;
curriculumCode: String; curriculumCode: String;
curriculumLevel: String; curriculumLevel: String;
curriculumName: String; curriculumTitle: String;
curriculumDescription: String;
curriculumImage: String; curriculumImage: String;
tutorials: tutorialItemProps[]; tutorials: tutorialItemProps[];
status: Number; status: Number;
...@@ -67,6 +68,7 @@ export interface tutorialItemProps { ...@@ -67,6 +68,7 @@ export interface tutorialItemProps {
_id: number | string | undefined; _id: number | string | undefined;
tutorialCode: String; tutorialCode: String;
tutorialTitle: String; tutorialTitle: String;
tutorialDescription: String;
tutorialImage: String; tutorialImage: String;
status: Number; status: Number;
createdBy: String; createdBy: String;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment