mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Fixed more factories
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
b7f45d2ae2
commit
b30bbe1740
|
@ -9,140 +9,14 @@ use App\Models\Location;
|
|||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
$factory->defineAs(App\Models\Actionlog::class, 'asset-upload', function ($faker) {
|
||||
$asset = \App\Models\Asset::factory()->create();
|
||||
|
||||
return [
|
||||
'item_type' => get_class($asset),
|
||||
'item_id' => 1,
|
||||
'user_id' => 1,
|
||||
'filename' => $faker->word,
|
||||
'action_type' => 'uploaded',
|
||||
];
|
||||
});
|
||||
|
||||
$factory->defineAs(Actionlog::class, 'asset-checkout-user', function (Faker\Generator $faker) {
|
||||
$target = User::inRandomOrder()->first();
|
||||
$item = Asset::inRandomOrder()->RTD()->first();
|
||||
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
||||
$asset = App\Models\Asset::where('id', $item->id)
|
||||
->update(
|
||||
[
|
||||
'assigned_to' => $target->id,
|
||||
'assigned_type' => App\Models\User::class,
|
||||
'assigned_to' => $target->location_id,
|
||||
]
|
||||
);
|
||||
|
||||
return [
|
||||
'created_at' => $faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
||||
'user_id' => $user_id,
|
||||
'action_type' => 'checkout',
|
||||
'item_id' => $item->id,
|
||||
'item_type' => App\Models\Asset::class,
|
||||
'target_id' => $target->id,
|
||||
'target_type' => get_class($target),
|
||||
|
||||
];
|
||||
});
|
||||
|
||||
$factory->defineAs(Actionlog::class, 'asset-checkout-location', function (Faker\Generator $faker) {
|
||||
$target = Location::inRandomOrder()->first();
|
||||
$item = Asset::inRandomOrder()->RTD()->first();
|
||||
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
||||
$asset = App\Models\Asset::where('id', $item->id)
|
||||
->update(
|
||||
[
|
||||
'assigned_to' => $target->id,
|
||||
'assigned_type' => App\Models\Location::class,
|
||||
'assigned_to' => $target->id,
|
||||
]
|
||||
);
|
||||
|
||||
return [
|
||||
'created_at' => $faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
||||
'user_id' => $user_id,
|
||||
'action_type' => 'checkout',
|
||||
'item_id' => $item->id,
|
||||
'item_type' => App\Models\Asset::class,
|
||||
'target_id' => $target->id,
|
||||
'target_type' => get_class($target),
|
||||
];
|
||||
});
|
||||
|
||||
// This doesn't work - we need to assign a seat
|
||||
|
||||
$factory->defineAs(Actionlog::class, 'license-checkout-asset', function (Faker\Generator $faker) {
|
||||
$target = Asset::inRandomOrder()->RTD()->first();
|
||||
$item = License::inRandomOrder()->first();
|
||||
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
||||
|
||||
return [
|
||||
'user_id' => $user_id,
|
||||
'action_type' => 'checkout',
|
||||
'item_id' => $item->id,
|
||||
'item_type' => get_class($item),
|
||||
'target_id' => $target->id,
|
||||
'target_type' => get_class($target),
|
||||
'created_at' => $faker->dateTime(),
|
||||
'note' => $faker->sentence,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->defineAs(Actionlog::class, 'accessory-checkout', function (Faker\Generator $faker) {
|
||||
$target = Asset::inRandomOrder()->RTD()->first();
|
||||
$item = Accessory::inRandomOrder()->first();
|
||||
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
||||
|
||||
return [
|
||||
'user_id' => $user_id,
|
||||
'action_type' => 'checkout',
|
||||
'item_id' => $item->id,
|
||||
'item_type' => get_class($item),
|
||||
'target_id' => $target->id,
|
||||
'target_type' => get_class($target),
|
||||
'created_at' => $faker->dateTime(),
|
||||
'note' => $faker->sentence,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->defineAs(Actionlog::class, 'consumable-checkout', function (Faker\Generator $faker) {
|
||||
$company = \App\Models\Company::factory()->create();
|
||||
$user = \App\Models\User::factory()->create(['company_id' => $company->id]);
|
||||
$target = \App\Models\User::factory()->create(['company_id' => $company->id]);
|
||||
$item = \App\Models\Consumable::factory()->create(['company_id' => $company->id]);
|
||||
|
||||
return [
|
||||
'user_id' => $user->id,
|
||||
'action_type' => 'checkout',
|
||||
'item_id' => $item->id,
|
||||
'item_type' => get_class($item),
|
||||
'target_id' => $target->id,
|
||||
'target_type' => get_class($target),
|
||||
'created_at' => $faker->dateTime(),
|
||||
'note' => $faker->sentence,
|
||||
'company_id' => $company->id,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->defineAs(Actionlog::class, 'component-checkout', function (Faker\Generator $faker) {
|
||||
$company = \App\Models\Company::factory()->create();
|
||||
$user = \App\Models\User::factory()->create(['company_id' => $company->id]);
|
||||
$target = \App\Models\User::factory()->create(['company_id' => $company->id]);
|
||||
$item = \App\Models\Component::factory()->create(['company_id' => $company->id]);
|
||||
|
||||
return [
|
||||
'user_id' => $user->id,
|
||||
'action_type' => 'checkout',
|
||||
'item_id' => $item->id,
|
||||
'item_type' => get_class($item),
|
||||
'target_id' => $target->id,
|
||||
'target_type' => get_class($target),
|
||||
'created_at' => $faker->dateTime(),
|
||||
'note' => $faker->sentence,
|
||||
'company_id' => $company->id,
|
||||
];
|
||||
});
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Action Log Factories
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This simulates checkin/checkout/etc activities
|
||||
|
|
||||
*/
|
||||
|
||||
class ActionlogFactory extends Factory
|
||||
{
|
||||
|
@ -151,7 +25,7 @@ class ActionlogFactory extends Factory
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Actionlog::class;
|
||||
protected $model = \App\Models\Actionlog::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
|
@ -160,8 +34,72 @@ class ActionlogFactory extends Factory
|
|||
*/
|
||||
public function definition()
|
||||
{
|
||||
$asset = \App\Models\Asset::factory()->create();
|
||||
return [
|
||||
'note' => 'Sample checkout from DB seeder!',
|
||||
'item_type' => get_class($asset),
|
||||
'item_id' => 1,
|
||||
'user_id' => 1,
|
||||
'filename' => $this->faker->word,
|
||||
'action_type' => 'uploaded',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function assetCheckoutToUser()
|
||||
{
|
||||
return $this->state(function () {
|
||||
$target = \App\Models\User::inRandomOrder()->first();
|
||||
$item = \App\Models\Asset::inRandomOrder()->RTD()->first();
|
||||
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
||||
$asset = Asset::where('id', $item->id)
|
||||
->update(
|
||||
[
|
||||
'assigned_to' => $target->id,
|
||||
'assigned_type' => \App\Models\User::class,
|
||||
'assigned_to' => $target->location_id,
|
||||
]
|
||||
);
|
||||
|
||||
return [
|
||||
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
||||
'user_id' => $user_id,
|
||||
'action_type' => 'checkout',
|
||||
'item_id' => $item->id,
|
||||
'item_type' => \App\Models\Asset::class,
|
||||
'target_id' => $target->id,
|
||||
'target_type' => get_class($target),
|
||||
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public function assetCheckoutToLocation()
|
||||
{
|
||||
return $this->state(function () {
|
||||
$target = \App\Models\Location::inRandomOrder()->first();
|
||||
$item = \App\Models\Asset::inRandomOrder()->RTD()->first();
|
||||
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
||||
$asset = \App\Models\Asset::where('id', $item->id)
|
||||
->update(
|
||||
[
|
||||
'assigned_to' => $target->id,
|
||||
'assigned_type' => \App\Models\Location::class,
|
||||
'assigned_to' => $target->id,
|
||||
]
|
||||
);
|
||||
|
||||
return [
|
||||
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
||||
'user_id' => $user_id,
|
||||
'action_type' => 'checkout',
|
||||
'item_id' => $item->id,
|
||||
'item_type' => \App\Models\Asset::class,
|
||||
'target_id' => $target->id,
|
||||
'target_type' => get_class($target),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ class AssetFactory extends Factory
|
|||
return [
|
||||
'model_id' => 1,
|
||||
'assigned_to' => \App\Models\User::factory()->create()->id,
|
||||
'assigned_type' => App\Models\User::class,
|
||||
'assigned_type' => \App\Models\User::class,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ class AssetFactory extends Factory
|
|||
return [
|
||||
'model_id' => 1,
|
||||
'assigned_to' => \App\Models\Location::factory()->create()->id,
|
||||
'assigned_type' => App\Models\Location::class,
|
||||
'assigned_type' => \App\Models\Location::class,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ class AssetFactory extends Factory
|
|||
return [
|
||||
'model_id' => 1,
|
||||
'assigned_to' => \App\Models\Asset::factory()->create()->id,
|
||||
'assigned_type' => App\Models\Asset::class,
|
||||
'assigned_type' => \App\Models\Asset::class,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
|
|
@ -30,12 +30,20 @@ class ComponentFactory extends Factory
|
|||
public function definition()
|
||||
{
|
||||
return [
|
||||
'user_id' => 1,
|
||||
'name' => $this->faker->text(20),
|
||||
'category_id' => function () {
|
||||
return \App\Models\Category::factory()->create()->id;
|
||||
},
|
||||
'location_id' => 1,
|
||||
'serial' => $this->faker->uuid,
|
||||
'qty' => $this->faker->numberBetween(3, 10),
|
||||
'order_number' => $this->faker->numberBetween(1000000, 50000000),
|
||||
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
||||
'purchase_cost' => $this->faker->randomFloat(2, 1, 50),
|
||||
'qty' => $this->faker->numberBetween(5, 10),
|
||||
'purchase_date' => $this->faker->dateTime(),
|
||||
'purchase_cost' => $this->faker->randomFloat(2),
|
||||
'min_amt' => $this->faker->numberBetween($min = 1, $max = 2),
|
||||
'company_id' => function () {
|
||||
return \App\Models\Company::factory()->create()->id;
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -89,28 +97,5 @@ class ComponentFactory extends Factory
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->text(20),
|
||||
'category_id' => function () {
|
||||
return \App\Models\Category::factory()->create()->id;
|
||||
},
|
||||
'location_id' => 1,
|
||||
'serial' => $this->faker->uuid,
|
||||
'qty' => $this->faker->numberBetween(3, 10),
|
||||
'order_number' => $this->faker->numberBetween(1000000, 50000000),
|
||||
'purchase_date' => $this->faker->dateTime(),
|
||||
'purchase_cost' => $this->faker->randomFloat(2),
|
||||
'min_amt' => $this->faker->numberBetween($min = 1, $max = 2),
|
||||
'company_id' => function () {
|
||||
return \App\Models\Company::factory()->create()->id;
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,21 +5,6 @@ namespace Database\Factories;
|
|||
use App\Models\Company;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
$password = bcrypt('password');
|
||||
|
||||
// USER GLOBAL PERMISSION STATES
|
||||
|
||||
// USER ASSET PERMISSION STATES
|
||||
|
||||
// USER ACCESSORY PERMISSION STATES
|
||||
|
||||
// USER CONSUMABLE PERMISSION STATES
|
||||
|
||||
// USER LICENSE PERMISSION STATES
|
||||
|
||||
// USER COMPONENTS PERMISSION STATES
|
||||
|
||||
// USER USER PERMISSION STATES
|
||||
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
|
@ -37,6 +22,7 @@ class UserFactory extends Factory
|
|||
*/
|
||||
public function definition()
|
||||
{
|
||||
$password = bcrypt('password');
|
||||
return [
|
||||
'activated' => 1,
|
||||
'address' => $this->faker->address,
|
||||
|
|
|
@ -10,7 +10,9 @@ class ActionlogSeeder extends Seeder
|
|||
public function run()
|
||||
{
|
||||
Actionlog::truncate();
|
||||
Actionlog::factory()->count('asset-checkout-user', 300)->create();
|
||||
Actionlog::factory()->count('asset-checkout-location', 100)->create();
|
||||
Actionlog::factory()->count(300)->assetCheckoutToUser()->create();
|
||||
Actionlog::factory()->count(100)->assetCheckoutToLocation()->create();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue