Skip to content

Commit 33aa06b

Browse files
committed
add jsdocs to userController.signup routes
1 parent ea21fc1 commit 33aa06b

2 files changed

Lines changed: 61 additions & 25 deletions

File tree

server/controllers/user.controller/signup.ts

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import {
1010
VerifyEmailQuery
1111
} from '../../types';
1212

13+
/**
14+
* - Method: `POST`
15+
* - Endpoint: `/signup`
16+
* - Authenticated: `false`
17+
* - Id: `UserController.createUser`
18+
*
19+
* Description:
20+
* - Create a new user
21+
*/
1322
export const createUser: RequestHandler<
1423
{},
1524
PublicUserOrError,
@@ -71,6 +80,15 @@ export const createUser: RequestHandler<
7180
}
7281
};
7382

83+
/**
84+
* - Method: `GET`
85+
* - Endpoint: `/signup/duplicate_check`
86+
* - Authenticated: `false`
87+
* - Id: `UserController.duplicateUserCheck`
88+
*
89+
* Description:
90+
* - Check if a user with the same email or username already exists
91+
*/
7492
export const duplicateUserCheck: RequestHandler<
7593
{},
7694
{},
@@ -94,29 +112,15 @@ export const duplicateUserCheck: RequestHandler<
94112
});
95113
};
96114

97-
export const verifyEmail: RequestHandler<{}, {}, {}, VerifyEmailQuery> = async (
98-
req,
99-
res
100-
) => {
101-
const token = req.query.t;
102-
const user = await User.findOne({
103-
verifiedToken: token,
104-
verifiedTokenExpires: { $gt: new Date() }
105-
}).exec();
106-
if (!user) {
107-
res.status(401).json({
108-
success: false,
109-
message: 'Token is invalid or has expired.'
110-
});
111-
return;
112-
}
113-
user.verified = User.EmailConfirmation().Verified;
114-
user.verifiedToken = null;
115-
user.verifiedTokenExpires = null;
116-
await user.save();
117-
res.json({ success: true });
118-
};
119-
115+
/**
116+
* - Method: `POST`
117+
* - Endpoint: `/verify/send`
118+
* - Authenticated: `false`
119+
* - Id: `UserController.emailVerificationInitiate`
120+
*
121+
* Description:
122+
* - Send a Confirm Email email to verify that the user owns the specified email account
123+
*/
120124
export const emailVerificationInitiate: RequestHandler<
121125
{},
122126
PublicUserOrError
@@ -157,3 +161,35 @@ export const emailVerificationInitiate: RequestHandler<
157161
res.status(500).json({ error: err });
158162
}
159163
};
164+
165+
/**
166+
* - Method: `GET`
167+
* - Endpoint: `/verify`
168+
* - Authenticated: `false`
169+
* - Id: `UserController.verifyEmail`
170+
*
171+
* Description:
172+
* - Used in the Confirm Email's link to verify a user's email is attached to their account
173+
*/
174+
export const verifyEmail: RequestHandler<{}, {}, {}, VerifyEmailQuery> = async (
175+
req,
176+
res
177+
) => {
178+
const token = req.query.t;
179+
const user = await User.findOne({
180+
verifiedToken: token,
181+
verifiedTokenExpires: { $gt: new Date() }
182+
}).exec();
183+
if (!user) {
184+
res.status(401).json({
185+
success: false,
186+
message: 'Token is invalid or has expired.'
187+
});
188+
return;
189+
}
190+
user.verified = User.EmailConfirmation().Verified;
191+
user.verifiedToken = null;
192+
user.verifiedTokenExpires = null;
193+
await user.save();
194+
res.json({ success: true });
195+
};

server/routes/user.routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const router = Router();
1313
router.post('/signup', UserController.createUser);
1414
// GET /signup/duplicate_check
1515
router.get('/signup/duplicate_check', UserController.duplicateUserCheck);
16-
// GET /verify
17-
router.get('/verify', UserController.verifyEmail);
1816
// POST /verify/send
1917
router.post('/verify/send', UserController.emailVerificationInitiate);
18+
// GET /verify
19+
router.get('/verify', UserController.verifyEmail);
2020

2121
/**
2222
* ===============

0 commit comments

Comments
 (0)