refactor: update article deletion and retrieval methods to use external ID

This commit is contained in:
2026-04-17 00:12:44 -03:00
parent 873e372bad
commit b9e34e590d
11 changed files with 134 additions and 115 deletions

View File

@@ -155,16 +155,19 @@ export const updateArticle: (
);
/** Deletes an article from the database. */
export const deleteArticle: (articleId: string) => Promise<TypedResult<void>> =
wrap(async (articleId: string): Promise<void> => {
export const deleteArticleByExternalId: (
externalId: UUIDv4
) => Promise<TypedResult<void>> = wrap(
async (externalId: UUIDv4): Promise<void> => {
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 ExternalID ${externalId} not found`);
}
await articleRepository.remove(existingArticle);
});
}
);