-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
145 lines (126 loc) · 3.5 KB
/
app.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
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
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
require("dotenv/config");
const app = express();
//MIDDLEWARES---functions which runs only when a certain page is requested
var PORT = process.env.PORT;
//app.use("bodyParser.json()");
//listening to server
app.listen(PORT);
//Connection to database
mongoose.connect(process.env.DB_CONNECTION, { useNewUrlParser: true }, () => {
console.log("connected to db");
});
//Creating a Schema for db----
var schema = new mongoose.Schema(
{
date: String,
Sign: String,
dailyHoroscope: String,
dailyHealthHoroscope: String,
dailyCarrerHoroscope: String,
dailyMoneyHoroscope: String,
Taurus: String,
},
{ collection: "ZodiacData" }
);
var zodiac = mongoose.model("zodiac", schema);
//api call-
//date mechanism-
let dateObj = new Date();
let month = String(dateObj.getMonth() + 1).padStart(2, "0");
let day = String(dateObj.getDate()).padStart(2, "0");
let year = dateObj.getFullYear();
let output = year + "-" + month + "-" + day;
//end
var query1 = { date: output, sign: "Leo" };
var query2 = { date: output, sign: "Aries" };
var query3 = { date: output, sign: "Pisces" };
var query4 = { date: output, sign: "Capricorn" };
var query5 = { date: output, sign: "Gemini" };
var query6 = { date: output, sign: "Scorpio" };
var query7 = { date: output, sign: "Libra" };
var query8 = { date: output, sign: "Virgo" };
var query9 = { date: output, sign: "Aquarius" };
var query10 = { date: output, sign: "Cancer" };
var query11 = { date: output, sign: "Sagittarius" };
var query12 = { date: output, sign: "Sagittarius" };
//main page:
app.get("/", function (req, res) {
res.send(
"============================== \n **********ZODIAC API********** \n 0101Author-Sauhardya Singha010 \n =============================="
);
});
//Leo
app.get("/api/zodiac/leo", function (req, res) {
zodiac.find(query1, function (err, result) {
res.send(result);
});
});
//Aries
app.get("/api/zodiac/aries", function (req, res) {
zodiac.find(query2, function (err, result) {
res.send(result);
});
});
//Pisces
app.get("/api/zodiac/pisces", function (req, res) {
zodiac.find(query3, function (err, result) {
res.send(result);
});
});
//Capricorn
app.get("/api/zodiac/capricorn", function (req, res) {
zodiac.find(query4, function (err, result) {
res.send(result);
});
});
//Gemini
app.get("/api/zodiac/gemini", function (req, res) {
zodiac.find(query5, function (err, result) {
res.send(result);
});
});
//Scorpio
app.get("/api/zodiac/scorpio", function (req, res) {
zodiac.find(query6, function (err, result) {
res.send(result);
});
});
//Libra
app.get("/api/zodiac/libra", function (req, res) {
zodiac.find(query7, function (err, result) {
res.send(result);
});
});
//Virgo
app.get("/api/zodiac/virgo", function (req, res) {
zodiac.find(query8, function (err, result) {
res.send(result);
});
});
//Aquarius
app.get("/api/zodiac/aquarius", function (req, res) {
zodiac.find(query9, function (err, result) {
res.send(result);
});
});
//Cancer
app.get("/api/zodiac/cancer", function (req, res) {
zodiac.find(query10, function (err, result) {
res.send(result);
});
});
//Sagittarius
app.get("/api/zodiac/sagittarius", function (req, res) {
zodiac.find(query11, function (err, result) {
res.send(result);
});
});
//Taurus
app.get("/api/zodiac/sagittarius", function (req, res) {
zodiac.find(query12, function (err, result) {
res.send(result);
});
});