-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes.js
66 lines (59 loc) · 1.38 KB
/
routes.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 express = require('express')
const router = express.Router()
const db = require('./db/index')
const utils = require('./utils')
const fetch = require('node-fetch')
router.get('/palettes', (req, res) => {
db.getPalettes()
.then((palettes) => {
let parsedColors = utils.parseColors(palettes)
res.render('palettes', { palettes: parsedColors })
})
.catch((err) => {
console.log(err)
res.send('Not good. ' + err.message)
})
})
// non async version
router.get('/generate', (req, res) => {
utils
.fetchRandomPalette()
.then((palette) => {
res.render('generate', palette)
})
.catch((err) => {
console.log(err)
res.send('Not good. ' + err.message)
})
})
// get targeted palette
router.post('/generate', (req, res) => {
let { colorOne, colorTwo } = req.body
utils
.fetchTargetedPalette(colorOne, colorTwo)
.then((palette) => {
res.render('generate', palette)
})
.catch((err) => {
console.log(err)
res.send('Not good. ' + err.message)
})
})
// add color to palettes
router.post('/generate/save', (req, res) => {
let colors = req.body
let array = colors.colors.split(',')
db.addPalette(array)
.then(() => {
res.redirect('/generate')
})
.catch((err) => {
console.log(err)
res.send('Not good. ' + err.message)
})
})
// TODO
// delete
// update
// built in color picker (react, bootstrap, other library or module.)
module.exports = router