From 08d78a745cc5d8431d12235fc9024a579f8283b6 Mon Sep 17 00:00:00 2001 From: Alice Marshall Date: Wed, 6 May 2020 13:28:35 +0100 Subject: [PATCH] adding share parent endpoint --- lib/share.js | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/share.js b/lib/share.js index b98836e..3c4d30a 100644 --- a/lib/share.js +++ b/lib/share.js @@ -43,6 +43,9 @@ const ENDPOINTS = { getById(id) { return `/shares/${id}`; }, + getByParentId(id) { + return `/shares/${id}/parent`; + }, recordView(id, uid) { return { path: `/shares/${id}/views`, @@ -104,7 +107,7 @@ const ENDPOINTS = { return { path: `/shares/${id}/featured`, method: 'PATCH', - body: JSON.stringify({ featured: featured }), + body: JSON.stringify({ featured }), responseType: 'text', }; }, @@ -127,7 +130,7 @@ const ENDPOINTS = { path: `/shares/${sid}/moderate`, method: 'POST', }; - } + }, }; function generateAttachmentPath(attachments, key, id) { @@ -150,48 +153,56 @@ export class ShareClient extends Client { super(opts); this.addEndpoints(ENDPOINTS); } + feed(limit) { const endpoint = this.getEndpoint('feed', limit); return this.fetch(endpoint) .then(res => res.data) .then(data => this.afterDataProcessed(endpoint, data)); } + userFeed(id, limit) { const endpoint = this.getEndpoint('userFeed', id, limit); return this.fetch(endpoint) .then(res => res.data) .then(data => this.afterDataProcessed(endpoint, data)); } + feedByApp(app, limit) { const endpoint = this.getEndpoint('feedByApp', app, limit); return this.fetch(endpoint) .then(res => res.data) .then(data => this.afterDataProcessed(endpoint, data)); } + feedByHardware(hardware, limit) { const endpoint = this.getEndpoint('feedByHardware', hardware, limit); return this.fetch(endpoint) .then(res => res.data) .then(data => this.afterDataProcessed(endpoint, data)); } + feedByHardwareFeatured(hardware, featured, limit) { const endpoint = this.getEndpoint('feedByHardwareFeatured', hardware, featured, limit); return this.fetch(endpoint) .then(res => res.data) .then(data => this.afterDataProcessed(endpoint, data)); } + feedByFollow(uid, limit) { const endpoint = this.getEndpoint('feedByFollow', uid, limit); return this.fetch(endpoint) .then(res => res.data) .then(data => this.afterDataProcessed(endpoint, data)); } + featured(limit) { const endpoint = this.getEndpoint('featured', limit); return this.fetch(endpoint) .then(res => res.data) .then(data => this.afterDataProcessed(endpoint, data)); } + getListByIds(ids) { const endpoint = this.getEndpoint('getShareListByIds', ids); return this.fetch(endpoint) @@ -202,39 +213,53 @@ export class ShareClient extends Client { ))) .then(data => this.afterDataProcessed(endpoint, data)); } + getById(id) { const endpoint = this.getEndpoint('getById', id); return this.fetch(endpoint) .then(res => expandShare(res.data.share, res.data.atBurl, res.data.aBurl)) .then(data => this.afterDataProcessed(endpoint, data)); } + + getByParentId(id) { + const endpoint = this.getEndpoint('getByParentId', id); + return this.fetch(endpoint) + .then(res => expandShare(res.data.share, res.data.atBurl, res.data.aBurl)) + .then(data => this.afterDataProcessed(endpoint, data)); + } + getBySlug(slug) { const endpoint = this.getEndpoint('getBySlug', slug); return this.fetch(endpoint) .then(res => expandShare(res.data.share, res.data.atBurl, res.data.aBurl)) .then(data => this.afterDataProcessed(endpoint, data)); } + recordView(id, uid) { const endpoint = this.getEndpoint('recordView', id, uid); return this.fetch(endpoint) .then(data => this.afterDataProcessed(endpoint, data)); } + recordLike(id) { const endpoint = this.getEndpoint('recordLike', id); return this.fetch(endpoint) .then(data => this.afterDataProcessed(endpoint, data)); } + deleteLike(id) { const endpoint = this.getEndpoint('deleteLike', id); return this.fetch(endpoint) .then(data => this.afterDataProcessed(endpoint, data)); } + getComments(id) { const endpoint = this.getEndpoint('getComments', id); return this.fetch(endpoint) .then(res => res.data) .then(data => this.afterDataProcessed(endpoint, data || [])); } + create(data) { const endpoint = this.getEndpoint('create', data); return this.fetch(endpoint) @@ -258,33 +283,36 @@ export class ShareClient extends Client { // All attachments are uploaded, trigger the moderation const moderate = this.getEndpoint('moderate', d.share.id); return this.fetch(moderate) - .then((moderationData) => { - // Add the moderation data to the response object - return Object.assign(d, { moderation: moderationData.data }); - }); + // Add the moderation data to the response object + .then(moderationData => Object.assign(d, { moderation: moderationData.data })); }) .then(d => this.afterDataProcessed(endpoint, d || [])); } + deleteShare(id) { const endpoint = this.getEndpoint('deleteShare', id); return this.fetch(endpoint) .then(data => this.afterDataProcessed(endpoint, data)); } + deleteShareByAdmin(id) { const endpoint = this.getEndpoint('deleteShareByAdmin', id); return this.fetch(endpoint) .then(data => this.afterDataProcessed(endpoint, data)); } + featureShareByAdmin(id, featured) { const endpoint = this.getEndpoint('featureShareByAdmin', id, featured); return this.fetch(endpoint) .then(data => this.afterDataProcessed(endpoint, data)); } + flagShare(id) { const endpoint = this.getEndpoint('flagShare', id); return this.fetch(endpoint) .then(data => this.afterDataProcessed(endpoint, data)); } + unflagShare(id) { const endpoint = this.getEndpoint('unflagShare', id); return this.fetch(endpoint)