Files
progcode/local-admin/src/entities/article/handleDeleteArticle.mjs
T
huncode 3a3b2bcfc0
Build and deploy / deploy (push) Successful in 16s
add simple admin service
2026-05-18 02:48:47 +03:00

18 lines
589 B
JavaScript

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 });
}