Skip to content

Commit

Permalink
Server: delete component
Browse files Browse the repository at this point in the history
  • Loading branch information
ifdjhxh committed Dec 8, 2024
1 parent df64eb8 commit 88470f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
21 changes: 21 additions & 0 deletions main/controllers/ComponentsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "Не удалось удалить компонент"
});
}
}
5 changes: 3 additions & 2 deletions main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 88470f7

Please sign in to comment.