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

This commit is contained in:
2026-04-17 01:43:31 -03:00
parent 93d66315a1
commit e2960027f2
8 changed files with 71 additions and 68 deletions

View File

@@ -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;