-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (43 loc) · 1.08 KB
/
index.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
const express = require('express');
const path = require('path');
const { Op } = require('sequelize');
const app = express();
const { School } = require('./models');
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.get('/', async (req, res) => {
const schools = await School.findAll();
res.render('index', {
schools: schools
});
});
app.post('/', async (req, res) => {
const schools = await School.findAll({
where: {
name: {
[Op.substring]: req.body.search
}
}
});
res.render('index', {
schools: schools
});
});
app.post('/filter', async (req, res) => {
const schools = await School.findAll({
where: {
[Op.and]: [
req.body.status != 'all' ? { status: req.body.status } : null,
req.body.address != null ? { address: { [Op.substring]: req.body.address } } : null
]
}
});
res.render('index', {
schools: schools
});
});
app.listen(3000, () => {
console.log(`Apps run on http://localhost:3000`)
});