-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.js
55 lines (50 loc) · 1.63 KB
/
data.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
const UserSchema = require("../models/user");
const express = require("express");
const mongoose = require("mongoose");
const bunyan = require("bunyan");
const Msg = require("../public/js/msg");
var router = express.Router();
var log = bunyan.createLogger({ name: "crud" });
mongoose.Promise = global.Promise;
const msg = new Msg();
const padrao = mongoose.model("User", UserSchema);
router
.route("/")
.get((_req, res) => {
padrao.find((error, elementos) => {
if (error)
{
res.render("pages/error", {
title: msg.titleData,
subtitle: msg.titleData,
error: error,
});
log.warn("GET -> /data ❌ " + error)
}
res.render("pages/data", {
title: msg.titleData,
nicknameResult:
"",
data: elementos,
});
log.info("GET -> /data ✅");
});
});
router
.route("/search?:nickname")
.get((req, res) => {
padrao.find((error, elementos) => {
if (error)
res.render("pages/error", {
title: msg.titleData,
error: error,
});
res.render("pages/data", {
title: msg.titleResults,
nicknameResult: req.query.nickname,
data: elementos,
});
log.info("GET -> /data/search?nickname=" + req.query.nickname + " ✅");
});
});
module.exports = router;