-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f838c62
commit 6b48905
Showing
9 changed files
with
117 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
exports.handler = function(context, event, callback) { | ||
|
||
// take the sync_id | ||
//create map with name "experts"" | ||
//what do we return??? | ||
|
||
const sync_id = event['service']; | ||
|
||
console.log('CONTEXT:'); | ||
for(var property in context) { | ||
console.log(property + "=" + context[property]); | ||
} | ||
|
||
console.log('EVENT:'); | ||
for(var proper in event) { | ||
console.log(proper + "=" + event[proper]); | ||
} | ||
let response = "{}"; | ||
|
||
/* fetch service hosting our DB */ | ||
const client = context.getTwilioClient(); | ||
|
||
|
||
client.sync.services(sync_id) | ||
.syncMaps | ||
.create({ uniqueName: 'experts'}) | ||
.then(sync_map => { | ||
//happy path | ||
console.log(sync_map.sid); | ||
response = "{experts_id: '"+ sync_map.sid +"'}"; | ||
callback(null,response); | ||
}) | ||
.catch(e => { | ||
//manage unhapy path | ||
console.log(e); | ||
if(e=="Error: Unique name already exists") | ||
{ | ||
client.sync.services(sync_id) | ||
.syncMaps | ||
.list({limit: 20}) | ||
.then(syncMaps => { | ||
syncMaps.forEach(s => { | ||
console.log(s.sid) | ||
if(s.uniqueName == "experts") | ||
callback(null,"{experts_id: '"+ s.sid +"'}"); | ||
}); | ||
callback(null,JSON.stringify(syncMaps)); //it should not get here | ||
} | ||
|
||
) | ||
.catch(e => { | ||
//manage unhapy path | ||
console.log(e); | ||
callback(e); | ||
}); | ||
} | ||
else | ||
callback(e); | ||
}); | ||
}; |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
exports.handler = function(context, event, callback) { | ||
|
||
// take the sync_id | ||
//create map with name "experts"" | ||
//what do we return??? | ||
|
||
const sync_id = event['service']; | ||
const expert_json = event['expert']; | ||
const expert = JSON.parse(expert_json); | ||
|
||
//HAPPY PATH | ||
|
||
console.log('CONTEXT:'); | ||
for(var property in context) { | ||
console.log(property + "=" + context[property]); | ||
} | ||
|
||
console.log('EVENT:'); | ||
for(var proper in event) { | ||
console.log(proper + "=" + event[proper]); | ||
} | ||
let response = "{}"; | ||
|
||
/* fetch service hosting our DB */ | ||
const client = context.getTwilioClient(); | ||
|
||
|
||
client.sync.services(sync_id) | ||
.syncMaps('experts') | ||
.syncMapItems(expert.number) | ||
.update({data: expert_json }) | ||
.then(sync_map_item => { | ||
console.log(sync_map_item.key) | ||
callback(null,sync_map_item.key); | ||
}) | ||
.catch(e => { | ||
console.log(e); | ||
callback(null,false); | ||
}); | ||
|
||
//callback(null, response); | ||
}; |