-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchThisSummary.txt
208 lines (172 loc) · 4.51 KB
/
fetchThisSummary.txt
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
fetchThisSummary
A logged in user can retrieve with visible confirmation without causing a refresh/redirect.
GET /api/summary/:id
/app/:id
This page displays summary of associated tasks, as well as a navigation bar with login/signup or logout buttons.
If logged in user owns the task, page displays buttons update and delete.
GET /app/:id
POST /app/:id
DELETE /app/:id
_______________________________________________________
Persist the User State
-[x] create session secret in .env, and Config file
```
module.exports = {
environment: process.env.NODE_ENV || 'development',
port: process.env.PORT || 8080,
sessionSecret: process.env.SESSION_SECRET,
```
-[x] in app.js import const session = require('express-session')
const app = express();
const { sessionSecret } = require('./config');
-[x] in app.js user cookie parser to pass the session secret
app.use(cookieParser(sessionSecret));
const summaryRouter = require('./routes/summary');
-[x] create & export in utils.pug /checkUserAvailable
-[x] import checkUserAvailable
-[x] update summary.js
```
const express = require("express");
const db = require('../db/models');
const { Task } = db;
const { csrfProtection, asyncHandler,checkUserAvailable } = require('../utils');
const router = express.Router();
```
-[x] touch routes/summary.js
```
router.get(
"/", checkUserAvailable,
asyncHandler(async (req, res, next) => {
const tasks = await Task.findAll();
if (tasks) {
res.json({ tasks });
} else {
next(taskNotFoundError(taskId));
}
})
);
router.get(
"/:id(\\d+)",
checkUserAvailable,
asyncHandler(async (req, res, next) => {
const taskId = parseInt(req.params.id, 10);
const task = await Task.findByPk(taskId);
if (task) {
res.json({ task });
} else {
next(taskNotFoundError(taskId));
}
})
);
const taskNotFoundError = (id) => {
const err = Error(`Task with id of ${id} could not be found.`);
err.title = "Task not found.";
err.status = 404;
return err;
};
router.patch(
"/:id(\\d+)", checkUserAvailable,
asyncHandler(async (req, res, next) => {
const taskId = parseInt(req.params.id, 10);
const task = await Task.findByPk(taskId);
if (task) {
await task.update({ name: req.body.name });
res.json({ task });
} else {
next(taskNotFoundError(taskId));
}
})
);
router.delete(
"/:id(\\d+)",checkUserAvailable,
asyncHandler(async (req, res, next) => {
const taskId = parseInt(req.params.id, 10);
const task = await Task.findByPk(taskId);
if (task) {
await task.destroy();
res.status(204).end();
} else {
next(taskNotFoundError(taskId));
}
})
);
module.exports = router;
```
-[x] touch views/summary.pug
```
extends layout.pug
append head
//- add page specific styles by appending to the head
link(rel="stylesheet" href="/stylesheets/summary.css")
//- add page specific js
//- script(src="/javascripts/index.js" type="module" defer)
block content
h1(class="summaryTitle") Task Summary
div(class="summaryFlexContainer")
div(class="summaryFlexChild")
h2 Pending Tasks
each task in tasks
if !task.completed
div(class="summaryTaskContainer")
p=task.name
p=task.description
div(class="summaryFlexChild")
h2 Completed Tasks
each task in tasks
if task.completed
div(class="summaryTaskContainer")
p=task.name
p=task.description
```
-[x] touch stylesheets/summary.css
append the style sheet with the layout head
import the style
```
body {
background: #DEF6CA;
overflow-y: scroll;
scroll-behavior: smooth;
scroll-snap-type: y mandatory;
scroll-snap-align: center;
}
.summaryFlexContainer{
display:flex;
justify-content: space-around;
}
.summaryFlexChild{
border: 0.5px solid grey;
border-radius: 10px;
width: 45%;
margin: 10px;
padding: 10px;
}
.summaryTaskContainer{
border: 0.5px solid grey;
border-radius: 10px;
background-color: lightgray;
margin: 10px 0;
padding: 10px;
}
.summaryTaskContainer{
border: 0.5px solid grey;
border-radius: 10px;
background-color: lightgray;
margin: 10px 0;
padding: 10px;
}
.summaryTitle{
text-align:center;
margin: 10px;
}
/*
background: #DEF6CA;
color: #bc4749;
background-color: #b4a0e5;
color: #bc4249;
DEF6CA background LIGHT GREEN
A7C957 Android Green BRIGHT GREEN
6A994E May Green Dark GReen
B4A0E5 purple
#bc4749 red
*/
```