Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const getArticleBySlugEffect$: HttpEffect = req$ =>
req$.pipe(
use(validator$),
mergeMap(req =>
of(req.params.slug).pipe(
mergeMap(ArticleDao.findByTitle),
mergeMap(neverNullable),
map(article => ({ body: article })),
catchError(() => throwError(new HttpError('Article does not exist', HttpStatus.NOT_FOUND)))
)
)
);
export const getArticleListEffect$: HttpEffect = req$ =>
req$.pipe(
use(articleQueryValidator$()),
mergeMap(req =>
of(req).pipe(
mapTo(req.query),
mergeMap(ArticleDao.findAllPublished),
map(articleList => ({ body: articleList }))
)
)
);
export const getDraftListEffect$: HttpEffect = req$ =>
req$.pipe(
use(articleQueryValidator$()),
mergeMap(req =>
of(req).pipe(
mapTo(req.query),
mergeMap(ArticleDao.findAll),
map(articleList => ({ body: articleList }))
)
)
);
export const postCommentByArticleEffect$: HttpEffect = req$ =>
req$.pipe(
use(requestValidator$({ body: commentSchema })),
map(req => req.body),
mergeMap(CommentDao.create),
map(article => ({ body: article }))
);
const rpc$: MsgEffect = event$ =>
event$.pipe(
matchEvent('RPC_TEST'),
delay(250),
use(eventValidator$(t.number)),
map(event => event.payload),
map(payload => ({ type: 'RPC_TEST_RESULT', payload: payload + 1 })),
);
export const postArticleEffect$: HttpEffect = req$ =>
req$.pipe(
use(validator$),
mergeMap(req =>
of(req).pipe(
mapTo(req.body),
mergeMap(ArticleDao.create),
map(article => ({ body: article })),
catchError(err => throwError(err))
)
)
);
export const getFileEffect$: HttpEffect = req$ =>
req$.pipe(
use(validator$),
mergeMap(req => of(req.params.dir).pipe(
mergeMap(FileHelper.readFile(STATIC_PATH)),
map(body => ({ body })),
catchError(error => iif(
() => error.code === 'ENOENT',
throwError(new HttpError(`Asset not found for path: ${req.url}`, HttpStatus.NOT_FOUND)),
throwError(new HttpError('Internal server error', HttpStatus.INTERNAL_SERVER_ERROR)),
)),
)),
);
export const updateArticleEffect$: HttpEffect = req$ =>
req$.pipe(
use(validator$),
mergeMap(req =>
of(req.params.id).pipe(
mapTo(req.body),
mergeMap(article => ArticleDao.updateById(req.params.id, article)),
mergeMap(neverNullable),
map(article => ({ body: article })),
catchError(err =>
throwError(new HttpError(err, HttpStatus.INTERNAL_SERVER_ERROR)),
),
),
),
);
export const removeArticleEffect$: HttpEffect = req$ =>
req$.pipe(
use(validator$),
mergeMap(req =>
of(req.params.id).pipe(
mergeMap(ArticleDao.removeById),
map(() => ({ body: null })),
catchError(err => throwError(new HttpError(err, HttpStatus.INTERNAL_SERVER_ERROR)))
)
)
);
export const getMovieListEffect$: HttpEffect = req$ =>
req$.pipe(
use(collectionQueryValidator$({ sortBy: SORTING_FIELDS })),
mergeMap(req => of(req).pipe(
map(req => req.query),
mergeMap(MoviesDao.findAll),
map(applyHostnameForCollection(req)),
map(movies => ({ body: movies })),
))
);