diff --git a/api/database/seeders/01_FakeDatas.ts b/api/database/seeders/01_FakeDatas.ts index e9b078f..46c0f9f 100644 --- a/api/database/seeders/01_FakeDatas.ts +++ b/api/database/seeders/01_FakeDatas.ts @@ -12,20 +12,45 @@ import UserLocation from 'App/Models/UserLocation' export default class FakeDatasSeeder extends BaseSeeder { public async run() { - const users = generateUsers(10) - const createdUsers = await User.createMany(users) + // Create users + const maxUsers: number = 10 + const existingUsers: Array = await User.all() + if (existingUsers.length < maxUsers) { + const users = generateUsers(maxUsers) + await User.createMany(users) + } - const locations = await generateLocations(20) - await Location.createMany(locations) + // Create locations + const maxLocations: number = 20 + const existingLocations: Array = await Location.all() + if (existingLocations.length < maxLocations) { + const locations = await generateLocations(maxLocations) + await Location.createMany(locations) + } - const userLocations = await generateUserLocations(10) - await UserLocation.createMany(userLocations) + // Create userLocations + const maxUserLocations: number = 10 + const existingUserLocations: Array = await UserLocation.all() + if (existingUserLocations.length < maxUserLocations) { + const userLocations = await generateUserLocations(maxUserLocations) + await UserLocation.createMany(userLocations) + } - const searches = await generateSearches(10, createdUsers) - const createdSearches = await Search.createMany(searches) + // Create searches + const maxSearches: number = 10 + const existingSearches: Array = await Search.all() + if (existingSearches.length < maxSearches) { + // 10 users + const createdUsers: Array = await User.all() + const tenUsers: Array = createdUsers.slice(0, 10) - await addUsersToSearches(createdSearches, createdUsers) - - await addPropertiesToSearches(createdSearches) + // 10 searches + const createdSearches: Array = await Search.all() + const tenSearches: Array = createdSearches.slice(0, 10) + const searches = await generateSearches(maxSearches, tenUsers) + await Search.createMany(searches) + await addUsersToSearches(tenSearches, createdUsers) + await addPropertiesToSearches(tenSearches) + } } }