refactor: update article service methods to use external ID and improve caching
All checks were successful
Build and Test / run-test (20.x) (push) Successful in 2m5s
All checks were successful
Build and Test / run-test (20.x) (push) Successful in 2m5s
This commit is contained in:
@@ -13,7 +13,6 @@ export const articleEntityToModel = (
|
||||
articleEntity: ArticleEntity
|
||||
): ArticleModel => {
|
||||
return {
|
||||
id: articleEntity.id,
|
||||
title: articleEntity.title,
|
||||
slug: articleEntity.slug,
|
||||
description: articleEntity.description,
|
||||
@@ -123,21 +122,21 @@ export const saveArticle: (
|
||||
);
|
||||
|
||||
/** Updates an existing article in the database. */
|
||||
export const updateArticle: (
|
||||
articleId: string,
|
||||
export const updateArticleByExternalId: (
|
||||
externalId: string,
|
||||
article: UpdateArticleModel
|
||||
) => Promise<TypedResult<ArticleModel>> = wrap(
|
||||
async (
|
||||
articleId: string,
|
||||
externalId: string,
|
||||
article: UpdateArticleModel
|
||||
): Promise<ArticleModel> => {
|
||||
const articleRepository = await getRepository(ArticleEntity);
|
||||
|
||||
const existingArticle = await articleRepository.findOneBy({
|
||||
id: articleId,
|
||||
externalId: externalId,
|
||||
});
|
||||
if (!existingArticle) {
|
||||
throw new Error(`Article with ID ${articleId} not found`);
|
||||
throw new Error(`Article with ID ${externalId} not found`);
|
||||
}
|
||||
|
||||
if (!!article.title) existingArticle.title = article.title;
|
||||
|
||||
Reference in New Issue
Block a user