This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { httpError } from '../../shared/http/httpError.mjs';
|
||||
import { sendJson } from '../../shared/http/sendJson.mjs';
|
||||
import { readArticles, writeArticles } from './articleRepository.mjs';
|
||||
|
||||
export async function handleDeleteArticle(_request, response, slug) {
|
||||
const articles = await readArticles();
|
||||
const index = articles.findIndex((article) => article.slug === slug);
|
||||
|
||||
if (index === -1) {
|
||||
throw httpError(404, `Article "${slug}" was not found`);
|
||||
}
|
||||
|
||||
const [article] = articles.splice(index, 1);
|
||||
await writeArticles(articles);
|
||||
|
||||
return sendJson(response, { article });
|
||||
}
|
||||
Reference in New Issue
Block a user