-
check_circle_outlineMódulo 1 | 8 clases
Introducción
expand_more -
check_circle_outlineMódulo 2 | 19 clases
Http
expand_more -
check_circle_outlineMódulo 3 | 11 clases
Bases de Datos
expand_more -
check_circle_outlineMódulo 4 | 24 clases
Buenas prácticas de desarrollo.
expand_more -
check_circle_outlineMódulo 5 | 14 clases
Autenticación
expand_more -
check_circle_outlineMódulo 6 | 14 clases
Relaciones en la base de datos.
expand_more-
done_all
Clase 1
Fundamentos de relaciones en la base de datos
-
done_all
Clase 2
Relaciones uno a muchos - El esquema
-
done_all
Clase 3
Relaciones uno a muchos - Los modelos
-
done_all
Clase 4
Nombres para asociaciones
-
done_all
Clase 5
Guardar relación uno a muchos
-
done_all
Clase 6
Relaciones en un proyecto real
-
done_all
Clase 7
Eager loading (Cargado anticipado)
-
done_all
Clase 8
Ejercicio - Implementa tu propio CRUD
-
done_all
Clase 9
Relaciones muchos a muchos
-
done_all
Clase 10
Integrando CRUD de Categorías
-
done_all
Clase 11
Tabla asociativa
-
done_all
Clase 12
Definir relación muchos a muchos
-
done_all
Clase 13
Crear relaciones muchos a muchos
-
done_all
Clase 14
Mostrar objetos de una relación muchos a muchos
-
-
check_circle_outlineMódulo 7 | 5 clases
Websockets (realtime)
expand_more -
check_circle_outlineMódulo 8 | 4 clases
Entorno de producción
expand_more -
check_circle_outlineMódulo 9.-
Examen del curso
expand_more-
done_all
Examen
Examen final del curso
-
4 comentario(s)
Hermano, lastima que no nos puso a disposición de Todos, el New, para que veamos la caja del color, en las lineas de abajo, están las lineas de código para lograrlo, exitos!!, que puedo hacer par en mi navegador se vea el json como en el suyo, yo veo su contenido en lineas seguidas, no en campos debajo del otro
controllers/categories.js
const Category = require('../models').Category;
module.exports = {
create: (req,res) => {
Category.create({
title: req.body.title,
color: req.body.color
})
.then(result => res.json(result))
.catch(err => res.json(err))
;
},
new: (req,res) => {
res.render('categories/new');
},
index: (req,res) => {
Category.findAll()
.then(categories => res.render('categories/index',{categories}))
;
},
show: (req,res) => {
Category.findById(req.params.id)
.then(category => res.render('categories/show',{category}))
;
},
update: (req,res) => {
Category.update({
title: req.body.title,
color: req.body.color
}, {
where: {
id: req.params.id
}
})
.then(response => res.redirect('/categories/' + req.params.id))
.catch(err => res.json('ERROR: ' + err))
;
},
edit: (req,res) => {
Category.findById(req.params.id)
.then(category => res.render('categories/edit',{category}))
;
},
destroy: (req,res) => {
Category.destroy({
where: {
id: req.params.id
}
})
.then(contadorElementosEliminados => {
console.log(contadorElementosEliminados);
res.redirect('/categories');
})
;
}
}
routes/categories_router.js
const router = require('express').Router();
let CategoriesController = require('../controllers/categories');
router.route('/categories')
.get(CategoriesController.index)
.post(CategoriesController.create)
;
router.get('/categories/new',CategoriesController.new);
router.get('/categories/:id/edit',CategoriesController.edit);
router.route('/categories/:id')
.get(CategoriesController.show)
.put(CategoriesController.update)
.delete(CategoriesController.destroy)
;
module.exports = router;
edit.pug
doctype html
html
head
title Categorias
body
form(action='/categories/' + category.id + '?_method=PUT' method='POST')
input(name='title' placeholder='Título' type='text' value=category.title)
input(name='color' type='color' value=category.color)
input(type='submit' value='Guardar')
index.pug
doctype html
html
head
title Categorías
body
ul
each category in categories
li= category.title
new.pug
doctype html
html
head
title Categorias
body
form(action='/categories' method='POST')
input(name='title' placeholder='Título' type='text')
input(name='color' type='color')
input(type='submit' value='Guardar')
show.pug
doctype html
html
head
title Tareas
body
h1= task.description
p= task.createdAt
p
strong Autor:
span= task.user.email
form(action='/tasks/' + task.id + '?_method=DELETE' method='POST')
input(type='submit' value='Eliminar')
const Category = require('../models').Category;
module.exports = {
create: (req,res) => {
Category.create({
title: req.body.title,
color: req.body.color
})
.then(result => res.json(result))
.catch(err => res.json(err))
;
},
new: (req,res) => {
res.render('categories/new');
},
index: (req,res) => {
Category.findAll()
.then(categories => res.render('categories/index',{categories}))
;
},
show: (req,res) => {
Category.findById(req.params.id)
.then(category => res.render('categories/show',{category}))
;
},
update: (req,res) => {
Category.update({
title: req.body.title,
color: req.body.color
}, {
where: {
id: req.params.id
}
})
.then(response => res.redirect('/categories/' + req.params.id))
.catch(err => res.json('ERROR: ' + err))
;
},
edit: (req,res) => {
Category.findById(req.params.id)
.then(category => res.render('categories/edit',{category}))
;
},
destroy: (req,res) => {
Category.destroy({
where: {
id: req.params.id
}
})
.then(contadorElementosEliminados => {
console.log(contadorElementosEliminados);
res.redirect('/categories');
})
;
}
}
routes/categories_router.js
const router = require('express').Router();
let CategoriesController = require('../controllers/categories');
router.route('/categories')
.get(CategoriesController.index)
.post(CategoriesController.create)
;
router.get('/categories/new',CategoriesController.new);
router.get('/categories/:id/edit',CategoriesController.edit);
router.route('/categories/:id')
.get(CategoriesController.show)
.put(CategoriesController.update)
.delete(CategoriesController.destroy)
;
module.exports = router;
edit.pug
doctype html
html
head
title Categorias
body
form(action='/categories/' + category.id + '?_method=PUT' method='POST')
input(name='title' placeholder='Título' type='text' value=category.title)
input(name='color' type='color' value=category.color)
input(type='submit' value='Guardar')
index.pug
doctype html
html
head
title Categorías
body
ul
each category in categories
li= category.title
new.pug
doctype html
html
head
title Categorias
body
form(action='/categories' method='POST')
input(name='title' placeholder='Título' type='text')
input(name='color' type='color')
input(type='submit' value='Guardar')
show.pug
doctype html
html
head
title Tareas
body
h1= task.description
p= task.createdAt
p
strong Autor:
span= task.user.email
form(action='/tasks/' + task.id + '?_method=DELETE' method='POST')
input(type='submit' value='Eliminar')
Clase 72