Last active
December 10, 2022 13:18
-
-
Save mrgulshanyadav/23a15c9223229dae356400980d12bb2d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const options = { | |
url: 'https://api.churchpool.com/v3/parish/'+bundle.inputData.parish_id+'/post?sort=createdDate,ASC', | |
// url: 'https://churchpool-api.dhimahi.com/v3/parish/'+bundle.inputData.parish_id+'/post?sort=createdDate,ASC', // New Posts - Test | |
method: 'GET', | |
headers: { | |
'Accept': 'application/json', | |
} | |
} | |
return z.request(options) | |
.then((response) => { | |
response.throwForStatus(); | |
const results = response.json; | |
// You can do any parsing you need for results here before returning them | |
if(results.data.length>0){ | |
var postsData = results.data; | |
var modifiedPostsData = postsData; | |
for(var i=0; i<postsData.length; i++){ | |
var postObject = postsData[i]; | |
var mediaAssets = postObject.mediaAssets; | |
var mediaList = postObject.mediaList; | |
var mediaURLs = ""; | |
if(mediaAssets.length>0){ | |
for(var j=0; j<mediaAssets.length; j++){ | |
var mediaAssetObject = mediaAssets[j]; | |
if(j!=mediaAssets.length-1){ | |
mediaURLs = mediaURLs + mediaAssetObject.mediaUrl + ","; | |
}else{ | |
mediaURLs = mediaURLs + mediaAssetObject.mediaUrl; | |
} | |
} | |
}else if(mediaList.length>0){ | |
for(var k=0; k<mediaList.length; k++){ | |
var mediaListObject = mediaList[k]; | |
if(k!=mediaList.length-1){ | |
mediaURLs = mediaURLs + mediaListObject.contentUrl + ","; | |
}else{ | |
mediaURLs = mediaURLs + mediaListObject.contentUrl; | |
} | |
mediaAssets.push({ | |
mediaUrl: mediaListObject.contentUrl, | |
mimeType: '', | |
size: 0, | |
}); | |
} | |
} | |
if(!("mediaURLs" in modifiedPostsData[i])){ | |
modifiedPostsData[i].mediaURLs = mediaURLs; | |
modifiedPostsData[i].mediaAssets = mediaAssets; | |
} | |
// send only 1st mediaAsset object from list | |
modifiedPostsData[i].mediaAssets = [mediaAssets[0]]; | |
} | |
return modifiedPostsData; | |
}else{ | |
return [{ | |
"id": 77, | |
"text": "Welcome Post", | |
"previewUrl": null, | |
"createdDate": Date.toISOString(), | |
"updatedDate": Date.toISOString(), | |
"parishId": bundle.inputData.parish_id, | |
"groupId": null, | |
"userId": 11, | |
"parish": { | |
"avatar": { | |
"contentUrl": "https://churchpool-test-bucket.obs.eu-de.otc.t-systems.com/1158f5033d650102be5d543f84f7f6.png", | |
"id": 1280, | |
"createdDate": Date.toISOString(), | |
}, | |
"id": bundle.inputData.parish_id, | |
"name": "Evangelische lutherische Kirchengemeinde v. Nils" | |
}, | |
"mediaAssets": [ | |
{ | |
"mediaUrl": "https://images.pexels.com/photos/5840867/pexels-photo-5840867.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1", | |
"mimeType": "image/jpeg", | |
"size": 2395, | |
} | |
], | |
"mediaURLs": "", | |
"mediaList": [ | |
{ | |
"contentUrl": "https://images.pexels.com/photos/5840867/pexels-photo-5840867.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1", | |
"id": 111, | |
"createdDate": Date.toISOString(), | |
} | |
], | |
"user": { | |
"role": "parish_admin", | |
"id": 11, | |
"name": "Nils", | |
"surname": "Bischoff", | |
"username": "nils2.bischoff", | |
"isAnonymised": false, | |
"parishId": 71, | |
"avatarBackgroundColor": "#4F9641", | |
"description": "I can do all things through Christ who strengthens me. \n\nBe strong and take heart, all you who hope in the lord.", | |
"emojis": [ | |
"🥳", | |
"😎", | |
"⛪", | |
"🙏", | |
"✌️" | |
], | |
"userId": "a310a3d1-b3ac-4fd9-889a-a7653f28146f" | |
}, | |
"usersReaction": null, | |
"commentsCount": 0, | |
"reactionsCount": { | |
"like": 0, | |
"heart": 0, | |
"joy": 0, | |
"innocent": 0, | |
"flushed": 0, | |
"cry": 0 | |
} | |
}, | |
]; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment