Skip to content

Commit 4c90abb

Browse files
committed
routing and seeding
1 parent f385034 commit 4c90abb

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

controllers/types.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
const { where } = require('sequelize/types');
2-
const type = require('../models/type');
31
const enginesRouter = require('../router/enginesRouter');
4-
const { types } = require('./../models')
2+
const { type } = require('./../models')
53

64
class Types {
75
static getAll = async (req, res, next) => {
86
try {
9-
let data = await types.findAll()
7+
let data = await type.findAll()
108
res.status(200).json({
119
data
1210
})

router/typesRouter.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ const typeRouter = require('express').Router();
22
const typeController = require('../controllers/types');
33
const auth = require("../middlewares/auth");
44

5-
typeRouter.get('/types', typeController.getAll)
5+
typeRouter.get('/types', typeController.getAll);
6+
typeRouter.get('/types/:id', typeController.getDetail);
7+
typeRouter.post('/types', typeController.postTypes);
8+
typeRouter.patch('/types/:id', typeController.patchType);
9+
typeRouter.delete('/types/:id', typeController.deleteType);
610

711
module.exports = typeRouter;

seeders/20210930144054-types.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
module.exports = {
4+
up: async (queryInterface, Sequelize) => {
5+
/**
6+
* Add seed commands here.
7+
*
8+
* Example:
9+
* await queryInterface.bulkInsert('People', [{
10+
* name: 'John Doe',
11+
* isBetaMember: false
12+
* }], {});
13+
*/
14+
await queryInterface.bulkInsert('types', [
15+
{
16+
name: 'Scooter',
17+
foundedYear: 1915,
18+
foundedCountry: 'Italy',
19+
createdAt: new Date(),
20+
updatedAt: new Date()
21+
},
22+
{
23+
name: 'Sport',
24+
foundedYear: 1894,
25+
foundedCountry: 'France',
26+
createdAt: new Date(),
27+
updatedAt: new Date()
28+
},
29+
{
30+
name: 'Adventure Tourer',
31+
foundedYear: 1947,
32+
foundedCountry: 'Spain',
33+
createdAt: new Date(),
34+
updatedAt: new Date()
35+
},
36+
{
37+
name: 'Jetsky',
38+
foundedYear: 1992,
39+
foundedCountry: 'Japan',
40+
createdAt: new Date(),
41+
updatedAt: new Date()
42+
},
43+
{
44+
name: 'Sport Tourer',
45+
foundedYear: 1967,
46+
foundedCountry: 'Northern Ireland',
47+
createdAt: new Date(),
48+
updatedAt: new Date()
49+
}
50+
])
51+
},
52+
53+
down: async (queryInterface, Sequelize) => {
54+
/**
55+
* Add commands to revert seed here.
56+
*
57+
* Example:
58+
* await queryInterface.bulkDelete('People', null, {});
59+
*/
60+
await queryInterface.bulkDelete('types', null, {});
61+
}
62+
};

0 commit comments

Comments
 (0)