mirror of
https://github.com/sergeyyarkov/digital-store.git
synced 2026-10-11 18:29:11 +03:00
fix json post request
This commit is contained in:
parent
2799b3e7fe
commit
cea0057f06
2
dist/public/js/admin.js
vendored
2
dist/public/js/admin.js
vendored
File diff suppressed because one or more lines are too long
@ -177,8 +177,7 @@ module.exports = function (server, db) {
|
||||
});
|
||||
server.post('/control-panel/categories/delete', checkAuthenticated, (req, res) => {
|
||||
try {
|
||||
const data = JSON.parse(req.body.category);
|
||||
db.collection('categories').deleteOne({"_id": ObjectID(data.id)});
|
||||
db.collection('categories').deleteOne({"_id": ObjectID(req.body.category)});
|
||||
res.redirect('/control-panel/categories');
|
||||
} catch {
|
||||
res.status(500).render('main/404');
|
||||
@ -221,15 +220,16 @@ module.exports = function (server, db) {
|
||||
});
|
||||
|
||||
// товары
|
||||
server.post('/control-panel/items/create', checkAuthenticated, (req, res) => {
|
||||
server.post('/control-panel/items/create', checkAuthenticated, async (req, res) => {
|
||||
try {
|
||||
const category = await db.collection('categories').findOne({_id: ObjectID(req.body.category)})
|
||||
// документ с информацией товара для отдачи клиенту
|
||||
const item = {
|
||||
_id: new ObjectID(),
|
||||
title: req.body.title,
|
||||
count: req.body.data.split(',').length,
|
||||
price: parseFloat(req.body.price),
|
||||
category: JSON.parse(req.body.category).title,
|
||||
category: category.title,
|
||||
description: req.body.description,
|
||||
date: new Date()
|
||||
}
|
||||
@ -257,17 +257,18 @@ module.exports = function (server, db) {
|
||||
res.render('main/404');
|
||||
}
|
||||
});
|
||||
server.post('/control-panel/items/update', checkAuthenticated, (req, res) => {
|
||||
server.post('/control-panel/items/update', checkAuthenticated, async (req, res) => {
|
||||
try {
|
||||
const category = await db.collection('categories').findOne({_id: ObjectID(req.body.category)})
|
||||
const data = {
|
||||
id: req.body.id,
|
||||
title: req.body.title,
|
||||
price: parseFloat(req.body.price),
|
||||
description: req.body.description,
|
||||
category: JSON.parse(req.body.category),
|
||||
category,
|
||||
info: req.body.data.split(',')
|
||||
}
|
||||
db.collection('items').updateOne({"_id": ObjectID(data.id)}, {$set: {title: data.title, price: data.price, description: data.description, category: data.category.title}});
|
||||
db.collection('items').updateOne({"_id": ObjectID(data.id)}, {$set: {title: data.title, price: data.price, description: data.description, category: category.title}});
|
||||
db.collection('info').updateOne({"_id": ObjectID(data.id)}, {$set: {title: data.title, data: data.info}});
|
||||
res.redirect('/control-panel/items');
|
||||
} catch {
|
||||
|
||||
@ -31,10 +31,11 @@ export class ItemEditModal extends Modal {
|
||||
const id = e.target.parentNode.parentNode.dataset.id,
|
||||
item = await apiService.getItemById(id),
|
||||
data = await apiService.getDataById(id),
|
||||
categories = await apiService.getCategories();
|
||||
categories = await apiService.getCategories(),
|
||||
category = await apiService.getCategory(item.category);
|
||||
item.data = data.data
|
||||
|
||||
this.$category.innerHTML = `<option value='{"title": "${item.category}"}' selected>Оставить прежнюю</option>`;
|
||||
this.$category.innerHTML = `<option value='${category[0]._id}' selected>Оставить прежнюю</option>`;
|
||||
this.$id.value = item._id;
|
||||
this.$title.value = item.title;
|
||||
this.$price.value = item.price;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user