diff --git a/.github/workflows/check-typescript-generated.yml b/.github/workflows/check-typescript-generated.yml new file mode 100644 index 00000000..f9a83135 --- /dev/null +++ b/.github/workflows/check-typescript-generated.yml @@ -0,0 +1,30 @@ +name: Check Typescript Generated + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.3.1' + extensions: intl, zip + - run: composer install + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '20.x' + - run: npm ci + - run: composer generate-typescript + - run: cat resources/js/types/models.ts + - run: npm run lint:fix + - name: Verify Changed files + uses: tj-actions/verify-changed-files@v17 + id: verify-changed-files + with: + fail-if-changed: true + fail-message: 'The models.ts file is not up to date. Please run `composer generate-typescript` locally and commit the changes.' + files: | + resources/js/types/models.ts diff --git a/app/Models/Notification.php b/app/Models/Notification.php new file mode 100644 index 00000000..25ea883b --- /dev/null +++ b/app/Models/Notification.php @@ -0,0 +1,11 @@ +withTimestamps() ->as('membership'); } + + /** + * @return MorphMany + */ + public function notifications(): MorphMany + { + return $this->morphMany(Notification::class, 'notifiable')->latest(); + } } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index e7a414c9..2cb4e969 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -5,6 +5,7 @@ namespace App\Providers; use App\Models\Organization; +use App\Models\Token; use App\Policies\OrganizationPolicy; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Laravel\Jetstream\Jetstream; @@ -47,5 +48,7 @@ public function boot(): void // use passport scopes for jetstream token permissions Jetstream::permissions(Passport::scopeIds()); + + Passport::useTokenModel(Token::class); } } diff --git a/composer.json b/composer.json index 7c5b2894..ce3a607c 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "@php ./vendor/bin/phpstan analyse --memory-limit=2G --configuration=phpstan.neon" ], "generate-typescript": [ - "@php artisan model:typer > ./resources/js/types/models.ts" + "@php artisan model:typer > ./resources/js/types/models.ts || true" ], "ptest": [ "@php artisan test --parallel --colors=always --stop-on-failure" diff --git a/resources/js/types/models.ts b/resources/js/types/models.ts index 08fa5d7e..889a62db 100644 --- a/resources/js/types/models.ts +++ b/resources/js/types/models.ts @@ -19,6 +19,11 @@ export interface Membership { updated_at: string | null; } +export interface Notification { + // relations + notifiable: Notification; +} + export interface Organization { // columns id: string; @@ -106,6 +111,22 @@ export interface TimeEntry { task: Task; } +export interface Token { + // columns + id: string; + user_id: string | null; + client_id: string; + name: string | null; + scopes: string[] | null; + revoked: boolean; + created_at: string | null; + updated_at: string | null; + expires_at: string | null; + // relations + client: Client; + user: User; +} + export interface User { // columns id: string; @@ -125,7 +146,9 @@ export interface User { profile_photo_url: string; // relations organizations: Organization[]; + notifications: Notification[]; clients: Client[]; + tokens: Token[]; current_team: Organization; owned_teams: Organization[]; teams: Organization[];