Skip to content
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
149 changes: 149 additions & 0 deletions _apidoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,3 +665,152 @@
* @apiSuccess {String[]} module.cognitiveLevels Array of cognitive levels of
* attainment as per Bloom's Taxanomy (L1-L6).
*/

// ------------------------------------------------------------------------------------------
// Activity.
// ------------------------------------------------------------------------------------------

/**
* @api {post} /activity/add Add Activty.
* @apiName AddActivity
* @apiGroup Activity
*
* @apiBody {Date} startTime The startTime of the activity.
* @apiBody {Number} duration The duration of the activity (in minutes).
* @apiBody {ObjectId} course The course of the activity (ObjectId).
* @apiBody {ObjectId} faculty The faculty alloted for the activity(ObjectId).
* @apiBody {String} type The type of activity.One of possible LECTURE, PRACTICAL, TUTORIAL.
* @apiBody {ObjectId} task The task of the activity (ObjectId).One of possible Topic,Practical,Tutorial.
* @apiBody {ObjectId} group The group of the activity (ObjectId).
* @apiBody {ObjectId} students the students who gonna attend the activity(ObjectId).
*
* @apiSuccess {String} res Response message.
*
* @apiError (Error 500) DatabaseError Error while inserting in the database.
*
* @apiDescription Adds a new Activity to the system.
*/

/**
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* {
* "res": "Added activity"
* }
*
* @apiErrorExample Error-Response:
* HTTP/1.1 500 Internal Server Error
* {
* "err": "Error while inserting in DB"
* }
*/

/**
* @api {delete} /timetable/delete/:timetableId Delete Timetable
* @apiName DeleteTimetable
* @apiGroup Timetable
*
* @apiParam {String} timetableId The ID of the timetable document to delete.
*
* @apiSuccess {String} res Success message indicating the deletion.
*
* @apiError (Error 500) DatabaseError Error message if there was an error during the deletion.
*/

/**
* @api {delete} /activity/delete/:activity Delete Activity.
* @apiName DeleteActivity
* @apiGroup Activity
*
* @apiParam {String} Activity The activity document to delete.
*
* @apiSuccess {String} res Success message indicating the deletion.
*
* @apiError (Error 500) DatabaseError Error message if there was an error during the deletion.
*/

/**
* @api {post} /timetable/update Update Timetable
* @apiName UpdateTimetable
* @apiGroup Timetable
* @apiDescription Update existing timetable data.
*
* @apiBody {Date} startTime The startTime of the activity.
* @apiBody {Number} duration The duration of the activity (in minutes).
* @apiBody {ObjectId} course The course of the activity (ObjectId).
* @apiBody {ObjectId} faculty The faculty alloted for the activity(ObjectId).
* @apiBody {String} type The type of activity.One of possible LECTURE, PRACTICAL, TUTORIAL.
* @apiBody {ObjectId} task The task of the activity (ObjectId).One of possible Topic,Practical,Tutorial.
* @apiBody {ObjectId} group The group of the activity (ObjectId).
* @apiBody {ObjectId} students the students who gonna attend the activity(ObjectId).
*
* @apiSuccess {String} res Timetable updated.
*/

/**
* @api {post} /activity/update Update Activity.
* @apiName UpdateActivity
* @apiGroup Activity
* @apiDescription Update existing activity data.
*
* @apiBody {Date} startTime The startTime of the activity.
* @apiBody {Number} duration The duration of the activity (in minutes).
* @apiBody {ObjectId} course The course of the activity (ObjectId).
* @apiBody {ObjectId} faculty The faculty alloted for the activity(ObjectId).
* @apiBody {String} type The type of activity.One of possible LECTURE, PRACTICAL, TUTORIAL.
* @apiBody {ObjectId} task The task of the activity (ObjectId).One of possible Topic,Practical,Tutorial.
* @apiBody {ObjectId} group The group of the activity (ObjectId).
* @apiBody {ObjectId} students the students who gonna attend the activity(ObjectId).
*
* @apiSuccess {String} res Activity updated.
* @apiError (Error 500) DatabaseError Error in updating the database.
*/

/**
* @api {get} /timetable/list Get Timetable List
* @apiName GetTimetableList
* @apiGroup Timetable
*
* @apiQuery {Date} startTime The startTime of the activity.
* @apiQuery {Number} duration The duration of the activity (in minutes).
* @apiQUERY {ObjectId} course The course of the activity (ObjectId).
* @apiQuery {ObjectId} faculty The faculty alloted for the activity(ObjectId).
* @apiQuery {String} type The type of activity.One of possible LECTURE, PRACTICAL, TUTORIAL.
* @apiQuery {ObjectId} task The task of the activity (ObjectId).One of possible Topic,Practical,Tutorial.
* @apiQuery {ObjectId} group The group of the activity (ObjectId).
* @apiQuery {ObjectId} students the students who gonna attend the activity(ObjectId).
*
* @apiSuccess {Date} startTime The startTime of the activity.
* @apiSuccess {Number} duration The duration of the activity (in minutes).
* @apiSuccess {ObjectId} course The course of the activity (ObjectId).
* @apiSuccess {ObjectId} faculty The faculty alloted for the activity(ObjectId).
* @apiSuccess {String} type The type of activity.One of possible LECTURE, PRACTICAL, TUTORIAL.
* @apiSuccess {ObjectId} task The task of the activity (ObjectId).One of possible Topic,Practical,Tutorial.
* @apiSuccess {ObjectId} group The group of the activity (ObjectId).
* @apiSucess {ObjectId} students the students who gonna attend the activity(ObjectId).
*/

/**
* @api {get} /activity/list Get Activity List
* @apiName GetActivityList
* @apiGroup Activity
*
* @apiQuery {Date} startTime The startTime of the activity.
* @apiQuery {Number} duration The duration of the activity (in minutes).
* @apiQUERY {ObjectId} course The course of the activity (ObjectId).
* @apiQuery {ObjectId} faculty The faculty alloted for the activity(ObjectId).
* @apiQuery {String} type The type of activity.One of possible LECTURE, PRACTICAL, TUTORIAL.
* @apiQuery {ObjectId} task The task of the activity (ObjectId).One of possible Topic,Practical,Tutorial.
* @apiQuery {ObjectId} group The group of the activity (ObjectId).
* @apiQuery {ObjectId} students the students who gonna attend the activity(ObjectId).
*
* @apiSuccess {Date} startTime The startTime of the activity.
* @apiSuccess {Number} duration The duration of the activity (in minutes).
* @apiSuccess {ObjectId} course The course of the activity (ObjectId).
* @apiSuccess {ObjectId} faculty The faculty alloted for the activity(ObjectId).
* @apiSuccess {String} type The type of activity.One of possible LECTURE, PRACTICAL, TUTORIAL.
* @apiSuccess {ObjectId} task The task of the activity (ObjectId).One of possible Topic,Practical,Tutorial.
* @apiSuccess {ObjectId} group The group of the activity (ObjectId).
* @apiSucess {ObjectId} students the students who gonna attend the activity(ObjectId).
*/
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import tutorialRouter from "#routes/tutorial";
import assignmentRouter from "#routes/assignment";
import timetableRouter from "#routes/timetable";
import courseworkRouter from "#routes/coursework";
import activityRouter from "#routes/activity";
import moduleRouter from "#routes/module";
import { identifyUser } from "#middleware/identifyUser";
import departmentRouter from "#routes/department";
Expand Down Expand Up @@ -46,6 +47,7 @@ app.use("/department", departmentRouter);
app.use("/practical", practicalRouter);
app.use("/organization", organizationRouter);
app.use("/student", studentRouter);
app.use("/activity", activityRouter);
app.use("/tutorial", tutorialRouter);
app.use("/assignment", assignmentRouter);
app.use("/timetable", timetableRouter);
Expand Down
64 changes: 64 additions & 0 deletions controller/activity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
createActivity,deleteActivityById, activityList ,updateActivityById,
}from "#services/activity";
import {logger} from "#util" ;

async function addActivity(req,res) {
const{
activityBlueprint,
startTime,
duration,
course,
faculty,
type,
task,
group,
students,
}=req.body;
try{
const newActivity = await createActivity(activityBlueprint,startTime,duration,course,faculty,type,task,group,students);
res.json ({res: `added activity ${newActivity.id}`, id: newActivity.id});
} catch (error){
logger.error ("Error while inserting",error);
res.status(500);
res.json({err:"Error while inserting in DB"});
}
}

async function updateActivity(req,res){
const { id }=req.params;
const {
...data
}=req.body;
try {
await updateActivityById(id,data);
res.json({res:`updated activity with id ${id}`});
}catch (error){
logger.error("Error while updating",error);
res.status(500);
res.json({err:"Error while updating in DB"});
}
}

async function getActivity(req,res){
const filter = req.query;
const activitylist =await activityList(filter);
res.json({res:activitylist});
}


async function deleteActivity(res,req){
const { id }=req.params;
try{
await deleteActivityById(id);

res.json({res:`Deleted activity with ID ${id}`});
}catch(error){
logger.error ("Error while deleting",error);
res.status(500).json({error:"Error while deleting from DB"});
}
}

export default {
addActivity, deleteActivity ,getActivity ,updateActivity,
};
46 changes: 25 additions & 21 deletions models/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,41 @@ const activitySchema = {

const Activity = connector.model("Activity", activitySchema);

// crud
///crud operation///

async function create(activityData) {
//add a activity to the database
async function create(activityData){
const {
activityBlueprint, startTime, duration, course, faculty, type, task, group, students,
} = activityData;
const activity = new Activity({
activityBlueprint, startTime, duration, course, faculty, type, task, group, students,
activityBlueprint, startTime,duration,course,faculty,type,task,group,students,
}=activityData;
const activity= new Activity({
activityBlueprint, startTime,duration,course,faculty,type,task,group,students,
});
const activityDoc = await activity.save();
const activityDoc =await activity.save();
return activityDoc;
}

async function read(filter, limit = 1) {
const activityDoc = await Activity.find(filter).limit(limit);
return activityDoc;
//Retrieve activity based on a given filter and limit
async function read(filter,limit=1){
const activityDoc = await Activity.find (filter).limit(limit);
return activityDoc ;
}

async function update(filter, updateObject, options = { multi: true }) {
const updateResult = await Activity.updateMany(filter, { $set: updateObject }, options);
return updateResult.acknowledged;
//update activity based on a given filter
async function update(filter,updateObject,options={multi:true}){
const updateActivity= await Activity.updateMany(filter,{$set:updateObject},options);
return updateActivity.acknowledged;
}

async function remove(filter) {
const deleteResult = await Activity.deleteMany(filter);
return deleteResult.acknowledged;
//Delete activity based on a given filter
async function remove(filter){
const deleteActivity= await Activity.deleteMany(filter).exec();
return deleteActivity.acknowledged
}

export default {
create,
read,
update,
remove,
//export crud functions

export default{
create,read,update,remove,
};

10 changes: 10 additions & 0 deletions routes/activity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import express from "express";
import activityController from "#controller/activity";

const router=express.Router();
router.post("/add",activityController.addActivity);
router.get("/list",activityController.getActivity);
router.post("/update/:id",activityController.updateActivity);
router.delete("/delete/:id",activityController.deleteActivity);

export default router;
33 changes: 33 additions & 0 deletions services/activity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Activity from "#models/activity" ;
import databaseError from "#error/database";

export async function createActivity (activityBlueprint,startTime,duration,course,faculty,type,task,group,students){
const newActivity = await Activity.create({
activityBlueprint,startTime,duration,course,faculty,task,type,group,students,
});
if (newActivity){
return newActivity;
}
throw new databaseError.DataEntryError("actvity");
}

export async function updateActivityById(id,data){
const updated= await Activity.update({_id:id},data);
if (updated){
return updated;
}
throw new databaseError.DataEntryError("activity");
}

export async function activityList(filter){
const activitylist = await Activity.read(filter,0);
return activitylist;
}

export async function deleteActivityById(id){
const deleted = await Activity.remove({_id:id},data);
if(deleted){
return deleted;
}
throw new databaseError.DataDeleteError("activity");
}
Loading