diff --git a/_apidoc.js b/_apidoc.js index 2d6b740..c91ac79 100644 --- a/_apidoc.js +++ b/_apidoc.js @@ -34,10 +34,10 @@ * @api {post} /auth Login User * @apiName LoginUser * @apiGroup Authentication - * + * * @apiBody {String} id User ID. * @apiBody {String} password User password. - * + * * @apiSuccess {String} res Response message. * @apiSuccess {Object} user User details. * @apiSuccess {String} user.uid User ID. @@ -45,7 +45,7 @@ * @apiSuccess {String} user.emailId User email ID. * @apiSuccess {String} user.type User type. * @apiSuccess {String} user.token User token. - * + * * @apiSuccessExample Success Response: * HTTP/1.1 200 OK * { @@ -58,7 +58,7 @@ * "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." * } * } - * + * * @apiError (Error 403) UserDoesNotExist Incorrect ID or password. * @apiError (Error 500) ServerError Something is wrong on our side. Try again. */ @@ -68,16 +68,16 @@ * @apiName ValidateUser * @apiGroup Authentication * @apiDescription Validates the user's authentication token. - * + * * @apiHeader {String} Authorization User's authentication token. - * + * * @apiSuccess {Object} res User object. * @apiSuccess {Object} res.user User details. * @apiSuccess {String} res.user.uid User ID. * @apiSuccess {String} res.user.name User name. * @apiSuccess {String} res.user.emailId User email ID. * @apiSuccess {String} res.user.type User type. - * + * * @apiSuccessExample Success Response: * HTTP/1.1 200 OK * { @@ -99,18 +99,18 @@ * @apiName SendOTP * @apiGroup Authentication * @apiDescription Sends an OTP (One-Time Password) to the user's email ID. - * + * * @apiBody {String} uid User ID. * @apiBody {String} emailId User email ID. - * + * * @apiSuccess {String} res Response message. - * + * * @apiSuccessExample Success Response: * HTTP/1.1 200 OK * { * "res": "otp sent to emailID" * } - * + * * @apiError (Error) IncorrectUidOrEmail Incorrect UID or emailId. */ @@ -119,19 +119,19 @@ * @apiName ResetPassword * @apiGroup Authentication * @apiDescription Resets the user's password using the provided OTP (One-Time Password). - * + * * @apiBody {String} uid User ID. * @apiBody {String} otp One-Time Password received by the user. * @apiBody {String} password New password. - * + * * @apiSuccess {String} res Response message. - * + * * @apiSuccessExample Success Response: * HTTP/1.1 200 OK * { * "res": "successfully updated password" * } - * + * * @apiError (Error) IncorrectOtp Incorrect OTP. * @apiError (Error 500) UpdateError Something went wrong while updating password. * @apiError (Error 500) ServerError Something went wrong. @@ -169,7 +169,7 @@ * @apiQuery {String} wing Wing of Infrastructure. One of possible A,B,C. * @apiQuery {Number} floor Floor of Infrastructure. * @apiQuery {Number} capacity Capacity of Infrastructure. - * + * * @apiSuccess {Infrastructure[]} res Array of Filtered Infrastructure Doc . * @apiSuccess {String} infrastructure.name Name of Infrastructure * @apiSuccess {String} infrastructure.type Type of Infrastructure. One of possible Lab, Classroom. @@ -178,7 +178,6 @@ * @apiSuccess {Number} infrastructure.capacity Capacity of Infrastructure. */ - /** * @api {delete} /infrastructure/delete/:infrastructureId Delete Infrastructure * @apiName DeleteInfrastructure @@ -190,7 +189,7 @@ * * @apiError (Error 500) err Error message if there was an error during the deletion. * -**/ +* */ // ------------------------------------------------------------------------------------------ // Accreditation. @@ -222,4 +221,3 @@ * "err": "Error while inserting in DB" * } */ - diff --git a/controller/accreditation.js b/controller/accreditation.js index b3a5209..c4e2404 100644 --- a/controller/accreditation.js +++ b/controller/accreditation.js @@ -1,4 +1,4 @@ -import { addNewAccreditation, deleteAccreditationById } from "#services/accreditation"; +import { addNewAccreditation, deleteAccreditationById, updateAccreditationById } from "#services/accreditation"; import { logger } from "#util"; async function addAccreditation(req, res) { @@ -16,7 +16,7 @@ async function addAccreditation(req, res) { } } async function deleteAccreditation(req, res) { - const { accredationId} = req.params; + const { accredationId } = req.params; try { await deleteAccreditationById(accredationId); res.json({ res: "Accreditation deleted successfully" }); @@ -26,4 +26,19 @@ async function deleteAccreditation(req, res) { res.json({ err: "Error while deleting from DB" }); } } -export default { addAccreditation, deleteAccreditation }; + +async function updateAccreditation(req, res) { + const { + id, ...data + } = req.body; + + try { + await updateAccreditationById(id, data); + res.json({ res: "accreditation updated" }); + } catch (error) { + logger.error("Error while inserting", error); + res.status(500); + res.json({ err: "Error while inserting in DB" }); + } +} +export default { addAccreditation, updateAccreditation, deleteAccreditation }; diff --git a/controller/infrastructure.js b/controller/infrastructure.js index d6ddee9..6cdcffa 100644 --- a/controller/infrastructure.js +++ b/controller/infrastructure.js @@ -1,4 +1,6 @@ -import { createInfrastructure, deleteInfrastructureById, infrastructureList, updateInfrastructureById } from "#services/infrastructure" +import { + createInfrastructure, deleteInfrastructureById, infrastructureList, updateInfrastructureById, +} from "#services/infrastructure"; import { logger } from "#util"; async function addInfrastructure(req, res) { @@ -15,28 +17,26 @@ async function addInfrastructure(req, res) { } } - -async function updateInfrastructure(req,res){ - const{ +async function updateInfrastructure(req, res) { + const { id, ...data - }= req.body; - try{ - await updateInfrastructureById(id,data); - res.json({res: `updated infrastructure with id ${id}`}); - }catch(error){ - logger.error("Error while updating",error); - res.status(500); - res.json({err:"Error while updaing in DB"}); - } + } = req.body; + try { + await updateInfrastructureById(id, data); + res.json({ res: `updated infrastructure with id ${id}` }); + } catch (error) { + logger.error("Error while updating", error); + res.status(500); + res.json({ err: "Error while updaing in DB" }); } +} async function getInfrastructure(req, res) { - const filter= req.query; + const filter = req.query; const infralist = await infrastructureList(filter); res.json({ res: infralist }); } - async function deleteInfrastructure(req, res) { const { infrastructureId } = req.params; try { @@ -48,4 +48,6 @@ async function deleteInfrastructure(req, res) { res.status(500).json({ error: "Error while deleting from DB" }); } } -export default { addInfrastructure, deleteInfrastructure, getInfrastructure, updateInfrastructure}; +export default { + addInfrastructure, deleteInfrastructure, getInfrastructure, updateInfrastructure, +}; diff --git a/error/DataDeleteError.js b/error/DataDeleteError.js index 3252446..c74c553 100644 --- a/error/DataDeleteError.js +++ b/error/DataDeleteError.js @@ -1,6 +1,6 @@ export class DataDeleteError extends Error { - constructor(modelName) { - super(`Error while deleting document in ${modelName}`); - this.name = "DataDeleteError"; - } - } \ No newline at end of file + constructor(modelName) { + super(`Error while deleting document in ${modelName}`); + this.name = "DataDeleteError"; + } +} diff --git a/error/database.js b/error/database.js index 93571c8..f2017dc 100644 --- a/error/database.js +++ b/error/database.js @@ -5,5 +5,5 @@ import { UserDoesNotExistError } from "#error/UserDoesNotExist"; import { DataDeleteError } from "#error/DataDeleteError"; export default { - DataEntryError, DataNotFoundError, UpdateError, UserDoesNotExistError,DataDeleteError, + DataEntryError, DataNotFoundError, UpdateError, UserDoesNotExistError, DataDeleteError, }; diff --git a/models/department.js b/models/department.js index c61ce0b..120bcf8 100644 --- a/models/department.js +++ b/models/department.js @@ -16,7 +16,6 @@ const departmentSchema = { }], }; - const Department = connector.model("Department", departmentSchema); // for creating @@ -56,4 +55,3 @@ export default { update, remove, }; - diff --git a/routes/accreditation.js b/routes/accreditation.js index 94e72c4..e39a370 100644 --- a/routes/accreditation.js +++ b/routes/accreditation.js @@ -4,4 +4,6 @@ import accreditationController from "#controller/accreditation"; const router = express.Router(); router.post("/add", accreditationController.addAccreditation); router.delete("/delete/:accredationId", accreditationController.deleteAccreditation); +router.post("/update", accreditationController.updateAccreditation); + export default router; diff --git a/routes/infrastructure.js b/routes/infrastructure.js index 8e774fa..5a7942f 100644 --- a/routes/infrastructure.js +++ b/routes/infrastructure.js @@ -3,8 +3,8 @@ import infrastructureController from "#controller/infrastructure"; const router = express.Router(); router.post("/add", infrastructureController.addInfrastructure); -router.get("/list",infrastructureController.getInfrastructure); -router.post("/update",infrastructureController.updateInfrastructure); +router.get("/list", infrastructureController.getInfrastructure); +router.post("/update", infrastructureController.updateInfrastructure); router.post("/delete/:infrastructureId", infrastructureController.deleteInfrastructure); export default router; diff --git a/services/accreditation.js b/services/accreditation.js index 0dc224e..802051b 100644 --- a/services/accreditation.js +++ b/services/accreditation.js @@ -14,13 +14,22 @@ export async function addNewAccreditation(name, agencyName, dateofAccreditation, throw new databaseError.DataEntryError("Accreditation"); } -export async function deleteAccreditationById(accredationId){ - const deleted = await accreditation.remove({_id: accredationId}); +export async function deleteAccreditationById(accredationId) { + const deleted = await accreditation.remove({ _id: accredationId }); if (deleted) { - return deleted + return deleted; } throw new databaseError.DataDeleteError("Accreditation"); } + +export async function updateAccreditationById(id, data) { + const updated = await accreditation.update({ _id: id }, data); + if (updated) { + return updated; + } + throw new databaseError.DataEntryError("Accrediation"); +} + export default { - deleteAccreditationById, addNewAccreditation -} \ No newline at end of file + deleteAccreditationById, addNewAccreditation, updateAccreditationById, +}; diff --git a/services/infrastructure.js b/services/infrastructure.js index 422c99f..073c4e2 100644 --- a/services/infrastructure.js +++ b/services/infrastructure.js @@ -11,12 +11,12 @@ export async function createInfrastructure(name, type, wing, floor, capacity) { throw new databaseError.DataEntryError("infrastructure"); } -export async function updateInfrastructureById(id,data){ - const updated = await infrastructure.update({_id: id},data); - if(updated){ +export async function updateInfrastructureById(id, data) { + const updated = await Infrastructure.update({ _id: id }, data); + if (updated) { return updated; } -throw new databaseError.DataEntryError("Infrastructure"); + throw new databaseError.DataEntryError("Infrastructure"); } export async function infrastructureList(filter) { @@ -25,10 +25,9 @@ export async function infrastructureList(filter) { } export async function deleteInfrastructureById(infrastructureId) { - const deleted = await Infrastructure.remove({ _id: infrastructureId }); - if (deleted){ + const deleted = await Infrastructure.remove({ _id: infrastructureId }); + if (deleted) { return deleted; } throw new databaseError.DataDeleteError("infrastructure"); - }