Skip to content

Commit 6bbdbc0

Browse files
Merge pull request #265 from tcet-opensource/development
Biweekly Merge
2 parents 022398c + 6963dd3 commit 6bbdbc0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3891
-3028
lines changed

_apidoc.js

Lines changed: 296 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,311 @@
11
// ------------------------------------------------------------------------------------------
22
// General apiDoc documentation blocks and old history blocks.
33
// ------------------------------------------------------------------------------------------
4-
54
// ------------------------------------------------------------------------------------------
65
// Current Success.
76
// ------------------------------------------------------------------------------------------
8-
97
// ------------------------------------------------------------------------------------------
108
// Current Errors.
119
// ------------------------------------------------------------------------------------------
12-
1310
// ------------------------------------------------------------------------------------------
1411
// Current Permissions.
1512
// ------------------------------------------------------------------------------------------
16-
1713
// ------------------------------------------------------------------------------------------
1814
// History.
1915
// ------------------------------------------------------------------------------------------
16+
17+
// ------------------------------------------------------------------------------------------
18+
// Index.
19+
// ------------------------------------------------------------------------------------------
20+
21+
/**
22+
* @api {get} / Retrieve Home Information
23+
* @apiName GetIndex
24+
* @apiGroup Index
25+
*
26+
* @apiSuccess {String} res server working.
27+
*/
28+
29+
// ------------------------------------------------------------------------------------------
30+
// User.
31+
// ------------------------------------------------------------------------------------------
32+
33+
/**
34+
* @api {post} /add Add new User
35+
* @apiName AddUser
36+
* @apiGroup User
37+
*
38+
* @apiBody {String} name Name and surname of user
39+
* @apiBody {String} password Password of the user
40+
* @apiBody {String} emailId EmailID of the user. It would be the college assosiated emailID
41+
* @apiBody {String} uid This will be their ERPID
42+
* @apiBody {String="Student", "Faculty"} userType This will be type of user.
43+
* currently we support only 2
44+
*
45+
* @apiSuccess {String} res returns success message "added user with \<ID\>".
46+
*
47+
* @apiError (Error 500) err Error while inserting in Database.
48+
*/
49+
50+
// ------------------------------------------------------------------------------------------
51+
// Auth.
52+
// ------------------------------------------------------------------------------------------
53+
54+
/**
55+
* @api {post} /auth Login User
56+
* @apiName LoginUser
57+
* @apiGroup Authentication
58+
*
59+
* @apiBody {String} id User ID.
60+
* @apiBody {String} password User password.
61+
*
62+
* @apiSuccess {String} res Response message.
63+
* @apiSuccess {Object} user User details.
64+
* @apiSuccess {String} user.uid User ID.
65+
* @apiSuccess {String} user.name User name.
66+
* @apiSuccess {String} user.emailId User email ID.
67+
* @apiSuccess {String} user.type User type.
68+
* @apiSuccess {String} user.token User token.
69+
*
70+
* @apiSuccessExample Success Response:
71+
* HTTP/1.1 200 OK
72+
* {
73+
* "res": "welcome",
74+
* "user": {
75+
* "uid": "123",
76+
* "name": "Some User",
77+
* "emailId": "someuser@example.com",
78+
* "type": "user",
79+
* "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
80+
* }
81+
* }
82+
*
83+
* @apiError (Error 403) UserDoesNotExist Incorrect ID or password.
84+
* @apiError (Error 500) ServerError Something is wrong on our side. Try again.
85+
*/
86+
87+
/**
88+
* @api {post} /auth/validateUser Validate User
89+
* @apiName ValidateUser
90+
* @apiGroup Authentication
91+
* @apiDescription Validates the user's authentication token.
92+
*
93+
* @apiHeader {String} Authorization User's authentication token.
94+
*
95+
* @apiSuccess {Object} res User object.
96+
* @apiSuccess {Object} res.user User details.
97+
* @apiSuccess {String} res.user.uid User ID.
98+
* @apiSuccess {String} res.user.name User name.
99+
* @apiSuccess {String} res.user.emailId User email ID.
100+
* @apiSuccess {String} res.user.type User type.
101+
*
102+
* @apiSuccessExample Success Response:
103+
* HTTP/1.1 200 OK
104+
* {
105+
* "res": {
106+
* "user": {
107+
* "uid": "123",
108+
* "name": "Some User",
109+
* "emailId": "someuser@example.com",
110+
* "type": "user"
111+
* },
112+
* "msg": "user validated",
113+
* "err": null
114+
* }
115+
* }
116+
*/
117+
118+
/**
119+
* @api {post} /auth/sendOTP Send OTP
120+
* @apiName SendOTP
121+
* @apiGroup Authentication
122+
* @apiDescription Sends an OTP (One-Time Password) to the user's email ID.
123+
*
124+
* @apiBody {String} uid User ID.
125+
* @apiBody {String} emailId User email ID.
126+
*
127+
* @apiSuccess {String} res Response message.
128+
*
129+
* @apiSuccessExample Success Response:
130+
* HTTP/1.1 200 OK
131+
* {
132+
* "res": "otp sent to emailID"
133+
* }
134+
*
135+
* @apiError (Error) IncorrectUidOrEmail Incorrect UID or emailId.
136+
*/
137+
138+
/**
139+
* @api {post} /auth/resetPassword Reset Password
140+
* @apiName ResetPassword
141+
* @apiGroup Authentication
142+
* @apiDescription Resets the user's password using the provided OTP (One-Time Password).
143+
*
144+
* @apiBody {String} uid User ID.
145+
* @apiBody {String} otp One-Time Password received by the user.
146+
* @apiBody {String} password New password.
147+
*
148+
* @apiSuccess {String} res Response message.
149+
*
150+
* @apiSuccessExample Success Response:
151+
* HTTP/1.1 200 OK
152+
* {
153+
* "res": "successfully updated password"
154+
* }
155+
*
156+
* @apiError (Error) IncorrectOtp Incorrect OTP.
157+
* @apiError (Error 500) UpdateError Something went wrong while updating password.
158+
* @apiError (Error 500) ServerError Something went wrong.
159+
*/
160+
161+
// ------------------------------------------------------------------------------------------
162+
// Infrastructure.
163+
// ------------------------------------------------------------------------------------------
164+
165+
/**
166+
* @api {post} /infrastructure/add Add Infrastructure
167+
* @apiName AddInfrastructure
168+
* @apiGroup Infrastructure
169+
*
170+
* @apiBody {String} name The name of the infrastructure.
171+
* @apiBody {String} type The type of the infrastructure.
172+
* @apiBody {String} wing The wing where the infrastructure is located.
173+
* @apiBody {Number} floor The floor where the infrastructure is located.
174+
* @apiBody {Number} capacity The capacity of the infrastructure.
175+
*
176+
* @apiSuccess {String} res Success message with the ID of the added infrastructure.
177+
*
178+
* @apiError (Error 500) DatabaseError Error while inserting in the database.
179+
*
180+
* @apiDescription Adds a new infrastructure to the system.
181+
*/
182+
183+
/**
184+
* @api {get} infrastructure/list Get Infrastructure List
185+
* @apiName GetInfrastructure
186+
* @apiGroup Infrastructure
187+
*
188+
* @apiQuery {String} [name] Name of Infrastructure .
189+
* @apiQuery {String} [type] Type of Infrastructure. One of possible Lab, Classroom.
190+
* @apiQuery {String} [wing] Wing of Infrastructure. One of possible A,B,C.
191+
* @apiQuery {Number} [floor] Floor of Infrastructure.
192+
* @apiQuery {Number} [capacity] Capacity of Infrastructure.
193+
*
194+
* @apiSuccess {Infrastructure[]} res Array of Filtered Infrastructure Doc .
195+
* @apiSuccess {String} infrastructure._id ID of document given by database.
196+
* @apiSuccess {String} infrastructure.name Name of Infrastructure
197+
* @apiSuccess {String} infrastructure.type Type of Infrastructure. One of possible Lab, Classroom.
198+
* @apiSuccess {String} infrastructure.wing Wing of Infrastructure. One of possible A,B,C.
199+
* @apiSuccess {Number} infrastructure.floor Floor of Infrastructure.
200+
* @apiSuccess {Number} infrastructure.capacity Capacity of Infrastructure.
201+
*/
202+
203+
/**
204+
* @api {delete} /infrastructure/delete/:infrastructureId Delete Infrastructure
205+
* @apiName DeleteInfrastructure
206+
* @apiGroup Infrastructure
207+
*
208+
* @apiParam {String} infrastructureId The ID of the infrastructure document to delete.
209+
*
210+
* @apiSuccess {String} res Success message indicating the deletion.
211+
*
212+
* @apiError (Error 500) err Error message if there was an error during the deletion.
213+
*
214+
* */
215+
216+
/**
217+
* @api {post} /infrastructure/update Update infrastructure details
218+
* @apiName UpdateInfrastructure
219+
* @apiGroup Infrastructure
220+
* @apiDescription update Existing Infrastructure details
221+
*
222+
* @apiBody {String} id Id of the infrastructure to be updated
223+
* @apiBody {String} [name] The name of the infrastructure.
224+
* @apiBody {String} [type] The type of the infrastructure.
225+
* @apiBody {String} [wing] The wing where the infrastructure is located.
226+
* @apiBody {Number} [floor] The floor where the infrastructure is located.
227+
* @apiBody {Number} [capacity] The capacity of the infrastructure.
228+
*
229+
* @apiSuccess {String} res infrastructure updated.
230+
* @apiError (Error 500) err Error in updating database
231+
*
232+
*/
233+
234+
// ------------------------------------------------------------------------------------------
235+
// Accreditation.
236+
// ------------------------------------------------------------------------------------------
237+
238+
/**
239+
* @api {post} /accreditation/add Add Accreditation
240+
* @apiName AddAccreditation
241+
* @apiGroup Accreditation
242+
* @apiDescription Add a new accreditation.
243+
*
244+
* @apiBody {String} name Accreditation name.
245+
* @apiBody {String} agencyName Agency name.
246+
* @apiBody {Date} dateofAccreditation Date of accreditation.
247+
* @apiBody {Date} dateofExpiry Date of expiry.
248+
*
249+
* @apiSuccess {String} res Response message.
250+
* @apiError (Error 500) UserNotFound The of the User was not found
251+
*
252+
* @apiSuccessExample Success-Response:
253+
* HTTP/1.1 200 OK
254+
* {
255+
* "res": "added accreditation Example Accreditation"
256+
* }
257+
*
258+
* @apiErrorExample Error-Response:
259+
* HTTP/1.1 500 Internal Server Error
260+
* {
261+
* "err": "Error while inserting in DB"
262+
* }
263+
*/
264+
265+
/**
266+
* @api {delete} /accreditation/delete/:accreditationId To delete Accreditation
267+
* @apiName DeleteAccreditation
268+
* @apiGroup Accreditation
269+
*
270+
* @apiParam {String} accreditationId The ID of the accreditation document to delete.
271+
*
272+
* @apiSuccess {String} res Success message indicating the deletion.
273+
*
274+
* @apiError (Error 500) err Error message if there was an error during the deletion.
275+
*
276+
* */
277+
278+
/**
279+
* @api {post} /accreditation/update update accreditation details
280+
* @apiName UpdateAccreditation
281+
* @apiGroup Accreditation
282+
* @apiDescription update Existing accreditation
283+
*
284+
* @apiBody {String} id Id of the accreditation to be updated
285+
* @apiBody {String} [name] Accreditation name.
286+
* @apiBody {String} [agencyName] Agency name.
287+
* @apiBody {Date} [dateofAccreditation] Date of accreditation.
288+
* @apiBody {Date} [dateofExpiry] Date of expiry.
289+
*
290+
* @apiSuccess {String} res Accreditation updated.
291+
* @apiError (Error 500) err Error in updating database
292+
*
293+
*/
294+
295+
/**
296+
* @api {get} accreditation/list Get Accreditation List
297+
* @apiName GetAccreditation
298+
* @apiGroup Accreditation
299+
*
300+
* @apiQuery {String} [name] Name of accreditation .
301+
* @apiQuery {String} [agencyName] Name of agency that issued the accreditation.
302+
* @apiQuery {Date} [dateofAccreditation] Date on which accreditation was issued.
303+
* @apiQuery {Date} [dateofExpiry] Date till which accreditation is valid.
304+
*
305+
* @apiSuccess {accreditation[]} res Array of Filtered accreditation Doc.
306+
* @apiSuccess {String} accreditation._id ID of document given by database.
307+
* @apiSuccess {String} accreditation.name Name of accreditation.
308+
* @apiSuccess {String} accreditation.agencyName Name of agency that issued the accreditation.
309+
* @apiSuccess {Date} accreditation.dateofAccreditation Date on which accreditation was issued.
310+
* @apiSuccess {Date} accreditation.dateofExpiry Date till which accreditation is valid.
311+
*/

app.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
import express from "express";
21
import path, { dirname } from "path";
2+
import { fileURLToPath } from "url";
3+
import express from "express";
34
import morgan from "morgan";
45
import cookieParser from "cookie-parser";
56
import cors from "cors";
6-
import { fileURLToPath } from "url";
77
import { logger } from "#util";
88
import indexRouter from "#routes/index";
99
import usersRouter from "#routes/users";
1010
import authRouter from "#routes/auth";
1111
import accreditationRouter from "#routes/accreditation";
1212
import infrastructureRouter from "#routes/infrastructure";
13+
import { identifyUser } from "#middleware/identifyUser";
1314

1415
const app = express();
1516
const currDirName = dirname(fileURLToPath(import.meta.url));
1617

18+
morgan.token("remote-user", (req) => req.user);
19+
app.use(identifyUser);
20+
app.use(cors());
21+
app.use(express.json());
22+
app.use(express.urlencoded({ extended: false }));
23+
app.use(cookieParser());
1724
app.use(morgan(
1825
":remote-addr - :remote-user \":method :url HTTP/:http-version\" :status \":referrer\" \":user-agent\"",
1926
{ stream: logger.stream },
2027
));
2128

22-
app.use(cors());
23-
app.use(express.json());
24-
app.use(express.urlencoded({ extended: false }));
25-
app.use(cookieParser());
2629
app.use(express.static(path.join(currDirName, "public")));
2730

2831
app.use("/", indexRouter);

0 commit comments

Comments
 (0)