-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-profile.js
More file actions
45 lines (40 loc) · 1.52 KB
/
get-profile.js
File metadata and controls
45 lines (40 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// import * as Sentry from '@sentry/node';
import { ProfileFetchTypes } from "@hypha-dao/ppp-common";
import { ResponseUtil } from './util';
import { ProfileDao } from "./dao";
import { AuthApiFactory, OauthAuthApi } from "./service";
import { AccessTypes } from "./const";
// Sentry.init({ dsn: process.env.sentryDsn });
const profileDao = new ProfileDao();
export async function main(event, context) {
try {
console.log('event: ', event);
console.log('context: ', context);
const body = JSON.parse(event.body) || {};
const authApi = AuthApiFactory.getInstance(event, body);
const eosAccount = await authApi.getUserName();
if(authApi instanceof OauthAuthApi){
if(!authApi.hasScope('profile_read')){
return ResponseUtil.success({
status: true,
profile:{
eosAccount,
},
});
}
}
let { fetchType } = body;
fetchType = ProfileFetchTypes.get(fetchType, ProfileFetchTypes.BASE_AND_APP);
const { appId } = await authApi.getApp();
const profile = await profileDao.findByEOSAccount(appId, eosAccount, fetchType, AccessTypes.OWNER);
console.log(" Profile Record: ", profile);
return ResponseUtil.success({
status: true,
profile,
});
} catch (e) {
console.error(e);
// Sentry.captureException(e);
return ResponseUtil.failure(e);
}
}