3
3
get_all_organizer_payment_invoice,
4
4
get_organizer_payment_invoice_by_id,
5
5
} = require ( "../services/organizerPaymentInvoiceService" ) ;
6
-
6
+ const { manage_organizer_level } = require ( "../services/organizerService" ) ;
7
+ const { getOrganizerIdFromToken } = require ( "../helper/index" ) ;
7
8
const messages = {
8
9
notFound : "No Data Found" ,
9
10
serverError : "Internal Server Error" ,
@@ -25,17 +26,24 @@ const addOrganizerInvoice = async (req, res) => {
25
26
26
27
const upgradeOrganizerPayment = async ( req , res ) => {
27
28
try {
28
- const id = await getOrganizerInvoiceById ( ) ;
29
+ const id = await getOrganizerIdFromToken ( req , res ) ;
30
+ if ( id === null ) {
31
+ return res . status ( 403 ) . send ( "Invalid token." ) ;
32
+ }
33
+
29
34
const accountLevelId = req . body . subscription . accountLevelId ;
30
- const data = await add_organizer_payment_invoice ( req . body . payment ) ;
31
35
32
- if ( ! data . error ) {
33
- return res . status ( 200 ) . json ( data ) ;
36
+ const payment = await add_organizer_payment_invoice ( req . body . payment ) ;
37
+
38
+ const upgradeAccount = await manage_organizer_level ( id , accountLevelId ) ;
39
+
40
+ if ( ! payment . error ) {
41
+ return res . status ( 200 ) . json ( { payment, upgradeAccount } ) ;
34
42
} else {
35
43
return res . status ( 404 ) . json ( { message : messages . notFound } ) ;
36
44
}
37
45
} catch ( error ) {
38
- return res . status ( 500 ) . json ( { message : messages . serverError } ) ;
46
+ res . json ( { error } ) ;
39
47
}
40
48
} ;
41
49
0 commit comments