Skip to content

Commit

Permalink
Merge branch 'development' into 126-Create-delete-endpoint-for-Infras…
Browse files Browse the repository at this point in the history
…tructure
  • Loading branch information
Hitansh159 authored Jul 8, 2023
2 parents 5bcf359 + b1ea6eb commit 1f4fe28
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 8 deletions.
153 changes: 148 additions & 5 deletions _apidoc.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,165 @@
// ------------------------------------------------------------------------------------------
// General apiDoc documentation blocks and old history blocks.
// ------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------
// Current Success.
// ------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------
// Current Errors.
// ------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------
// Current Permissions.
// ------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------
// History.
// ------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------
// Index.
// ------------------------------------------------------------------------------------------

/**
* @api {get} / Retrieve Home Information
* @apiName GetIndex
* @apiGroup index
*
* @apiSuccess {String} res server working.
*/

// ------------------------------------------------------------------------------------------
// Auth.
// ------------------------------------------------------------------------------------------

/**
* @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
* {
* "res": "welcome",
* "user": {
* "uid": "123",
* "name": "Some User",
* "emailId": "[email protected]",
* "type": "user",
* "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
* }
* }
*
* @apiError (Error 403) UserDoesNotExist Incorrect ID or password.
* @apiError (Error 500) ServerError Something is wrong on our side. Try again.
*/

/**
* @api {post} /auth/validateUser Validate User
* @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
* {
* "res": {
* "user": {
* "uid": "123",
* "name": "Some User",
* "emailId": "[email protected]",
* "type": "user"
* },
* "msg": "user validated",
* "err": null
* }
* }
*/

/**
* @api {post} /auth/sendOTP Send OTP
* @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.
*/

/**
* @api {post} /auth/resetPassword Reset Password
* @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.
*/

// ------------------------------------------------------------------------------------------
// Infrastructure.
// ------------------------------------------------------------------------------------------

/**
* @api {post} /infrastructure/add Add Infrastructure
* @apiName AddInfrastructure
* @apiGroup Infrastructure
*
* @apiBody {String} name The name of the infrastructure.
* @apiBody {String} type The type of the infrastructure.
* @apiBody {String} wing The wing where the infrastructure is located.
* @apiBody {Number} floor The floor where the infrastructure is located.
* @apiBody {Number} capacity The capacity of the infrastructure.
*
* @apiSuccess {String} res Success message with the ID of the added infrastructure.
*
* @apiError (Error 500) DatabaseError Error while inserting in the database.
*
* @apiDescription Adds a new infrastructure to the system.
*/


/**
* @api {delete} /infrastructure/delete/:infrastructureId Delete Infrastructure
* @apiName DeleteInfrastructure
Expand All @@ -28,4 +171,4 @@
*
* @apiError (Error 500) err Error message if there was an error during the deletion.
*
*/
**/
16 changes: 13 additions & 3 deletions controller/accreditation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addNewAccreditation } from "#services/accreditation";
import { addNewAccreditation, deleteAccreditationById } from "#services/accreditation";
import { logger } from "#util";

async function addAccreditation(req, res) {
Expand All @@ -15,5 +15,15 @@ async function addAccreditation(req, res) {
res.json({ err: "Error while inserting in DB" });
}
}

export default { addAccreditation };
async function deleteAccreditation(req, res) {
const { accredationId} = req.params;
try {
await deleteAccreditationById(accredationId);
res.json({ res: "Accreditation deleted successfully" });
} catch (error) {
logger.error("Error while deleting", error);
res.status(500);
res.json({ err: "Error while deleting from DB" });
}
}
export default { addAccreditation, deleteAccreditation };
1 change: 1 addition & 0 deletions routes/accreditation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import accreditationController from "#controller/accreditation";

const router = express.Router();
router.post("/add", accreditationController.addAccreditation);
router.delete("/delete/:accredationId", accreditationController.deleteAccreditation);
export default router;
11 changes: 11 additions & 0 deletions services/accreditation.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@ export async function addNewAccreditation(name, agencyName, dateofAccreditation,
}
throw new databaseError.DataEntryError("Accreditation");
}

export async function deleteAccreditationById(accredationId){
const deleted = await accreditation.remove({_id: accredationId});
if (deleted) {
return deleted
}
throw new databaseError.DataDeleteError("Accreditation");
}
export default {
deleteAccreditationById, addNewAccreditation
}

0 comments on commit 1f4fe28

Please sign in to comment.