-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
371 lines (318 loc) · 23.7 KB
/
db.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
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
const Sequelize = require("sequelize");
const ProfileModel = require("./models/profile");
const UserModel = require("./models/user");
const ImageModel = require("./models/image");
const PostModel = require("./models/post");
const FollowModel = require("./models/follow");
const PostImageModel = require('./models/postimage');
const HeartModel = require('./models/heart');
const CommentModel = require('./models/comment');
const ConversationModel = require('./models/conversation');
const MessageModel = require('./models/message');
// const RecoverModel = require('./models/recover');
// const LevelModel = require('./models/level');
// const CountryModel = require('./models/country');
// const SentimentalModel = require('./models/sentimental');
// const AlbumModel = require('./models/album');
// const FriendModel = require('./models/friend');
// const NotificationModel = require('./models/notification');
// const TeamModel = require('./models/team');
/*const sequelize = new Sequelize("redsocial", "develoddy", "$$developer20", {
host: "192.168.64.6",
dialect: "mysql",
define: {
timestamps: false,
},
});*/
const sequelize = new Sequelize("redsocial", "root", "", {
host: "localhost",
dialect: "mysql",
define: {
timestamps: false,
},
});
const Profile = ProfileModel(sequelize, Sequelize);
const User = UserModel(sequelize, Sequelize);
const Image = ImageModel(sequelize, Sequelize);
const Post = PostModel(sequelize, Sequelize);
const Follow = FollowModel(sequelize, Sequelize);
const PostImage = PostImageModel(sequelize, Sequelize);
const Heart = HeartModel(sequelize, Sequelize);
const Comment = CommentModel(sequelize, Sequelize);
const Conversation= ConversationModel(sequelize, Sequelize);
const Message = MessageModel(sequelize, Sequelize);
// const Recover = RecoverModel(sequelize, Sequelize);
// const Level = LevelModel(sequelize, Sequelize);
// const Country = CountryModel(sequelize, Sequelize);
// const Sentimental = SentimentalModel(sequelize, Sequelize);
// const Album = AlbumModel(sequelize, Sequelize);
// const Friend = FriendModel(sequelize, Sequelize);
// const Notification= NotificationModel(sequelize, Sequelize);
// const Team = TeamModel(sequelize, Sequelize);
// USUARIOS
const users = [
{id: 1, name: "eddy",lastname: "",username: "eddylujan",email: "[email protected]",password: "$2a$10$pLDdShGtxluePFEIErqk.e3iXB5tEVbOLkXzqw0bW5CEDKYyVYo4S",code: "",is_active: 0,is_admin: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23"},
{id: 2, name: "jordan",lastname: "",username: "jordan",email: "[email protected]",password: "$2a$10$oeq01oRVnhu7YQVoZdIWkOJ6DN3qsfJju5TCS1CRqu8Jo5JUQn/4G",code: "",is_active: 0,is_admin: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23"},
{id: 3, name: "Pablo Lujan",lastname: "",username: "chingo",email: "[email protected]",password: "$2a$10$AWKpCGfdLgo/EHq9Z8Abrev9S7tFUVYPlG1Ucgxj6CtjwxO.ummO6",code: "",is_active: 0,is_admin: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23"},
{id: 4, name: "Paola Lujan",lastname: "",username: "paola",email: "[email protected]",password: "$2a$10$.F0KIcPCzFw7QCBQjrZ1huDsmGWDYoGuxgIO9fyJUMlyzf7rDz1ny",code: "",is_active: 0,is_admin: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23"},
{id: 5, name: "Pepito Flores",lastname: "",username: "pepito",email: "[email protected]",password: "$2a$10$7RjAHKWor3zgni5foiGGFupeqSNZVCpfdoP6BPODVd9tg/7wy1JSe",code: "",is_active: 0,is_admin: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23"},
{id: 6, name: "Juanito Perez",lastname: "",username: "juanito",email: "[email protected]",password: "$2a$10$tg4q7Q3GNmN5n/JtX4GjuOLBmsUZfEAtjHfNk2gzoFfq241VSN6XK",code: "",is_active: 0,is_admin: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23"},
{id: 7, name: "Mendito Rodriguez",lastname: "",username: "mendito",email: "[email protected]",password: "$2a$10$aJyHRoKEv3NZAwib4rRt4uEfEa1Ar1pJQhPZzMwKoCF5HIJHdl9nO",code: "",is_active: 0,is_admin: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23"},
{id: 8, name: "Paquito Avianca",lastname: "",username: "paquito",email: "[email protected]",password: "$2a$10$yFSEHej/Rzte4sh6Wc/sZen2EVwidgWJdvt3dnf/9wf4BfwwVShBe",code: "",is_active: 0,is_admin: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23"},
{id: 9, name: "Lolita Castillo",lastname: "",username: "lolita",email: "[email protected]",password: "$2a$10$z5QRrsb5Sv9INVKzlBmQEO3sUC.NX4oDM6WP36A4APkUtgNxZz8py",code: "",is_active: 0,is_admin: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23"},
{id: 10, name: "Luna Mendieta",lastname: "",username: "luna",email: "[email protected]",password: "$2a$10$FgT2Z4sZ8MMEEpvTBYGwIO8pqNAYLnOTB2n6.Nu0XzqwJTstM3YhW",code: "",is_active: 0,is_admin: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23"},
];
// PERFILES
const profiles = [
{day_of_birth: "2021-12-26 21:47:23", gender: "", country_id: 0, image: "", image_header: "eddy.jpeg", title: "", bio: "Bio Eddy", likes: "", dislikes: "", address: "", phone: "",public_email: "[email protected]",user_id: 1,level_id: 0,sentimental_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 1,},
{day_of_birth: "2021-12-26 21:47:23", gender: "", country_id: 0, image: "", image_header: "jordan.jpeg", title: "", bio: "Bio Jordan", likes: "", dislikes: "", address: "", phone: "",public_email: "[email protected]",user_id: 2,level_id: 0,sentimental_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 2,},
{day_of_birth: "2021-12-26 21:47:23", gender: "", country_id: 0, image: "", image_header: "chingo.jpeg", title: "", bio: "Bio Chingo", likes: "", dislikes: "", address: "", phone: "",public_email: "[email protected]",user_id: 3,level_id: 0,sentimental_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 3,},
{day_of_birth: "2021-12-26 21:47:23", gender: "", country_id: 0, image: "", image_header: "paola.jpeg", title: "", bio: "Bio Paola", likes: "", dislikes: "", address: "", phone: "",public_email: "[email protected]",user_id: 4,level_id: 0,sentimental_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 4,},
{day_of_birth: "2021-12-26 21:47:23", gender: "", country_id: 0, image: "", image_header: "profile.jpg", title: "", bio: "Bio Pepito", likes: "", dislikes: "", address: "", phone: "",public_email: "[email protected]",user_id: 5,level_id: 0,sentimental_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 5,},
{day_of_birth: "2021-12-26 21:47:23", gender: "", country_id: 0, image: "", image_header: "profile.jpg", title: "", bio: "Bio juanito", likes: "", dislikes: "", address: "", phone: "",public_email: "[email protected]",user_id: 6,level_id: 0,sentimental_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 6,},
{day_of_birth: "2021-12-26 21:47:23", gender: "", country_id: 0, image: "", image_header: "profile.jpg", title: "", bio: "Bio Mendito", likes: "", dislikes: "", address: "", phone: "",public_email: "[email protected]",user_id: 7,level_id: 0,sentimental_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 7,},
{day_of_birth: "2021-12-26 21:47:23", gender: "", country_id: 0, image: "", image_header: "profile.jpg", title: "", bio: "Bio Paquito", likes: "", dislikes: "", address: "", phone: "",public_email: "[email protected]",user_id: 8,level_id: 0,sentimental_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 8,},
{day_of_birth: "2021-12-26 21:47:23", gender: "", country_id: 0, image: "", image_header: "profile.jpg", title: "", bio: "Bio Lolita", likes: "", dislikes: "", address: "", phone: "",public_email: "[email protected]",user_id: 9,level_id: 0,sentimental_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 9,},
{day_of_birth: "2021-12-26 21:47:23", gender: "", country_id: 0, image: "", image_header: "profile.jpg", title: "", bio: "Bio Luna", likes: "", dislikes: "", address: "", phone: "",public_email: "[email protected]",user_id: 10,level_id: 0,sentimental_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 10,},
];
// IMAGENES
const images = [
{ src:"public/posts/imga-01.jpg" , title:"imga-01.jpg" , content: "b02", user_id: 0, level_id: 0, album_id:0, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23", }
]
// FOLLOWS
const follows = [
// eddy sigue a 5 usuarios
{ user_id: 1, followed_id: 2, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23" },
{ user_id: 1, followed_id: 3, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23" },
{ user_id: 1, followed_id: 4, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23" },
{ user_id: 1, followed_id: 5, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23" },
{ user_id: 1, followed_id: 6, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23" },
// Jordan sigue a 2 usuarios (eddy y paola)
{ user_id: 6, followed_id: 1, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23" },
{ user_id: 6, followed_id: 5, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23" },
// Paola sigue a 3 usuarios (eddy, jordan y chingo)
{ user_id: 5, followed_id: 1, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23" },
{ user_id: 5, followed_id: 2, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23" },
{ user_id: 5, followed_id: 6, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23" },
];
// CONVERSACIONES.
const conversations = [
{sender_id: 1, receptor_id: 2, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23"},
{sender_id: 2, receptor_id: 1, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23"}
]
// MENSAJES
const messages = [
{content: "Hola Jordan, mi nombre es eddy", user_id: 0, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23", is_read: 0, conversationId: 1, userId: 1},
{content: "Hola Jordan, Como te va sigo siendo eddy", user_id: 0, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23", is_read: 1, conversationId: 1, userId: 1},
{content: "Hola Eddy, mi nombre es jordan", user_id: 0, created_at: "2021-12-26 21:47:23", updated_at: "2021-12-26 21:47:23", is_read: 0, conversationId: 2, userId: 2}
];
// COMENTARIOS
const comments = [
// Jordan a comenta a la publicacion de Eddy.
//{ type_id: 0, ref_id: 0, user_id: 0, content: "Hola eddy", comment_id: 0, created_at: "2021-12-26 20:47:23", updated_at: "2021-12-26 20:47:23", postId: 1, userId: 2, commentId: 1 },
//{ type_id: 0, ref_id: 0, user_id: 0, content: "Esta chevere tu foto", comment_id: 0, created_at: "2021-12-26 20:47:23", updated_at: "2021-12-26 20:47:23", postId: 1, userId: 2, commentId: 2 },
//{ type_id: 0, ref_id: 0, user_id: 0, content: "Hola Eddy soy Paola", comment_id: 0, created_at: "2021-12-26 20:47:23", updated_at: "2021-12-26 20:47:23", postId: 1, userId: 4, commentId: 3 },
//{ type_id: 0, ref_id: 0, user_id: 0, content: "Hola Eddy soy Paola", comment_id: 0, created_at: "2021-12-26 20:47:23", updated_at: "2021-12-26 20:47:23", postId: 2, userId: 4, commentId: 4 }
];
// LIKES
const likes = [
{ type_id: 10, ref_id: 1, user_id: 1, created_at: "2021-12-26 20:47:23", updated_at: "2021-12-26 20:47:23"},
{ type_id: 10, ref_id: 1, user_id: 2, created_at: "2021-12-26 20:47:23", updated_at: "2021-12-26 20:47:23"},
{ type_id: 10, ref_id: 1, user_id: 3, created_at: "2021-12-26 20:47:23", updated_at: "2021-12-26 20:47:23"},
{ type_id: 10, ref_id: 1, user_id: 1, created_at: "2021-12-26 20:47:23", updated_at: "2021-12-26 20:47:23"},
];
// AUTENTICACIÓN
// EN ESTE PUNTO SE CONECTARÁ A LA BASE DE DATOS.
// FOCE TRUE: DROP TABLES
sequelize.sync({ force: true })
.then(() => {
console.log("[ DATABASE ] => La conexion a la base de datos redsocial se ha realizado correctamente!");
})
.then(() => {
// Rellenar usuarios
users.forEach((user) => User.create(user));
})
.then(() => {
// Rellenar profiles
profiles.forEach((profile) => Profile.create(profile));
})
.then(() => {
// Rellenar posts
//posts.forEach((post) => Post.create(post));
})
.then(() =>{
// Rellenar images
images.forEach((image) => Image.create(image));
})
.then(() =>{
follows.forEach((follow) => Follow.create(follow));
})
.then(() =>{
conversations.forEach((conversation) => Conversation.create(conversation));
})
.then(() => {
messages.forEach((message) => Message.create(message) );
})
.then(() => {
comments.forEach((comment) => Comment.create(comment) );
})
.then(async () => {
let post1 = await Post.create(
{title: "",content: "Publicacion 1 de Eddy con 1 sola imagen, haciendo pruebas para ver como se ve en el entorno de desarrollo y espero que les guste a todos.",lat: 0,lng: 0,start_at: "2021-12-26 21:47:23",finish_at: "2021-12-26 21:47:23",receptor_type_id: 0,author_ref_id: 1,receptor_ref_id: 0,level_id: 0,post_type_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 1,
images: [{src: "public/posts/imag-02.jpg",title: "imag-02.jpg",content: "69f",user_id: 1,level_id: 0,album_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23", userId:1 }],
},
{include: [{model: Image,},],}
);
let post2 = await Post.create(
{title: "",content: "Publicacion 2 de Eddy con 2 imagenes, haciendo pruebas para ver como se ve en el entorno de desarrollo y espero que les guste a todos.",lat: 0,lng: 0,start_at: "2021-12-26 21:47:23",finish_at: "2021-12-26 21:47:23",receptor_type_id: 0,author_ref_id: 1,receptor_ref_id: 0,level_id: 0,post_type_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 1,
images: [
{src: "public/posts/imag-03.jpg",title: "imag-03.jpg",content: "32b",user_id: 1,level_id: 0,album_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId:1},
{src: "public/posts/imag-04.jpg",title: "imag-04.jpg",content: "b02",user_id: 1,level_id: 0,album_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId:1}],
},
{include: [{model: Image,},],}
);
let post3 = await Post.create(
{title: "",content: "Publicacion 3 de Eddy con 1 imagen, haciendo pruebas para ver como se ve en el entorno de desarrollo y espero que les guste a todos.",lat: 0,lng: 0,start_at: "2021-12-26 21:47:23",finish_at: "2021-12-26 21:47:23",receptor_type_id: 0,author_ref_id: 1,receptor_ref_id: 0,level_id: 0,post_type_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 1,
images: [{src: "public/posts/imag-05.jpg",title: "imag-05.jpg",content: "32b", user_id: 1,level_id: 0,album_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId:1}],
},
{include: [{model: Image,},],}
);
let post4 = await Post.create(
{title: "",content: "Publicacion 4 de Eddy con 1 imagen, haciendo pruebas para ver como se ve en el entorno de desarrollo y espero que les guste a todos.",lat: 0,lng: 0,start_at: "2021-12-26 21:47:23",finish_at: "2021-12-26 21:47:23",receptor_type_id: 0,author_ref_id: 1,receptor_ref_id: 0,level_id: 0,post_type_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 1,
images: [{src: "public/posts/imag-06.jpg",title: "imag-06.jpg",content: "32b",user_id: 1,level_id: 0,album_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId:1}],
},
{include: [{model: Image,},],}
);
let post5 = await Post.create(
{title: "",content: "Publicacion 5 xxx.",lat: 0,lng: 0,start_at: "2021-12-26 21:47:23",finish_at: "2021-12-26 21:47:23",receptor_type_id: 0,author_ref_id: 2,receptor_ref_id: 0,level_id: 0,post_type_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 2,
images: [{src: "public/posts/imag-06.jpg",title: "imag-06.jpg",content: "32b",user_id: 2,level_id: 0,album_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId:2}],
},
{include: [{model: Image,},],}
);
await Post.create(
{title: "",content: "Publicacion 5 xxx.",lat: 0,lng: 0,start_at: "2021-12-26 21:47:23",finish_at: "2021-12-26 21:47:23",receptor_type_id: 0,author_ref_id: 1,receptor_ref_id: 0,level_id: 0,post_type_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 1,
images: [{src: "public/posts/imag-06.jpg",title: "imag-06.jpg",content: "32b",user_id: 1,level_id: 0,album_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId:1}],
},
{include: [{model: Image,},],}
);
await Post.create(
{title: "",content: "Publicacion 5 xxx.",lat: 0,lng: 0,start_at: "2021-12-26 21:47:23",finish_at: "2021-12-26 21:47:23",receptor_type_id: 0,author_ref_id: 1,receptor_ref_id: 0,level_id: 0,post_type_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 1,
images: [{src: "public/posts/imag-06.jpg",title: "imag-06.jpg",content: "32b",user_id: 1,level_id: 0,album_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId:1}],
},
{include: [{model: Image,},],}
);
await Post.create(
{title: "",content: "Publicacion 5 xxx.",lat: 0,lng: 0,start_at: "2021-12-26 21:47:23",finish_at: "2021-12-26 21:47:23",receptor_type_id: 0,author_ref_id: 1,receptor_ref_id: 0,level_id: 0,post_type_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 1,
images: [{src: "public/posts/imag-06.jpg",title: "imag-06.jpg",content: "32b",user_id: 1,level_id: 0,album_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId:1}],
},
{include: [{model: Image,},],}
);
await Post.create(
{title: "",content: "Publicacion 5 xxx.",lat: 0,lng: 0,start_at: "2021-12-26 21:47:23",finish_at: "2021-12-26 21:47:23",receptor_type_id: 0,author_ref_id: 1,receptor_ref_id: 0,level_id: 0,post_type_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 1,
images: [{src: "public/posts/imag-06.jpg",title: "imag-06.jpg",content: "32b",user_id: 1,level_id: 0,album_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId:1}],
},
{include: [{model: Image,},],}
);
await Post.create(
{title: "",content: "Publicacion 5 xxx.",lat: 0,lng: 0,start_at: "2021-12-26 21:47:23",finish_at: "2021-12-26 21:47:23",receptor_type_id: 0,author_ref_id: 1,receptor_ref_id: 0,level_id: 0,post_type_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 1,
images: [{src: "public/posts/imag-06.jpg",title: "imag-06.jpg",content: "32b",user_id: 1,level_id: 0,album_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId:1}],
},
{include: [{model: Image,},],}
);
await Post.create(
{title: "",content: "Publicacion 5 xxx.",lat: 0,lng: 0,start_at: "2021-12-26 21:47:23",finish_at: "2021-12-26 21:47:23",receptor_type_id: 0,author_ref_id: 2,receptor_ref_id: 0,level_id: 0,post_type_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId: 1,
images: [{src: "public/posts/imag-06.jpg",title: "imag-06.jpg",content: "32b",user_id: 1,level_id: 0,album_id: 0,created_at: "2021-12-26 21:47:23",updated_at: "2021-12-26 21:47:23",userId:1}],
},
{include: [{model: Image,},],}
);
})
.then(() => {
likes.forEach((likes) => Heart.create( likes ) );
})
.catch((err) => {
console.log("No se conecto a la Base de datos.");
});
// 1a1
// Usuario tiene un Profile
// Añadir una clave forenea userId a la tabla Profile
User.hasOne(Profile);
// Añade una clave userId a la table Profile
Profile.belongsTo(User);
// 1aN
// Uno a muchos, 1 a N
// Un usuario tiene muchos posts
// Se añade una clave usrId a la tabla Posts
User.hasMany(Post);
// Se añade una clave userId a la tabla Posts
Post.belongsTo(User);
// sercicios sociales ayuntamiento
// NaN
// Un post pertenece o tiene varias imagenes
// Esto es crear una nueva tabla en la base de datos llamada post_image
// post.addImage post.getImage... etc
Post.belongsToMany(Image, { through: PostImage});
Image.belongsToMany(Post, { through: PostImage});
PostImage.belongsTo(Post);
PostImage.belongsTo(Image);
//1aN
User.hasMany(Image);
Image.belongsTo(User);
// Follow
// 1aN
// Un usuario va a tener muchos seguidores o seguidos
// Se agrega dos claves ("followed_id", "user_id") a la tabla Follow
User.hasMany(Follow, { foreignKey: "followed_id" });
User.hasMany(Follow, { foreignKey: "user_id" });
// Se añade dos claves ("followed_id", "user_id") a la tabla Follow
Follow.belongsTo(User, { foreignKey: "followed_id" });
Follow.belongsTo(User, { foreignKey: "user_id" });
// 1aN
// Una conversación tiene muchos mensajes
Conversation.hasMany(Message);
// Se añade una clave conversationId a la table Message
Message.belongsTo(Conversation);
// 1aN
User.hasMany(Message);
// Se añade una clave userId en la tabla Message
Message.belongsTo(User);
// 1aN
// Un usuario puede tener muchas conversaciones
User.hasMany(Conversation, {foreignKey: 'sender_id'});
User.hasMany(Conversation, {foreignKey: 'receptor_id'});
// Se añade clave a la table Conversation
Conversation.belongsTo(User, {foreignKey: 'sender_id'});
Conversation.belongsTo(User, {foreignKey: 'receptor_id'});
// 1aN
// Un post tiene muchos comentarios.
// Un usuario tiene muchos comentarios.
// Un comentario puede tener otro comentario (Se guarda el id del comentario superior).
Post.hasMany(Comment);
User.hasMany(Comment);
Comment.hasMany(Comment);
// Se añade una clave postId a la tabla Comment
// Se añade una clave userId a la tabla Comment
// Se añade una clave commentId a la tabla Comment
Comment.belongsTo(Post)
Comment.belongsTo(User);
Comment.belongsTo(Comment);
// LIKE
Post.hasMany(Heart, {foreignKey: 'ref_id'});
User.hasMany(Heart, {foreignKey: 'user_id'});
//Comment.hasMany(Heart, {foreignKey: 'ref_id'});
//Post.hasMany(Heart, {foreignKey: 'ref_id'});
Heart.belongsTo(Post, {foreignKey: 'ref_id'})
Heart.belongsTo(User, {foreignKey: 'user_id'})
//Heart.belongsTo(Post, {foreignKey: 'ref_id'})
// EXPORTACION
module.exports = {
Profile,
Post,
User,
Image,
Follow,
Conversation,
Message,
Comment,
Heart,
PostImage
};