|
|
@ -92,12 +92,12 @@ class VenueService extends SiteService {
|
|
|
|
widgetKey: channelDefinition['credentials.widgetKey'].trim(),
|
|
|
|
widgetKey: channelDefinition['credentials.widgetKey'].trim(),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const status = await this.updateChannelStatus(channel);
|
|
|
|
|
|
|
|
channel.name = status.name;
|
|
|
|
channel.name = status.name;
|
|
|
|
channel.description = status.description;
|
|
|
|
channel.description = status.description;
|
|
|
|
|
|
|
|
|
|
|
|
await channel.save();
|
|
|
|
await channel.save();
|
|
|
|
await this.updateChannelStatus(channel);
|
|
|
|
|
|
|
|
|
|
|
|
channel.currentStatus = await this.updateChannelStatus(channel);
|
|
|
|
|
|
|
|
|
|
|
|
return channel.toObject();
|
|
|
|
return channel.toObject();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -111,7 +111,6 @@ class VenueService extends SiteService {
|
|
|
|
updateOp.$set.slug = this.getChannelSlug(channelDefinition.url);
|
|
|
|
updateOp.$set.slug = this.getChannelSlug(channelDefinition.url);
|
|
|
|
updateOp.$set.sortOrder = parseInt(channelDefinition.sortOrder || '0', 10);
|
|
|
|
updateOp.$set.sortOrder = parseInt(channelDefinition.sortOrder || '0', 10);
|
|
|
|
|
|
|
|
|
|
|
|
const status = await this.updateChannelStatus(channel);
|
|
|
|
|
|
|
|
updateOp.$set.name = status.name;
|
|
|
|
updateOp.$set.name = status.name;
|
|
|
|
updateOp.$set.description = status.description;
|
|
|
|
updateOp.$set.description = status.description;
|
|
|
|
|
|
|
|
|
|
|
@ -126,7 +125,9 @@ class VenueService extends SiteService {
|
|
|
|
updateOp.$set['credentials.widgetKey'] = channelDefinition['credentials.widgetKey'].trim();
|
|
|
|
updateOp.$set['credentials.widgetKey'] = channelDefinition['credentials.widgetKey'].trim();
|
|
|
|
|
|
|
|
|
|
|
|
channel = await VenueChannel.findOneAndUpdate({ _id: channel._id }, updateOp, { new: true });
|
|
|
|
channel = await VenueChannel.findOneAndUpdate({ _id: channel._id }, updateOp, { new: true });
|
|
|
|
await this.updateChannelStatus(channel);
|
|
|
|
channel.currentStatus = await this.updateChannelStatus(channel);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getChannels (pagination, options) {
|
|
|
|
async getChannels (pagination, options) {
|
|
|
@ -146,7 +147,7 @@ class VenueService extends SiteService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const channels = await q.populate(this.populateVenueChannel).lean();
|
|
|
|
const channels = await q.populate(this.populateVenueChannel).lean();
|
|
|
|
for await (const channel of channels) {
|
|
|
|
for (const channel of channels) {
|
|
|
|
channel.currentStatus = await this.updateChannelStatus(channel);
|
|
|
|
channel.currentStatus = await this.updateChannelStatus(channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return channels;
|
|
|
|
return channels;
|
|
|
@ -202,20 +203,31 @@ class VenueService extends SiteService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async updateChannelStatus (channel) {
|
|
|
|
async updateChannelStatus (channel) {
|
|
|
|
const requestUrl = `https://${this.soapboxDomain}/channel/${channel.slug}/status`;
|
|
|
|
const { logan: loganService } = this.dtp.services;
|
|
|
|
this.log.info('fetching Shing channel status', { slug: channel.slug, requestUrl });
|
|
|
|
try {
|
|
|
|
|
|
|
|
const requestUrl = `https://${this.soapboxDomain}/channel/${channel.slug}/status`;
|
|
|
|
|
|
|
|
this.log.info('fetching Shing channel status', { slug: channel.slug, requestUrl });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const response = await fetch(requestUrl, { agent: this.httpsAgent });
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
|
|
|
throw new SiteError(500, `Failed to fetch channel status: ${response.statusText}`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const response = await fetch(requestUrl, { agent: this.httpsAgent });
|
|
|
|
const json = await response.json();
|
|
|
|
if (!response.ok) {
|
|
|
|
if (!json.success) {
|
|
|
|
throw new SiteError(500, `Failed to fetch channel status: ${response.statusText}`);
|
|
|
|
throw new Error(`failed to fetch channel status: ${json.message}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const json = await response.json();
|
|
|
|
return json.channel;
|
|
|
|
if (!json.success) {
|
|
|
|
} catch (error) {
|
|
|
|
throw new Error(`failed to fetch channel status: ${json.message}`);
|
|
|
|
loganService.sendEvent(module.exports, {
|
|
|
|
|
|
|
|
level: 'error',
|
|
|
|
|
|
|
|
event: 'updateChannelStatus',
|
|
|
|
|
|
|
|
message: error.message,
|
|
|
|
|
|
|
|
data: { error },
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return; // undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return json.channel;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getChannelSlug (channelUrl) {
|
|
|
|
getChannelSlug (channelUrl) {
|
|
|
|