This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Sequelize } = require("sequelize"); | |
const Dojos = require("../models/dojos"); | |
module.exports = { | |
async getAll(req, res) { | |
// TODO: This request will result in an error because table name is wrong: `martial_art`... | |
const sequelize = new Sequelize("martial_art", "root", "password", { | |
host: "127.0.0.1", | |
dialect: "mysql", | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
+ const bodyParser = require("body-parser"); | |
const dojosRoutes = require("./api/routes/dojos"); | |
const app = express(); | |
+ const jsonParser = bodyParser.json(); | |
app.listen(8000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Sequelize } = require("sequelize"); | |
const Dojos = require("../models/dojos"); | |
module.exports = { | |
async getAll(req, res) { | |
const sequelize = new Sequelize("martial_arts", "root", "password", { | |
host: "127.0.0.1", | |
dialect: "mysql", | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const dojosController = require("../controllers/dojos"); | |
const router = express.Router(); | |
router.get("/", (req, res) => { | |
dojosController.getAll(req, res); | |
}); | |
router.get("/:id", (req, res) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Sequelize } = require("sequelize"); | |
const Dojos = require("../models/dojos"); | |
module.exports = { | |
async getAll(req, res) { | |
const sequelize = new Sequelize( | |
"martial_arts", | |
"root", | |
"password", | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const { Model } = require("sequelize"); | |
module.exports = (sequelize, DataTypes) => { | |
class Dojos extends Model {} | |
Dojos.init( | |
{ | |
dojo_name: DataTypes.STRING, | |
teacher: DataTypes.STRING, | |
}, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE martial_arts; | |
CREATE TABLE dojos ( | |
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, | |
dojo_name VARCHAR(255), | |
teacher VARCHAR(255) | |
); | |
INSERT INTO dojos (dojo_name, teacher) | |
VALUES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const dojosRoutes = require("./api/routes/dojos"); | |
const app = express(); | |
app.listen(8000); | |
/** | |
* Adding headers to our requests. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const dojosController = require("../controllers/dojos"); | |
const router = express.Router(); | |
router.get("/", (req, res) => { | |
dojosController.getAll(req, res); | |
}); | |
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
getAll(req, res) { | |
res.send({ | |
id: 1, | |
name: "KARATÊ DOJO", | |
teacher: "JACKSON TANAKA", | |
}); | |
}, | |
}; | |
NewerOlder