Major refactoring of get_session(), get_account(), get_nodemailer(), introduces ...
[ndcode_site.git] / api / account / change_details / get.json.jst
1 let XDate = require('xdate')
2
3 return async env => {
4   let get_account = await _require('/_lib/get_account.jst')
5   let get_session = await _require('/_lib/get_session.jst')
6   let post_request = await _require('/_lib/post_request.jst')
7   let Problem = await _require('/_lib/Problem.jst')
8
9   await post_request(
10     // env
11     env,
12     // handler
13     async () => {
14       let transaction = await env.site.database.Transaction()
15       try {
16         let root = await transaction.get({})
17         let session = await get_session(env, root)
18
19         let account = await get_account(root, session)
20         if (account === undefined)
21           throw new Problem('Unauthorized', 'Please sign in first.', 401)
22
23         return {
24           given_names: await account.get_json('given_names'),
25           family_name: await account.get_json('family_name'),
26           contact_me: await account.get_json('contact_me')
27         }
28       }
29       finally {
30         transaction.rollback()
31       }
32     }
33   )
34 }