Major refactoring of get_session(), get_account(), get_nodemailer(), introduces ...
[ndcode_site.git] / api / contact / send_enquiry.json.jst
index edf8f55..137210d 100644 (file)
@@ -1,9 +1,7 @@
 let XDate = require('xdate')
 
 return async env => {
-  let get_globals = await _require('/_lib/get_globals.jst')
   let get_nodemailer = await _require('/_lib/get_nodemailer.jst')
-  let get_session = await _require('/_lib/get_session.jst')
   let post_request = await _require('/_lib/post_request.jst')
   let Problem = await _require('/_lib/Problem.jst')
 
@@ -32,21 +30,19 @@ return async env => {
         )
 
       let transaction = await env.site.database.Transaction()
-      let nodemailer, contact_from, contact_to
+      let nodemailer
+      let contact_from, contact_to
       try {
-        // initialize env.session_key, set cookie in env.response
-        get_session(env, transaction)
+        let root = await transaction.get({})
 
-        nodemailer = await get_nodemailer(env, transaction, 'contact')
-        let globals = await get_globals(env, transaction)
+        nodemailer = await get_nodemailer(root, 'contact')
+
+        let globals = await root.get('globals', {})
         contact_from = await globals.get_json('contact_from')
         contact_to = await globals.get_json('contact_to')
-
-        await transaction.commit()
       }
-      catch (error) {
+      finally {
         transaction.rollback()
-        throw error
       }
 
       let name =