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