-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch-profiles.js
51 lines (45 loc) · 1.49 KB
/
search-profiles.js
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
46
47
48
49
50
51
// import * as Sentry from '@sentry/node';
import { AppIds, ProfileFetchTypes } from '@hypha-dao/ppp-common';
import { AuthApiFactory } from "./service";
import { ResponseUtil } from './util';
import { ProfileDao } from "./dao";
// Sentry.init({ dsn: process.env.sentryDsn });
const profileDao = new ProfileDao();
export async function main(event, context) {
try {
const body = JSON.parse(event.body);
let {
appId,
fetchType,
limit,
lastEvaluatedKey,
search,
} = body;
appId = appId || AppIds.BASE_PROFILE_APP;
fetchType = appId === AppIds.BASE_PROFILE_APP ? ProfileFetchTypes.BASE_ONLY : ProfileFetchTypes.get(fetchType, ProfileFetchTypes.BASE_AND_APP);
if (appId === AppIds.CURRENT_APP) {
const authApi = AuthApiFactory.getInstance(event, body);
const app = await authApi.getApp(false);
if (app) {
appId = app.appId;
} else {
throw "Can't search current app profiles, when app is not registered";
}
}
let profiles = await profileDao.search({
appId,
fetchType,
search,
limit,
lastEvaluatedKey
});
return ResponseUtil.success({
status: true,
profiles,
});
} catch (e) {
console.error(e);
// Sentry.captureException(e);
return ResponseUtil.failure(e);
}
}