diff --git a/src/request_results.ts b/src/request_results.ts index 28f4aae..85f6f88 100644 --- a/src/request_results.ts +++ b/src/request_results.ts @@ -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 { diff --git a/src/server.ts b/src/server.ts index fff8d1f..97fd0bf 100644 --- a/src/server.ts +++ b/src/server.ts @@ -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) @@ -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)