-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.js
More file actions
74 lines (62 loc) · 1.54 KB
/
models.js
File metadata and controls
74 lines (62 loc) · 1.54 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
const db = require('../db-config');
module.exports = {
getAllStories,
getStoriesByID,
addStories,
updateStories,
removeStories,
getAllStoriesAuth,
getStoriesByIDAuth,
addStoriesAuth,
updateStoriesAuth,
removeStoriesAuth
}
////////////////////////////UN-AUTHORIZED ROUTES\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//Get All requests
function getAllStories(){
return db('stories')
}
function getStoriesByID(id){
return db('stories').where({ id });
}
function addStories(stories) {
return db('stories')
.insert(stories)
.then(([id]) => getStoriesByID(id));
}
function updateStories(id, changes) {
return db('stories')
.where('id', id)
.update(changes)
.then(count => (count > 0 ? getStoriesByID(id) : null));
}
function removeStories(id) {
return db('stories')
.where('id', id)
.del();
}
////////////////////////////AUTHORIZED ROUTES\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//Get All requests
function getAllStoriesAuth(){
return db('auth-stories')
}
function getStoriesByIDAuth(id){
return db('auth-stories').where({ id });
}
function addStoriesAuth(stories) {
return db('auth-stories')
.insert(stories)
.then(([id]) => getStoriesByID(id));
}
function updateStoriesAuth(id, changes) {
return db('auth-stories')
.where('id', id)
.update(changes)
.then(count => (count > 0 ? getStoriesByID(id) : null));
}
function removeStoriesAuth(id) {
return db('auth-stories')
.where('id', id)
.del();
}
//models