refactor: update article deletion and retrieval methods to use external ID
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user