1
1
import type { ElysiaContext , ResponseBody } from "../../types" ;
2
2
import { ErrorTypes } from "../../types/enums" ;
3
+ import { status501 } from "../../routes" ;
3
4
4
5
import UnivStudent from "../../db/models/univ_events/student" ;
5
6
import response from "../../utils/response" ;
6
7
import Strings from "../../config/strings" ;
7
- import { status501 } from "../../routes" ;
8
-
9
-
8
+ import Log from "../../utils/log" ;
10
9
11
10
/**
12
11
* Students API
13
12
* @author TotalElderBerry (Unknown af)
14
13
* @param context
15
14
*/
16
15
export function students ( context : ElysiaContext ) : Promise < ResponseBody | undefined > | ResponseBody {
17
- switch ( context . request . method ) {
18
- case "GET" :
19
- // return getStudents(context);
20
- case "POST" :
21
- return postStudents ( context ) ;
22
- case "PUT" :
23
- // return putStudents(context);
24
- case "OPTIONS" :
25
- return response . success ( ) ;
26
- }
27
-
28
- return status501 ( context ) ;
16
+ switch ( context . request . method ) {
17
+ case "POST" :
18
+ return postStudents ( context ) ;
19
+ case "OPTIONS" :
20
+ return response . success ( ) ;
21
+ }
22
+
23
+ return status501 ( context ) ;
29
24
}
30
25
31
- async function postStudents ( context : ElysiaContext ) {
32
- try {
33
- await UnivStudent . insert ( context . body ) ;
34
- // If no error, student is created
35
- return response . success ( Strings . STUDENT_CREATED ) ;
36
- } catch ( error ) {
37
- // if list of errors
38
- if ( Array . isArray ( error ) ) {
39
- context . set . status = 400 ;
40
- return response . error ( error [ 0 ] , error [ 1 ] ) ;
41
- }
42
-
43
- // If database error
44
- if ( error === ErrorTypes . DB_ERROR ) {
45
- context . set . status = 500 ;
46
- return response . error ( Strings . STUDENT_POST_ERROR ) ;
47
- }
26
+ /**
27
+ * POST /tatakforms/register
28
+ */
29
+ async function postStudents ( context : ElysiaContext ) {
30
+ try {
31
+ // Insert student
32
+ await UnivStudent . insert ( context . body ) ;
33
+ // If no error, student is created
34
+ return response . success ( "You have successfully registered! 💛" ) ;
35
+ }
36
+
37
+ catch ( error ) {
38
+ // if list of errors
39
+ if ( Array . isArray ( error ) ) {
40
+ context . set . status = 400 ;
41
+ return response . error ( error [ 0 ] , error [ 1 ] ) ;
48
42
}
43
+
44
+ // If database error
45
+ if ( error === ErrorTypes . DB_ERROR ) {
46
+ context . set . status = 500 ;
47
+ return response . error ( Strings . STUDENT_POST_ERROR ) ;
48
+ }
49
+
50
+ // If unknown error
51
+ Log . e ( error ) ;
52
+ context . set . status = 500 ;
53
+ return response . error ( Strings . GENERAL_SYSTEM_ERROR ) ;
54
+ }
49
55
}
0 commit comments