1
- const mongoose = require ( ' mongoose' ) ;
2
- const ObjectModel = require ( ' ../models/object.model' ) ;
3
- const Discipline = require ( ' ../models/discipline.model' ) ;
4
- const User = require ( ' ../models/user.model' ) ;
1
+ const mongoose = require ( " mongoose" ) ;
2
+ const ObjectModel = require ( " ../models/object.model" ) ;
3
+ const Discipline = require ( " ../models/discipline.model" ) ;
4
+ const User = require ( " ../models/user.model" ) ;
5
5
6
6
const seedObjects = async ( ) => {
7
7
try {
8
8
const disciplines = await Discipline . find ( { } ) ;
9
- const users = await User . find ( { role : 'user' } ) ;
10
- const admins = await User . find ( { role : 'admin' } ) ;
11
-
9
+ const users = await User . find ( { role : "user" } ) ;
10
+ const admins = await User . find ( { role : "admin" } ) ;
12
11
if ( disciplines . length === 0 || users . length === 0 ) {
13
- console . log ( 'Ensure that disciplines and users are seeded before seeding objects.' ) ;
12
+ console . log (
13
+ "Ensure that disciplines and users are seeded before seeding objects."
14
+ ) ;
14
15
return ;
15
16
}
16
-
17
17
const objects = [
18
18
{
19
- name : ' Cien Años de Soledad' ,
20
- description : ' Una novela clásica de Gabriel García Márquez.' ,
21
- imageUrl : ' public/images/objects/cien_años.jpg' ,
22
- discipline : disciplines . find ( d => d . name === ' Libros' ) . _id ,
19
+ name : " Cien Años de Soledad" ,
20
+ description : " Una novela clásica de Gabriel García Márquez." ,
21
+ imageUrl : " public/images/objects/cien_años.jpg" ,
22
+ discipline : disciplines . find ( ( d ) => d . name === " Libros" ) . _id ,
23
23
createdBy : users [ 0 ] . _id ,
24
24
} ,
25
25
{
26
- name : ' Bohemian Rhapsody' ,
27
- description : ' Canción icónica de Queen.' ,
28
- imageUrl : ' public/images/objects/bohemian_rhapsody.jpg' ,
29
- discipline : disciplines . find ( d => d . name === ' Canciones' ) . _id ,
26
+ name : " Bohemian Rhapsody" ,
27
+ description : " Canción icónica de Queen." ,
28
+ imageUrl : " public/images/objects/bohemian_rhapsody.jpg" ,
29
+ discipline : disciplines . find ( ( d ) => d . name === " Canciones" ) . _id ,
30
30
createdBy : users [ 1 ] . _id ,
31
31
} ,
32
32
{
33
- name : ' The Legend of Zelda' ,
34
- description : ' Un famoso videojuego de aventura.' ,
35
- imageUrl : ' public/images/objects/zelda.jpg' ,
36
- discipline : disciplines . find ( d => d . name === ' Videojuegos' ) . _id ,
33
+ name : " The Legend of Zelda" ,
34
+ description : " Un famoso videojuego de aventura." ,
35
+ imageUrl : " public/images/objects/zelda.jpg" ,
36
+ discipline : disciplines . find ( ( d ) => d . name === " Videojuegos" ) . _id ,
37
37
createdBy : users [ 0 ] . _id ,
38
38
} ,
39
39
{
40
- name : ' The Legend of Zelda 2' ,
41
- description : ' Un famoso videojuego de aventura.' ,
42
- imageUrl : ' public/images/objects/zelda.jpg' ,
43
- discipline : disciplines . find ( d => d . name === ' Videojuegos' ) . _id ,
40
+ name : " The Legend of Zelda 2" ,
41
+ description : " Un famoso videojuego de aventura." ,
42
+ imageUrl : " public/images/objects/zelda.jpg" ,
43
+ discipline : disciplines . find ( ( d ) => d . name === " Videojuegos" ) . _id ,
44
44
createdBy : admins [ 0 ] . _id ,
45
45
} ,
46
46
{
47
- name : ' The Legend of Zelda 3' ,
48
- description : ' Un famoso videojuego de aventura.' ,
49
- imageUrl : ' public/images/objects/zelda.jpg' ,
50
- discipline : disciplines . find ( d => d . name === ' Videojuegos' ) . _id ,
47
+ name : " The Legend of Zelda 3" ,
48
+ description : " Un famoso videojuego de aventura." ,
49
+ imageUrl : " public/images/objects/zelda.jpg" ,
50
+ discipline : disciplines . find ( ( d ) => d . name === " Videojuegos" ) . _id ,
51
51
createdBy : admins [ 1 ] . _id ,
52
52
} ,
53
53
] ;
54
-
55
54
for ( const objectData of objects ) {
56
55
const exist = await ObjectModel . findOne ( { name : objectData . name } ) ;
57
56
if ( ! exist ) {
@@ -61,9 +60,9 @@ const seedObjects = async () => {
61
60
console . log ( `Object ${ objectData . name } already exists` ) ;
62
61
}
63
62
}
64
- console . log ( ' Objects seeded successfully' ) ;
63
+ console . log ( " Objects seeded successfully" ) ;
65
64
} catch ( error ) {
66
- console . error ( ' Error seeding objects:' , error ) ;
65
+ console . error ( " Error seeding objects:" , error ) ;
67
66
process . exit ( 1 ) ;
68
67
}
69
68
} ;
0 commit comments