def generate_exports(self): self.add_line_to_controller(" ") self.add_line_to_controller("module.exports = {") self.add_line_to_controller("\tget" + self.model_name + ",") self.add_line_to_controller("\tget" + sh.pluralize(self.model_name) + ",") self.add_line_to_controller("\tadd" + self.model_name + ",") self.add_line_to_controller("\tupdate" + self.model_name + ",") self.add_line_to_controller("\tremove" + self.model_name + ",") self.add_function_closer()
def generate_find_all(self): self.add_line_to_controller("") self.add_comment_to_controller(comment="Get every " + self.model_name + " from the db") self.add_function_header("get" + sh.pluralize(self.model_name)) self.add_line_to_controller("\t" + self.model_name + ".findAll().then((" + sh.pluralize(self.model_name_camel_case) + " ) => {") self.add_line_to_controller("\t\t return res.status(200).json({" + sh.pluralize(self.model_name_camel_case) + "});") self.add_line_to_controller("\t}).catch((err) => {") self.add_line_to_controller("\t\t return res.status(400).json({") self.add_line_to_controller( '\t\t\t content : "No ' + sh.pluralize(sh.break_camel_case(self.model_name_camel_case)) + ' found"') self.add_line_to_controller("\t });") self.add_line_to_controller("\t});") self.add_function_closer()
def generate_find_one(self): self.add_line_to_controller("") self.add_comment_to_controller(comment="Get one " + self.model_name + " from the db") self.add_function_header("get" + self.model_name) self.add_line_to_controller("") self.add_line_to_controller("\tconst id = req.params.id") self.add_line_to_controller("") self.add_line_to_controller("\t" + self.model_name + ".findOne({where : { id : id }}).then((" + self.model_name_camel_case + ") => {") self.add_line_to_controller("\t\t return res.status(200).json(" + self.model_name_camel_case + ");") self.add_line_to_controller("\t}).catch((err) => {") self.add_line_to_controller("\t\t return res.status(400).json({") self.add_line_to_controller( '\t\t\t content : "No ' + sh.pluralize(sh.break_camel_case(self.model_name_camel_case)) + ' found"') self.add_line_to_controller("\t });") self.add_line_to_controller("\t});") self.add_function_closer()
def generate_get_all(self): self.add_line_to_router("") self.add_comment_to_router(" Get all " + sh.pluralize(sh.break_camel_case(self.model_name)) + " from the db") self.add_line_to_router("" + self.router_name + '.get("/", ' + self.controller_name + ".get" + sh.pluralize(self.model_name) + ");")
def test_pluralize_y_case(self): self.assertEqual(sh.pluralize("weapon"), "weapons")
def test_pluralize_normal_case(self): self.assertEqual(sh.pluralize("quality"), "qualities")