-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.js
More file actions
executable file
·266 lines (240 loc) · 7.99 KB
/
User.js
File metadata and controls
executable file
·266 lines (240 loc) · 7.99 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
let db;
module.exports = (_db)=>{
db = _db;
return User
}
let User = class {
static connexion(email, password){
return new Promise((next)=>{
db.query("SELECT * FROM users WHERE email = ? AND mot_de_passe = ?", [email, password])
.then((result)=>{
if(result[0] !== undefined){
next(result[0])
}
else{
next(new Error('Aucun User'))
}
})
.catch((error)=>{
next(error);
})
})
}
static inscription(element){
return new Promise((next) => {
db.query("INSERT INTO users (nom,prenoms,email,contacts,localite,sexe,mot_de_passe) VALUES(?,?,?,?,?,?,?)",[element.nom,element.prenoms,element.email,element.contacts,element.localite,element.sexe,element.passwordc])
.then((result) => {
if(result[0] !== undefined){
next(result[0])
}
else{
next(new Error('Erreur survenu lors de l\'inscription'))
}
})
.catch((error)=>{
next(error);
})
})
}
static getPractizePublications(){
return new Promise((next) =>{
db.query('SELECT publications_good_practize.id as id_pub,publications_good_practize.objet,publications_good_practize.message,publications_good_practize.date_de_publication,publications_good_practize.id_user,users.nom,users.prenoms,users.email ,users.localite FROM publications_good_practize INNER JOIN users ON publications_good_practize.id_user = users.id ORDER BY publications_good_practize.id DESC')
.then((result) =>{
next(result)
})
.catch((error)=>{
next(error)
})
})
}
static getConseilSport(){
return new Promise((next) =>{
db.query('SELECT * FROM conseils_sports')
.then((result) =>{
next(result)
})
.catch((error)=>{
next(error)
})
})
}
static getPlats(){
return new Promise((next) =>{
db.query('SELECT * FROM bons_plats')
.then((result) =>{
next(result)
})
.catch((error)=>{
next(error)
})
})
}
static setPractizePublications(element,fichier){
return new Promise((next)=>{
db.query('INSERT INTO publications_good_practize (objet,message,fichier,id_user) VALUES(?,?,?,?)',[element.objet,element.message,fichier,element.id_user])
.then((result)=>{
if(result)
{
next(result)
}
else
{
next(new Error('erruer survenenue lors du serveur'));
}
})
.catch((error) =>{
next(error)
})
})
}
static getCommentairesPractize(){
return new Promise((next)=>{
db.query('SELECT * FROM commmentaires_good_practize')
.then((result)=>{
if(result){
next(result)
}
else
{
next(new Error('erreur survenue'));
}
})
.catch((error)=>{
next(error)
})
})
}
static getCommentairesConseils(){
return new Promise((next)=>{
db.query('SELECT * FROM commentaires_advice')
.then((result)=>{
if(result){
next(result)
}
else
{
next(new Error('erreur survenue'));
}
})
.catch((error)=>{
next(error)
})
})
}
static getCommentairesPlats(){
return new Promise((next)=>{
db.query('SELECT * FROM commentaires_plats')
.then((result)=>{
if(result){
next(result)
}
else
{
next(new Error('erreur survenue'));
}
})
.catch((error)=>{
next(error)
})
})
}
static setCommentairesPractize(element){
return new Promise((next)=>{
db.query('INSERT INTO commmentaires_good_practize (name,commentaire,id_publication) VALUES (?,?,?)',[element.name,element.commentaire,element.id_publication])
.then((result)=>{
if(result){
next(result)
}
else
{
next(new Error('erreur survenue'))
}
})
.catch((error)=>{
next(error)
})
})
}
static setCommentairesConseils(element){
return new Promise((next)=>{
db.query('INSERT INTO commentaires_advice (name,commentaire,id_advice) VALUES (?,?,?)',[element.name,element.commentaire,element.id_publication])
.then((result)=>{
if(result){
next(result)
}
else
{
next(new Error('erreur survenue'))
}
})
.catch((error)=>{
next(error)
})
})
}
static getRecettesPlats(element){
return new Promise((next)=>{
db.query('SELECT bons_plats.id as id_p,bons_plats.nom,bons_plats.image,bons_plats.description,recettes_plats.description as recette_dep,recettes_plats.id_plats FROM bons_plats INNER JOIN recettes_plats ON bons_plats.id = recettes_plats.id_plats WHERE recettes_plats.id_plats = ?',[element])
.then((result)=>{
if(result[0] !== undefined){
next(result[0])
}
else
{
next(new Error('erreur survenue'))
}
})
.catch((error)=>{
next(error)
})
})
}
static setCommentairesPlats(element){
return new Promise((next)=>{
db.query('INSERT INTO commentaires_plats (name,description,id_plats) VALUES (?,?,?)',[element.name,element.description,element.id_plat])
.then((result)=>{
if(result){
next(result)
}
else
{
next(new Error('erreur survenue'))
}
})
.catch((error)=>{
next(error)
})
})
}
static deletePractizePublications(element){
return new Promise((next)=>{
db.query('DELETE FROM commmentaires_good_practize WHERE id_publication = ?',[element.id])
.then((resultat)=>{
if(resultat)
{
db.query('DELETE FROM publications_good_practize WHERE id = ? AND id_user = ?',[element.id,element.id_user])
.then((result)=>{
if(result)
{
next(result);
}
else
{
next(new Error('erreur lors de la suppression'));
}
})
.catch((error)=>{
next(error)
})
}
else
{
next(new Error('il ya une erreur'))
}
})
.catch((error)=>{
next(error)
})
})
}
}