Skip to content

Commit

Permalink
fix: seeder necessary limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Leoglme committed Jan 16, 2024
1 parent af36b9a commit 7959124
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions api/database/seeders/01_FakeDatas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<User> = 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<Location> = 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<UserLocation> = 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<Search> = await Search.all()
if (existingSearches.length < maxSearches) {
// 10 users
const createdUsers: Array<User> = await User.all()
const tenUsers: Array<User> = createdUsers.slice(0, 10)

await addUsersToSearches(createdSearches, createdUsers)

await addPropertiesToSearches(createdSearches)
// 10 searches
const createdSearches: Array<Search> = await Search.all()
const tenSearches: Array<Search> = createdSearches.slice(0, 10)
const searches = await generateSearches(maxSearches, tenUsers)
await Search.createMany(searches)
await addUsersToSearches(tenSearches, createdUsers)
await addPropertiesToSearches(tenSearches)
}
}
}

0 comments on commit 7959124

Please sign in to comment.