👌 IMPROVE: backend modifier isOnline

This commit is contained in:
Divlo 2020-04-15 21:32:25 +02:00
parent 9336bf12fd
commit 5eb64d200b

View File

@ -9,12 +9,13 @@ const helperQueryNumber = require('../assets/utils/helperQueryNumber');
const Sequelize = require('sequelize');
const deleteFilesNameStartWith = require('../assets/utils/deleteFilesNameStartWith');
const handleEditFunction = async (res, resultFunction, { title, slug, description, type, categorieId }, imageName = false) => {
const handleEditFunction = async (res, resultFunction, { title, slug, description, type, categorieId, isOnline }, imageName = false) => {
resultFunction.title = title;
resultFunction.slug = slug;
resultFunction.description = description;
resultFunction.type = type;
resultFunction.categorieId = categorieId;
resultFunction.isOnline = isOnline;
if (imageName) {
resultFunction.image = `/images/functions/${imageName}`;
}
@ -114,7 +115,7 @@ exports.postFunction = (req, res, next) => {
exports.putFunction = async (req, res, next) => {
const { id } = req.params;
const { title, slug, description, type, categorieId } = req.body;
const { title, slug, description, type, categorieId, isOnline } = req.body;
const image = req.files.image;
const errors = validationResult(req);
if (!errors.isEmpty()) {
@ -150,11 +151,11 @@ exports.putFunction = async (req, res, next) => {
deleteFilesNameStartWith(slug, functionPath, () => {
image.mv(path.join(functionPath, imageName), async (error) => {
if (error) return errorHandling(next, serverError);
return await handleEditFunction(res, resultFunction, { title, slug, description, type, categorieId }, imageName);
return await handleEditFunction(res, resultFunction, { title, slug, description, type, categorieId, isOnline }, imageName);
});
});
} else {
return await handleEditFunction(res, resultFunction, { title, slug, description, type, categorieId });
return await handleEditFunction(res, resultFunction, { title, slug, description, type, categorieId, isOnline });
}
} catch (error) {
console.log(error);