forked from FamesStore/scratchProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
91 lines (74 loc) · 2.11 KB
/
controller.js
File metadata and controls
91 lines (74 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const Sequelize = require('sequelize');
const sequelize = new Sequelize('itemsList', 'famesStore', 'Seth', {
host: 'localhost',
dialect: 'postgres'
});
const Item = sequelize.define('item', {
itemId: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
sellerId: Sequelize.INTEGER,
sellerRating: Sequelize.INTEGER,
category: Sequelize.STRING,
itemName: Sequelize.STRING,
price: Sequelize.INTEGER,
condition: Sequelize.STRING,
quantity: Sequelize.INTEGER,
});
const User = sequelize.define('user', {
userId: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
userName: Sequelize.STRING,
password: Sequelize.STRING,
sellerRating: Sequelize.INTEGER,
itemsBought: Sequelize.STRING,
itemsToSell: Sequelize.STRING,
description: Sequelize.STRING,
});
//User.hasMany(Item, {foreignKey: "itemId"});
//Item.hasOne(User, {foreignKey: "userId"});
sequelize.sync({force: true});
let dbController = {
createUser: (req, res, next) => {
console.log(req.body)
User
.build({
userName: req.body.userName,
password: req.body.userPassword,
description: req.body.userDescription,
})
.save()
//.then(anotherTask => {
// you can now access the currently saved task with the variable anotherTask... nice!
//})
.catch(error => {
console.log(error)
})
next();
},
createItem: (req, res, next) => {
console.log(req.body)
Item
.build({
category: req.body.itemCategory,
itemName: req.body.itemName,
price: req.body.itemPrice,
condition: req.body.itemCondition,
quantity: req.body.itemQuantity,
description: req.body.itemDescription
})
.save()
//.then(anotherTask => {
// you can now access the currently saved task with the variable anotherTask... nice!
//})
.catch(error => {
console.log(error)
})
next();
}
}
module.exports = dbController;
// what does the sync method do?
// const itemRecord = Item.build('item');
// await itemRecord.save();
// const userRecord = User.build('user');
// await userRecord.save();
// });
// });