-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete-app.js
33 lines (30 loc) · 1.03 KB
/
delete-app.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
import { ResponseUtil } from './util';
import { AppDao } from "./dao";
import { AuthApiFactory } from "./service";
const appDao = new AppDao();
export async function main(event, context) {
try {
console.log('event: ', event);
console.log('context: ', context);
const body = JSON.parse(event.body);
const { appId } = body;
if (!appId) {
throw 'appId is a required parameter';
}
const authApi = AuthApiFactory.getInstance(event, body);
await authApi.getApp();
const eosAccount = await authApi.getUserName();
const { ownerAccount, domain } = await appDao.getById(appId);
if (eosAccount != ownerAccount) {
throw `User is not owner of the app: ${appId}`;
}
await appDao.delete(appId, domain);
return ResponseUtil.success({
status: true,
message: `App: ${appId} was deleted succesfully`,
});
} catch (e) {
console.error(e);
return ResponseUtil.failure(e);
}
}