Skip to content

Commit

Permalink
Update status code based on sign up result.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Sep 13, 2024
1 parent c024b1a commit 6c84438
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/request_results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ export enum SignUpResult {

export namespace SignUpResult {
export function statusCode(result: SignUpResult): number {
return result === SignUpResult.BadRequest ? 400 : 200;
switch (result) {
case SignUpResult.Ok:
return 200;
case SignUpResult.EmailExists:
return 409;
case SignUpResult.BadRequest:
case SignUpResult.Error:
return 400;
}
}

export function success(result: SignUpResult): boolean {
Expand Down
8 changes: 4 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ app.post([
result = await signUpEducator(maybe.right);
} else {
result = SignUpResult.BadRequest;
res.status(400);
}
res.json({
const statusCode = SignUpResult.statusCode(result);
res.status(statusCode).json({
educator_info: data,
status: result,
success: SignUpResult.success(result)
Expand All @@ -266,9 +266,9 @@ app.post([
result = await signUpStudent(maybe.right);
} else {
result = SignUpResult.BadRequest;
res.status(400);
}
res.json({
const statusCode = SignUpResult.statusCode(result);
res.status(statusCode).json({
student_info: data,
status: result,
success: SignUpResult.success(result)
Expand Down

0 comments on commit 6c84438

Please sign in to comment.