1
1
// import { Prisma } from "@prisma/client";
2
2
import { Router } from "express" ;
3
- import prisma from ' ../prisma' ;
3
+ import prisma from " ../prisma" ;
4
4
import DonationService from "../services/implementations/donationService" ;
5
5
import IDonationService from "../services/interfaces/donationService" ;
6
6
import { getErrorMessage } from "../utilities/errorUtils" ;
@@ -11,44 +11,45 @@ const donationRouter = Router();
11
11
12
12
// display all donations
13
13
donationRouter . get ( "/" , async ( req : any , res : any ) => {
14
- try {
15
- const allDonations = await donationService . getAllDonations ( ) ;
16
- console . log ( ' getting donations' ) ;
17
- res . status ( 200 ) . json ( allDonations ) ;
18
- } catch ( error ) {
19
- res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
20
- }
14
+ try {
15
+ const allDonations = await donationService . getAllDonations ( ) ;
16
+ console . log ( " getting donations" ) ;
17
+ res . status ( 200 ) . json ( allDonations ) ;
18
+ } catch ( error ) {
19
+ res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
20
+ }
21
21
} ) ;
22
22
23
23
// display all donations made by a user
24
24
donationRouter . get ( "/:id" , async ( req : any , res : any ) => {
25
- const id = req . params . id ;
25
+ const { id } = req . params ;
26
26
27
- try {
28
- const userDonations = await donationService . getUserDonation ( id ) ;
27
+ try {
28
+ const userDonations = await donationService . getUserDonation ( id ) ;
29
29
30
- res . status ( 200 ) . json ( userDonations ) ;
31
- } catch ( error ) {
32
- res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
33
- }
30
+ res . status ( 200 ) . json ( userDonations ) ;
31
+ } catch ( error ) {
32
+ res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
33
+ }
34
34
} ) ;
35
35
36
36
// Each donation has 1 cause associated with it, the donation from user will be split before calling this route.
37
37
donationRouter . post ( "/give" , async ( req : any , res : any ) => {
38
- try {
39
- const { user_id, amount, cause_id, is_recurring, confirmation_email_sent } = req . body ;
40
-
41
- const newDonation = await donationService . createDonation (
42
- user_id ,
43
- amount ,
44
- cause_id ,
45
- is_recurring ,
46
- confirmation_email_sent
47
- ) ;
48
- res . status ( 200 ) . json ( newDonation ) ;
49
- } catch ( error ) {
50
- res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
51
- }
52
- } )
53
-
54
- export default donationRouter ;
38
+ try {
39
+ const { user_id, amount, cause_id, is_recurring, confirmation_email_sent } =
40
+ req . body ;
41
+
42
+ const newDonation = await donationService . createDonation (
43
+ user_id ,
44
+ amount ,
45
+ cause_id ,
46
+ is_recurring ,
47
+ confirmation_email_sent ,
48
+ ) ;
49
+ res . status ( 200 ) . json ( newDonation ) ;
50
+ } catch ( error ) {
51
+ res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
52
+ }
53
+ } ) ;
54
+
55
+ export default donationRouter ;
0 commit comments