Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

120 created update endpoint for accreditation #190

Merged
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
36 changes: 17 additions & 19 deletions _apidoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@
* @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.
* @apiSuccess {String} user.name User name.
* @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
* {
Expand All @@ -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.
*/
Expand All @@ -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
* {
Expand All @@ -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.
*/

Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -178,7 +178,6 @@
* @apiSuccess {Number} infrastructure.capacity Capacity of Infrastructure.
*/


/**
* @api {delete} /infrastructure/delete/:infrastructureId Delete Infrastructure
* @apiName DeleteInfrastructure
Expand All @@ -190,7 +189,7 @@
*
* @apiError (Error 500) err Error message if there was an error during the deletion.
*
**/
* */

// ------------------------------------------------------------------------------------------
// Accreditation.
Expand Down Expand Up @@ -222,4 +221,3 @@
* "err": "Error while inserting in DB"
* }
*/

21 changes: 18 additions & 3 deletions controller/accreditation.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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" });
Expand All @@ -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 };
34 changes: 18 additions & 16 deletions controller/infrastructure.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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 {
Expand All @@ -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,
};
10 changes: 5 additions & 5 deletions error/DataDeleteError.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export class DataDeleteError extends Error {
constructor(modelName) {
super(`Error while deleting document in ${modelName}`);
this.name = "DataDeleteError";
}
}
constructor(modelName) {
super(`Error while deleting document in ${modelName}`);
this.name = "DataDeleteError";
}
}
2 changes: 1 addition & 1 deletion error/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
2 changes: 0 additions & 2 deletions models/department.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const departmentSchema = {
}],
};


const Department = connector.model("Department", departmentSchema);

// for creating
Expand Down Expand Up @@ -56,4 +55,3 @@ export default {
update,
remove,
};

2 changes: 2 additions & 0 deletions routes/accreditation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions routes/infrastructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
19 changes: 14 additions & 5 deletions services/accreditation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
deleteAccreditationById, addNewAccreditation, updateAccreditationById,
};
13 changes: 6 additions & 7 deletions services/infrastructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");

}