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';
export const getAllCurriculums = async (req, res) => {
try {
const curriculums = await Curriculum.find();
const curriculums = await Curriculum.find().populate("tutorials");
res.status(200).json(curriculums);
} catch (error) {
res.status(500).json({ message: error.message });
}
}
};
export const getCurriculumById = async (req, res) => {
const { id } = req.params;
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);
} catch (error) {
res.status(404).json({ message: 'Curriculum not found' });
res.status(500).json({ message: error.message });
}
}
};
export const createCurriculum = async (req, res) => {
const curriculumData = req.body;
......
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({
tutorialCode: String,
tutorialTitle: String,
tutorialDescription: String,
tutorialImage: String,
taskItems: [taskItemSchema], // Embed task items as subdocuments
// Additional fields for tutorial content
});
const curriculumSchema = new mongoose.Schema({
curriculumCode: String,
curriculumLevel: String,
curriculumName: String,
curriculumTitle: String,
curriculumDescription: String,
curriculumImage: String,
tutorials: [tutorialSchema], // Embed tutorials as subdocuments
tutorials: [{
type: mongoose.Schema.Types.ObjectId,
ref: "Tutorial",
}],
// Additional fields for curriculum details
status: {
type: Number,
default: 1, // Default status as active (1)
},
createdBy: String,
updatedBy: String,
createdAt: {
type: Date,
default: new Date(),
},
updatedAt: {
type: Date,
default: new Date(),
},
...commonFields
});
const Curriculum = mongoose.model("Curriculum", curriculumSchema);
......
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,
......@@ -10,8 +23,12 @@ const taskItemSchema = new mongoose.Schema({
});
const tutorialSchema = new mongoose.Schema({
tutorialCode: String,
tutorialCode: {
type: String,
unique: true, // Ensures unique values for tutorialCode
},
tutorialTitle: String,
tutorialDescription: String,
tutorialImage: String,
taskItems: [taskItemSchema], // Embed task items as subdocuments
// Additional fields for tutorial details
......@@ -19,16 +36,7 @@ const tutorialSchema = new mongoose.Schema({
type: Number,
default: 1, // Default status as active (1)
},
createdBy: String,
updatedBy: String,
createdAt: {
type: Date,
default: new Date(),
},
updatedAt: {
type: Date,
default: new Date(),
},
...commonFields
});
const Tutorial = mongoose.model("Tutorial", tutorialSchema);
......
......@@ -157,7 +157,7 @@ const List = () => {
},
{
Header: 'Curriculum Name',
accessor: 'curriculumName'
accessor: 'curriculumTitle'
},
{
Header: 'Status',
......
......@@ -24,7 +24,8 @@ export interface curriculumProps {
_id: number | string | undefined;
curriculumCode: String;
curriculumLevel: String;
curriculumName: String;
curriculumTitle: String;
curriculumDescription: String;
curriculumImage: String;
tutorials: tutorialItemProps[];
status: Number;
......@@ -38,6 +39,7 @@ export interface tutorialItemProps {
_id: number | string | undefined;
tutorialCode: String;
tutorialTitle: String;
tutorialDescription: String;
tutorialImage: String;
status: Number;
createdBy: String;
......
......@@ -152,7 +152,7 @@ const List = () => {
accessor: 'tutorialCode'
},
{
Header: 'Tutorial Title',
Header: 'Tutorial Name',
accessor: 'tutorialTitle'
},
{
......
......@@ -51,7 +51,8 @@ export interface Props {
_id: number | string | undefined;
curriculumCode: String;
curriculumLevel: String;
curriculumName: String;
curriculumTitle: String;
curriculumDescription: String;
curriculumImage: String;
tutorials: tutorialItemProps[];
status: Number;
......@@ -67,6 +68,7 @@ export interface tutorialItemProps {
_id: number | string | undefined;
tutorialCode: String;
tutorialTitle: String;
tutorialDescription: String;
tutorialImage: String;
status: Number;
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