Skip to content

Commit

Permalink
task(fibery): fetch keywords & publication date [#56]
Browse files Browse the repository at this point in the history
  • Loading branch information
Drapegnik committed Sep 10, 2019
1 parent ae33d7a commit 1100463
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/api/article/article.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ const joiArticleSchema = Joi.object({
platform: Joi.string().valid(['youtube']),
id: Joi.string().regex(/^[a-zA-Z0-9_-]{11}$/),
url: Joi.string().uri(),
}),
}).allow(null),
audio: Joi.object({
platform: Joi.string().valid(['soundcloud']),
id: Joi.string(),
url: Joi.string().uri(),
}),
}).allow(null),
color: Joi.color().default(DEFAULT_COLOR),
// Text on article card may be rendered in one of the following ways.
// This depends on the color and is set manually.
Expand All @@ -64,7 +64,9 @@ const joiArticleSchema = Joi.object({
tags: Joi.array().items(Joi.objectId().meta({ ref: 'Tag' })),
// Keywords are for SEO optimization and search engines.
keywords: Joi.string(),
}).nand('video', 'audio');
});
// FIXME: falls with { audio: null, video: null }
// .nand('video', 'audio');

// FIXME: sync with design
const IMAGES_BY_TYPE = {
Expand Down
15 changes: 13 additions & 2 deletions src/api/article/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,16 @@ const getType = ({ video, audio }) => {
};

// `fibery` -> `wir` mapper
export const mapFiberyArticle = async ({ cover, collection, locales, video, audio, ...rest }) => ({
export const mapFiberyArticle = async ({
cover,
collection,
locales,
video,
audio,
publishAt,
keywords,
...rest
}) => ({
...omit(rest, TOPIC_SLUGS),
...mapCover(cover || {}),
collection: mapCollection(collection),
Expand All @@ -132,10 +141,12 @@ export const mapFiberyArticle = async ({ cover, collection, locales, video, audi
articleId: rest.fiberyId,
active: true,
type: getType({ video, audio }),
publishAt: new Date(publishAt),
keywords: keywords || ' ',
});

export const getArticle = async data => {
const { fiberyId } = data;
const article = await Article.findOne({ fiberyId });
const article = await Article.findOneAndUpdate({ fiberyId }, data);
return article || Article(data);
};
17 changes: 13 additions & 4 deletions src/services/fibery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ import { ValidationError } from 'utils/validation';
import { map } from 'utils/func';

import { /* STATE_READY, */ DOC_SECRET_NAME, DOC_FORMAT } from './constants';
import { FIBERY_DEFAULT, ARTICLE_FIELDS, STATE, TAGS, RELATED_ENTITIES, CONTENT } from './query';
import { getArticlePublicId, addAppName, mapAppNameLocales } from './utils';
import {
FIBERY_DEFAULT,
ARTICLE_FIELDS,
ARTICLE_LOC_FIELDS,
STATE,
TAGS,
RELATED_ENTITIES,
CONTENT,
} from './query';
import { getArticlePublicId, addAppName, mapAppName, mapAppNameLocales } from './utils';
// import { getState } from './getters';
import { toWirFormat, formatEnum, IMAGE_FORMATER, TAG_FORMATER } from './formatters';

Expand All @@ -26,7 +34,8 @@ const getArticleData = async url => {
{
'q/from': addAppName('Article'),
'q/select': FIBERY_DEFAULT.concat(
mapAppNameLocales(ARTICLE_FIELDS),
mapAppName(ARTICLE_FIELDS),
mapAppNameLocales(ARTICLE_LOC_FIELDS),
STATE,
TAGS,
RELATED_ENTITIES,
Expand Down Expand Up @@ -61,7 +70,7 @@ const getArticleData = async url => {
});

const formatArticle = toWirFormat({
mapping: { Podcast: 'audio' },
mapping: { Podcast: 'audio', publication: 'publishAt' },
mapper: (key, lang = '') => (lang ? `locales.${lang}.${key}` : key),
formatters: {
authors: TAG_FORMATER,
Expand Down
4 changes: 3 additions & 1 deletion src/services/fibery/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { DOC_SECRET_NAME } from './constants';

export const FIBERY_DEFAULT = ['fibery/id', 'fibery/public-id'];

export const ARTICLE_FIELDS = ['Title', 'Subtitle', 'Slug'];
export const ARTICLE_FIELDS = ['Keywords', 'publication-date'];

export const ARTICLE_LOC_FIELDS = ['Title', 'Subtitle', 'Slug'];

export const ENUM = ['enum/name'];

Expand Down

0 comments on commit 1100463

Please sign in to comment.