fga-eps-mds/2020.1-VC_Gestor-BackEnd

View on GitHub
packages/news/src/controller/CreateResolve.js

Summary

Maintainability
A
35 mins
Test Coverage
const News = require("../models/news");
 
module.exports = {
async CreateResolve(request) {
 
Identical blocks of code found in 2 locations. Consider refactoring.
const { title, subtitle, text, image1, image2, image3, post_id } = request.body;
 
if ( title === "" || subtitle === "" || text === "" ) {
throw { error: "Fill request.body correctly, cannot be an empty string or null value "};
}
 
var news = await News.findOne({ where: {title} });
 
if(news) {
throw { error: "News already with this title" };
}
 
news = await News.create({
title,
subtitle,
text,
image1,
image2,
image3,
post_id
});
 
return news;
}
};