From d2eb7cf3378511770af6b4817d463364c7bd52be Mon Sep 17 00:00:00 2001 From: Gregor Vostrak Date: Sun, 21 Jan 2024 23:59:29 +0100 Subject: [PATCH 1/4] publish custom token and notification models --- app/Models/Notification.php | 11 +++++++++++ app/Models/Token.php | 11 +++++++++++ app/Models/User.php | 10 ++++++++++ app/Providers/AuthServiceProvider.php | 3 +++ resources/js/types/models.ts | 23 +++++++++++++++++++++++ 5 files changed, 58 insertions(+) create mode 100644 app/Models/Notification.php create mode 100644 app/Models/Token.php 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/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[]; From 6e88e083c15b2f8e8a459d5c501de5f63b6e27e4 Mon Sep 17 00:00:00 2001 From: Gregor Vostrak Date: Mon, 22 Jan 2024 00:27:30 +0100 Subject: [PATCH 2/4] add check typescript generated github action --- .../workflows/check-typescript-generated.yml | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/check-typescript-generated.yml diff --git a/.github/workflows/check-typescript-generated.yml b/.github/workflows/check-typescript-generated.yml new file mode 100644 index 00000000..5f13a8dd --- /dev/null +++ b/.github/workflows/check-typescript-generated.yml @@ -0,0 +1,29 @@ +name: NPM Build + +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: npm run lint:fix + - run: composer generate-typescript + - 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 From 459b63e6ed6bf012d570db60a8aebd3d408c5d6c Mon Sep 17 00:00:00 2001 From: Gregor Vostrak Date: Mon, 22 Jan 2024 00:32:59 +0100 Subject: [PATCH 3/4] fix composer script error code --- .github/workflows/check-typescript-generated.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-typescript-generated.yml b/.github/workflows/check-typescript-generated.yml index 5f13a8dd..b8eaf5fa 100644 --- a/.github/workflows/check-typescript-generated.yml +++ b/.github/workflows/check-typescript-generated.yml @@ -17,8 +17,8 @@ jobs: with: node-version: '20.x' - run: npm ci - - run: npm run lint:fix - run: composer generate-typescript + - run: npm run lint:fix - name: Verify Changed files uses: tj-actions/verify-changed-files@v17 id: verify-changed-files 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" From f365721b7235b84c9c294f36d74af3633659c57d Mon Sep 17 00:00:00 2001 From: Gregor Vostrak Date: Mon, 22 Jan 2024 00:41:31 +0100 Subject: [PATCH 4/4] fix action name --- .github/workflows/check-typescript-generated.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-typescript-generated.yml b/.github/workflows/check-typescript-generated.yml index b8eaf5fa..f9a83135 100644 --- a/.github/workflows/check-typescript-generated.yml +++ b/.github/workflows/check-typescript-generated.yml @@ -1,4 +1,4 @@ -name: NPM Build +name: Check Typescript Generated on: [push] @@ -18,6 +18,7 @@ jobs: 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