diff --git a/main/controllers/ComponentsController.js b/main/controllers/ComponentsController.js index 87ca49c..420ab51 100644 --- a/main/controllers/ComponentsController.js +++ b/main/controllers/ComponentsController.js @@ -119,4 +119,25 @@ export const update = async (req, res) => { message: "Не удалось обновить компонент" }) } +} + +export const deleteElem = async (req, res) => { + try { + const componentId = String(req.params.id); + await ComponentsModel.deleteOne({_id: componentId}) + .then(() => { + res.json({success: true}); + }) + .catch((e) => { + console.warn(e); + res.json({ + message: "Не удалось удалить компонент" + }); + }); + }catch (e) { + console.warn(e); + res.json({ + message: "Не удалось удалить компонент" + }); + } } \ No newline at end of file diff --git a/main/index.js b/main/index.js index d3d51de..12ffa45 100644 --- a/main/index.js +++ b/main/index.js @@ -3,11 +3,11 @@ import mongoose from "mongoose"; import cors from "cors"; import {login} from "./controllers/AdminController.js"; import checkAuth from "./utils/checkAuth.js"; -import {addComponent, getAll, getOne, update} from "./controllers/ComponentsController.js"; +import {addComponent, deleteElem, getAll, getOne, update} from "./controllers/ComponentsController.js"; import path from 'path'; const app = express(); -const isProduction = false; +const isProduction = true; const folder = isProduction? "dist": "_public"; const PORT = 4444; @@ -52,6 +52,7 @@ app.post('/components', checkAuth, addComponent); app.get('/components', getAll); app.get('/components/:id', getOne); app.patch('/components/:id', checkAuth, update); +app.delete('/components/:id', checkAuth, deleteElem); app.get('/auth/authorized', checkAuth, (req, res) => { res.json({ message: true