-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.js
66 lines (54 loc) · 1.56 KB
/
queries.js
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
const knex = require('knex')
const database = require('./database/Database')
const { Model } = require('objection')
Model.knex(database)
const User = require('./models/User')
const UserCommand = require('./models/UserCommand')
module.exports = {
showUser(id) {
return User.query()
.where('id', id)
.withGraphFetched('usercommands')
},
findUser(username) {
const foundUser = User.query()
.where('username', username)
.first()
.withGraphFetched('usercommands')
return foundUser
},
createUser(user) {
const newUser = User.query().insert({
username: user.username,
password: user.password
})
return newUser
},
createNewUserCommands(id) {
for(let i = 1; i < 15; i++) {
UserCommand.query().insert({
user_id: id,
command_id: i,
phrase: ""
})
.then(response => console.log(response))
}
return User.query().findById(id)
.withGraphFetched('usercommands')
},
deleteUser(id) {
// UserCommand.query()
// .where('user_id', id)
// .delete()
const userDeleted = User.query().deleteById(id)
return userDeleted
},
updateUserCommand(params) {
const updatedUserCommand = UserCommand.query()
.findById(params.id)
.patch({
phrase: params.phrase
})
return updatedUserCommand
}
}