@@ -12,20 +12,45 @@ import UserLocation from 'App/Models/UserLocation'
1212
1313export default class FakeDatasSeeder extends BaseSeeder {
1414 public async run ( ) {
15- const users = generateUsers ( 10 )
16- const createdUsers = await User . createMany ( users )
15+ // Create users
16+ const maxUsers : number = 10
17+ const existingUsers : Array < User > = await User . all ( )
18+ if ( existingUsers . length < maxUsers ) {
19+ const users = generateUsers ( maxUsers )
20+ await User . createMany ( users )
21+ }
1722
18- const locations = await generateLocations ( 20 )
19- await Location . createMany ( locations )
23+ // Create locations
24+ const maxLocations : number = 20
25+ const existingLocations : Array < Location > = await Location . all ( )
26+ if ( existingLocations . length < maxLocations ) {
27+ const locations = await generateLocations ( maxLocations )
28+ await Location . createMany ( locations )
29+ }
2030
21- const userLocations = await generateUserLocations ( 10 )
22- await UserLocation . createMany ( userLocations )
31+ // Create userLocations
32+ const maxUserLocations : number = 10
33+ const existingUserLocations : Array < UserLocation > = await UserLocation . all ( )
34+ if ( existingUserLocations . length < maxUserLocations ) {
35+ const userLocations = await generateUserLocations ( maxUserLocations )
36+ await UserLocation . createMany ( userLocations )
37+ }
2338
24- const searches = await generateSearches ( 10 , createdUsers )
25- const createdSearches = await Search . createMany ( searches )
39+ // Create searches
40+ const maxSearches : number = 10
41+ const existingSearches : Array < Search > = await Search . all ( )
42+ if ( existingSearches . length < maxSearches ) {
43+ // 10 users
44+ const createdUsers : Array < User > = await User . all ( )
45+ const tenUsers : Array < User > = createdUsers . slice ( 0 , 10 )
2646
27- await addUsersToSearches ( createdSearches , createdUsers )
28-
29- await addPropertiesToSearches ( createdSearches )
47+ // 10 searches
48+ const createdSearches : Array < Search > = await Search . all ( )
49+ const tenSearches : Array < Search > = createdSearches . slice ( 0 , 10 )
50+ const searches = await generateSearches ( maxSearches , tenUsers )
51+ await Search . createMany ( searches )
52+ await addUsersToSearches ( tenSearches , createdUsers )
53+ await addPropertiesToSearches ( tenSearches )
54+ }
3055 }
3156}
0 commit comments