-
Notifications
You must be signed in to change notification settings - Fork 2
/
xserver.js
169 lines (149 loc) · 5.4 KB
/
xserver.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// 'use strict';
// const express = require('express');
// require('dotenv').config();
// const mongoose = require('mongoose');
// const cors = require('cors');
// const app = express();
// app.use(cors());
// app.use(express.json());
// mongoose.connect(process.env.MONGODB_URL, {
// useNewUrlParser: true,
// useUnifiedTopology: true,
// });
// const PORT = process.env.PORT;
// const bookSchema = mongoose.Schema({
// bookName: String,
// describtion: String,
// image: String,
// });
// const Book = mongoose.model('book', bookSchema);
// const userSchema = mongoose.Schema({
// email: String,
// books: [bookSchema],
// });
// const User = mongoose.model('user', userSchema);
// function createUser() {
// const mahmoud = new User({
// email: '[email protected]',
// books: [
// {
// bookName: 'Reinforcement Concrete',
// describtion: 'talk about designing structural concrete',
// image:
// 'https://images-na.ssl-images-amazon.com/images/I/81Wj1JQ+mKL.jpg',
// },
// {
// bookName: 'Crime and Punishment',
// describtion:
// 'Crime and Punishment focuses on the mental anguish and moral dilemmas of Rodion Raskolnikov, an impoverished ex-student in Saint Petersburg who formulates a plan to kill an unscrupulous pawnbroker for her money.',
// image:
// 'https://kbimages1-a.akamaihd.net/b1c96137-0ddf-4ee4-8f46-73bdfa9b8621/1200/1200/False/crime-and-punishment-by-fyodor-dostoevsky-1.jpg',
// },
// {
// bookName: 'Demons',
// describtion:
// 'Demons is an allegory of the potentially catastrophic consequences of the political and moral nihilism that were becoming prevalent in Russia in the 1860s. A fictional town descends into chaos as it becomes the focal point of an attempted revolution, orchestrated by master conspirator Pyotr Verkhovensky.',
// image:
// 'https://i.gr-assets.com/images/S/compressed.photo.goodreads.com/books/1524586008l/5695.jpg',
// },
// ],
// });
// const alaa = new User({
// email: '[email protected]',
// books: [
// {
// bookName: 'Static',
// describtion: 'talk about designing structural concrete',
// image:
// 'https://images-na.ssl-images-amazon.com/images/I/81Wj1JQ+mKL.jpg',
// },
// {
// bookName: 'Crime and Punishment2',
// describtion:
// 'Crime and Punishment focuses on the mental anguish and moral dilemmas of Rodion Raskolnikov, an impoverished ex-student in Saint Petersburg who formulates a plan to kill an unscrupulous pawnbroker for her money.',
// image:
// 'https://kbimages1-a.akamaihd.net/b1c96137-0ddf-4ee4-8f46-73bdfa9b8621/1200/1200/False/crime-and-punishment-by-fyodor-dostoevsky-1.jpg',
// },
// {
// bookName: 'Demons',
// describtion:
// 'Demons is an allegory of the potentially catastrophic consequences of the political and moral nihilism that were becoming prevalent in Russia in the 1860s. A fictional town descends into chaos as it becomes the focal point of an attempted revolution, orchestrated by master conspirator Pyotr Verkhovensky.',
// image:
// 'https://i.gr-assets.com/images/S/compressed.photo.goodreads.com/books/1524586008l/5695.jpg',
// },
// ],
// });
// alaa.save();
// mahmoud.save();
// }
// // createUser();
// app.get('/books', (req, res) => {
// const email = req.query.userEmail;
// User.find({ email: email }, (err, data) => {
// if (err) {
// console.log(err);
// } else {
// res.status(200).send(data[0].books);
// }
// });
// });
// app.post('/books', postBook);
// function postBook(req, res) {
// const { bookName, describtion, image, email } = req.body;
// User.find({ email: email }, (err, data) => {
// if (err) {
// console.log(err.message);
// res.status(500).send(err.message);
// } else {
// data[0].books.push({
// bookName,
// describtion,
// image,
// });
// data[0].save();
// res.status(201).send(data[0].books);
// }
// });
// }
// app.delete('/books/:id', deletBook);
// function deletBook(req, res) {
// const { email } = req.query;
// const id = req.params.id;
// // console.log(index);
// // console.log(email);
// User.find({ email: email }, (err, data) => {
// if (err) {
// console.log(err.message);
// res.status(500).send(err.message);
// } else {
// const newBookStore = data[0].books.filter((book, index) => {
// return id != index;
// });
// data[0].books = newBookStore;
// data[0].save();
// res.status(201).send(data[0].books);
// }
// });
// }
// app.put('/books/:id', updateBook);
// function updateBook(req, res) {
// const { bookName, describtion, image, email } = req.body;
// const id = req.params.id;
// // console.log(index);
// // console.log(email);
// User.find({ email: email }, (err, data) => {
// if (err) {
// console.log(err.message);
// res.status(500).send(err.message);
// } else {
// data[0].books.splice(id, 1, {
// bookName,
// describtion,
// image,
// });
// data[0].save();
// res.status(201).send(data[0].books);
// }
// });
// }
// app.listen(PORT, () => console.log(`listening on PORT ${PORT}`));