Add superadmin moderation queues
This commit is contained in:
54
database/factories/TenantFeedbackFactory.php
Normal file
54
database/factories/TenantFeedbackFactory.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\TenantFeedback;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\TenantFeedback>
|
||||
*/
|
||||
class TenantFeedbackFactory extends Factory
|
||||
{
|
||||
protected $model = TenantFeedback::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'tenant_id' => Tenant::factory(),
|
||||
'event_id' => Event::factory(),
|
||||
'category' => $this->faker->randomElement(['bug', 'idea', 'praise', 'question']),
|
||||
'sentiment' => $this->faker->randomElement(['positive', 'neutral', 'negative']),
|
||||
'rating' => $this->faker->numberBetween(1, 5),
|
||||
'title' => $this->faker->sentence(4),
|
||||
'message' => $this->faker->paragraph(),
|
||||
'metadata' => ['source' => 'factory'],
|
||||
'status' => 'pending',
|
||||
];
|
||||
}
|
||||
|
||||
public function configure(): static
|
||||
{
|
||||
return $this->afterMaking(function (TenantFeedback $feedback) {
|
||||
if ($feedback->event && ! $feedback->tenant_id) {
|
||||
$feedback->tenant_id = $feedback->event->tenant_id;
|
||||
}
|
||||
})->afterCreating(function (TenantFeedback $feedback) {
|
||||
if ($feedback->event && ! $feedback->tenant_id) {
|
||||
$feedback->tenant_id = $feedback->event->tenant_id;
|
||||
$feedback->save();
|
||||
}
|
||||
|
||||
if ($feedback->event && $feedback->tenant_id && $feedback->event->tenant_id !== $feedback->tenant_id) {
|
||||
$feedback->event->update(['tenant_id' => $feedback->tenant_id]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('photos', function (Blueprint $table) {
|
||||
if (! Schema::hasColumn('photos', 'moderation_notes')) {
|
||||
$table->text('moderation_notes')->nullable()->after('status');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('photos', 'moderated_at')) {
|
||||
$table->timestamp('moderated_at')->nullable()->after('moderation_notes');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('photos', 'moderated_by')) {
|
||||
$table->foreignId('moderated_by')
|
||||
->nullable()
|
||||
->after('moderated_at')
|
||||
->constrained('users')
|
||||
->nullOnDelete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('photos', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('photos', 'moderated_by')) {
|
||||
$table->dropConstrainedForeignId('moderated_by');
|
||||
}
|
||||
|
||||
foreach (['moderated_at', 'moderation_notes'] as $column) {
|
||||
if (Schema::hasColumn('photos', $column)) {
|
||||
$table->dropColumn($column);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('tenant_feedback', function (Blueprint $table) {
|
||||
if (! Schema::hasColumn('tenant_feedback', 'status')) {
|
||||
$table->string('status', 32)->default('pending')->after('message');
|
||||
$table->index('status', 'tenant_feedback_status_index');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('tenant_feedback', 'moderation_notes')) {
|
||||
$table->text('moderation_notes')->nullable()->after('status');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('tenant_feedback', 'moderated_at')) {
|
||||
$table->timestamp('moderated_at')->nullable()->after('moderation_notes');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('tenant_feedback', 'moderated_by')) {
|
||||
$table->foreignId('moderated_by')
|
||||
->nullable()
|
||||
->after('moderated_at')
|
||||
->constrained('users')
|
||||
->nullOnDelete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('tenant_feedback', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('tenant_feedback', 'moderated_by')) {
|
||||
$table->dropConstrainedForeignId('moderated_by');
|
||||
}
|
||||
|
||||
foreach (['moderated_at', 'moderation_notes', 'status'] as $column) {
|
||||
if (Schema::hasColumn('tenant_feedback', $column)) {
|
||||
$table->dropColumn($column);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user