module.exports.updateCard = asyncHandler(async (req, res, next) => {
// Решение
req.body.htmlText = req.body.htmlText.replace(/</g, "<");
const card = await Card.findOneAndUpdate(
{
card: req.params.card
},
req.body,
{ new: true, runValidators: true }
);
if (!card) {
return next(
new ErrorResponse(`Not found with slug of ${req.params.card}`, 404)
);
}
res.status(200).json({ message: "Карточка успешно обновлена", data: card });
});
module.exports.updateCard = asyncHandler(async (req, res, next) => {
// console.log(req.body.htmlText.replace(/</g, "<"));
const card = await Card.findOneAndUpdate(
{
card: req.params.card
},
req.body,
{ new: true, runValidators: true }
);
if (!card) {
return next(
new ErrorResponse(`Not found with slug of ${req.params.card}`, 404)
);
}
res.status(200).json({ message: "Карточка успешно обновлена", data: card });
});
export default {
data() {
return {
htmlText: { html: "" },
};
},
methods: {
async onSubmit() {
try {
const formData = {
htmlText: this.htmlText,
};
console.log(this.htmlText);
const res = await this.$axios.$put(
`api/card/admin/${this.$route.params.card}`,
formData
);
alert(res.message);
} catch (err) {
alert(res.message, err);
}
},
}
};