-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile-handle-app-updates.js
More file actions
30 lines (23 loc) · 1.03 KB
/
profile-handle-app-updates.js
File metadata and controls
30 lines (23 loc) · 1.03 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
import { ProfileDao } from "./dao";
import { Profile } from './domain';
const profileDao = new ProfileDao();
export async function main(event, context, callback) {
console.log('event: ', JSON.stringify(event, null, 2));
console.log('context: ', JSON.stringify(context, null, 2));
for (const record of event.Records) {
if (record.eventName == 'MODIFY') {
const {
OldImage: oldApp,
NewImage: newApp,
} = record.dynamodb;
console.log('Old app: ', JSON.stringify(oldApp, null, 2));
console.log('New app: ', JSON.stringify(newApp, null, 2));
if (Profile.requiresUpdate('app', oldApp, newApp, true)) {
console.log('Requires update, updating Profiles...')
const appDetails = Profile.getEntityDetails('app', newApp, true);
await profileDao.updateAppDetails(newApp.appId.S, appDetails);
}
}
}
callback(null, `Successfully processed ${event.Records.length} records.`);
}