0bde260251bfeed23809faec3ce9d9a154f39d61
[ndcode_site.git] / api / account / change_details / get.json.jst
1 let logjson = (await import('@ndcode/logjson')).default
2 let XDate = require('xdate')
3
4 return async env => {
5   let post_request = await _require('/_lib/post_request.jst')
6   let session_cookie = await _require('/_lib/session_cookie.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         // initialize env.session_key, set cookie in env.response
17         let session = await session_cookie(env, transaction)
18
19         let account = await (
20           await (
21             await transaction.get({})
22           ).get('accounts', {})
23         ).get(env.signed_in_as)
24         let details = {
25           given_names: await logjson.logjson_to_json(
26             await account.get('given_names')
27           ),
28           family_name: await logjson.logjson_to_json(
29             await account.get('family_name')
30           ),
31           contact_me: await logjson.logjson_to_json(
32             await account.get('contact_me')
33           )
34         }
35
36         await transaction.commit()
37         return details
38       }
39       catch (error) {
40         transaction.rollback()
41         throw error
42       }
43     }
44   )
45 }