From f57bc217e7623880f22db7fbd9af8eadfc145ea9 Mon Sep 17 00:00:00 2001 From: Tom Gobich Date: Sun, 22 Dec 2024 11:52:15 -0500 Subject: [PATCH] fixed: build issues --- app/actions/plans/destroy_plan.ts | 3 ++- app/actions/plans/get_paginated_plans.ts | 2 +- app/actions/posts/destroy_post.ts | 2 +- app/actions/users/update_user_role.ts | 2 +- app/controllers/collections_controller.ts | 7 +------ app/dtos/collection.ts | 4 ++-- app/dtos/post_form.ts | 8 -------- app/middleware/auth_middleware.ts | 6 +++++- app/models/plan.ts | 13 +++++++------ 9 files changed, 20 insertions(+), 27 deletions(-) diff --git a/app/actions/plans/destroy_plan.ts b/app/actions/plans/destroy_plan.ts index ea633a3..58cbaf5 100644 --- a/app/actions/plans/destroy_plan.ts +++ b/app/actions/plans/destroy_plan.ts @@ -1,5 +1,6 @@ import HttpStatus from '#enums/http_statuses' import Plan from '#models/plan' +import User from '#models/user' import { Exception } from '@adonisjs/core/exceptions' export default class DestroyPlan { @@ -13,7 +14,7 @@ export default class DestroyPlan { } static async #destroy(plan: Plan) { - const users = await plan.related('users').query().getCount() + const users = await User.query().where('planId', plan.id).getCount() if (Number(users) > 0) { throw new Exception( diff --git a/app/actions/plans/get_paginated_plans.ts b/app/actions/plans/get_paginated_plans.ts index 3e40d88..6dcb472 100644 --- a/app/actions/plans/get_paginated_plans.ts +++ b/app/actions/plans/get_paginated_plans.ts @@ -9,7 +9,7 @@ type Params = Infer export default class GetPaginatedPlans { static async handle({ page = 1, perPage = 25 }: Params) { return Plan.query() - .withCount('users', (query) => + .withCount<'users'>('users', (query) => query .where('planId', Plans.FOREVER) .orWhere('planId', Plans.FREE) diff --git a/app/actions/posts/destroy_post.ts b/app/actions/posts/destroy_post.ts index 0c23b31..6ca62fd 100644 --- a/app/actions/posts/destroy_post.ts +++ b/app/actions/posts/destroy_post.ts @@ -58,7 +58,7 @@ export default class DestroyPost { static async #destroyAssets(post: Post, trx: TransactionClientContract) { const assets = await post.related('assets').query().select(['id', 'filename']) const assetIds = assets.map((a) => a.id) - const unusedQuery = Asset.query() + const unusedQuery = Asset.query({ client: trx }) .whereIn('id', assetIds) .whereDoesntHave('collections', (query) => query) .whereDoesntHave('posts', (query) => query) diff --git a/app/actions/users/update_user_role.ts b/app/actions/users/update_user_role.ts index be6c876..7f653cd 100644 --- a/app/actions/users/update_user_role.ts +++ b/app/actions/users/update_user_role.ts @@ -14,7 +14,7 @@ export default class UpdateUserRole { } static async #updateRole(user: User, data: Data) { - const oldRole = await user.related('role').query().firstOrFail() + const oldRole = await user.related<'role'>('role').query().firstOrFail() const newRole = await Role.findOrFail(data.roleId) await user.merge(data).save() diff --git a/app/controllers/collections_controller.ts b/app/controllers/collections_controller.ts index 084f92f..bcc4fcd 100644 --- a/app/controllers/collections_controller.ts +++ b/app/controllers/collections_controller.ts @@ -1,17 +1,12 @@ import DestroyCollection from '#actions/collections/destroy_collection' import GetPaginatedCollections from '#actions/collections/get_paginated_collections' import StoreCollection from '#actions/collections/store_collection' -import StubCollection from '#actions/collections/stub_collection' import UpdateCollection from '#actions/collections/update_collection' import CollectionDto from '#dtos/collection' import TaxonomyDto from '#dtos/taxonomy' import Collection from '#models/collection' import Taxonomy from '#models/taxonomy' -import { - collectionIndexValidator, - collectionStubValidator, - collectionValidator, -} from '#validators/collection' +import { collectionIndexValidator, collectionValidator } from '#validators/collection' import type { HttpContext } from '@adonisjs/core/http' import router from '@adonisjs/core/services/router' diff --git a/app/dtos/collection.ts b/app/dtos/collection.ts index c08e2ab..b02a13e 100644 --- a/app/dtos/collection.ts +++ b/app/dtos/collection.ts @@ -26,8 +26,8 @@ export default class CollectionDto extends BaseModelDto { declare description: string declare pageTitle: string declare metaDescription: string - declare youtubePlaylistUrl: string - declare repositoryUrl: string + declare youtubePlaylistUrl: string | null + declare repositoryUrl: string | null declare sortOrder: number declare moduleNumber: number declare owner: UserDto | null diff --git a/app/dtos/post_form.ts b/app/dtos/post_form.ts index a75e11c..1105edf 100644 --- a/app/dtos/post_form.ts +++ b/app/dtos/post_form.ts @@ -1,14 +1,6 @@ import { BaseModelDto } from '@adocasts.com/dto/base' import Post from '#models/post' import AssetDto from '#dtos/asset' -import PostSnapshotDto from '#dtos/post_snapshot' -import CommentDto from '#dtos/comment' -import UserDto from '#dtos/user' -import TaxonomyDto from '#dtos/taxonomy' -import CollectionDto from '#dtos/collection' -import HistoryDto from '#dtos/history' -import ProgressDto from '#dtos/progress' -import WatchlistDto from '#dtos/watchlist' import VideoTypes from '#enums/video_types' import States from '#enums/states' import PaywallTypes from '#enums/paywall_types' diff --git a/app/middleware/auth_middleware.ts b/app/middleware/auth_middleware.ts index 6e07003..e416644 100644 --- a/app/middleware/auth_middleware.ts +++ b/app/middleware/auth_middleware.ts @@ -20,6 +20,10 @@ export default class AuthMiddleware { } = {} ) { await ctx.auth.authenticateUsing(options.guards, { loginRoute: this.redirectTo }) + + // require user to at least have access to the dashboard to access cms + await ctx.bouncer.with('CmsPolicy').authorize('viewDashboard') + return next() } -} \ No newline at end of file +} diff --git a/app/models/plan.ts b/app/models/plan.ts index b4b40d5..c937a0c 100644 --- a/app/models/plan.ts +++ b/app/models/plan.ts @@ -1,14 +1,15 @@ import { DateTime } from 'luxon' -import { BaseModel, beforeSave, column, computed, hasMany } from '@adonisjs/lucid/orm' +import { beforeSave, column, computed, hasMany } from '@adonisjs/lucid/orm' import Env from '#start/env' import UtilityService from '#services/utility_service' import Plans from '#enums/plans' import CouponDurations from '#enums/coupon_durations' -import User from './user.js' +import User from '#models/user' import type { HasMany } from '@adonisjs/lucid/types/relations' import SlugService from '#services/slug_service' +import AppBaseModel from '#models/app_base_model' -export default class Plan extends BaseModel { +export default class Plan extends AppBaseModel { @column({ isPrimary: true }) declare id: number @@ -60,6 +61,9 @@ export default class Plan extends BaseModel { @column.dateTime({ autoCreate: true, autoUpdate: true }) declare updatedAt: DateTime + @hasMany(() => User) + declare users: HasMany + @computed() get mode() { if (Env.get('NODE_ENV') === 'production') { @@ -128,9 +132,6 @@ export default class Plan extends BaseModel { return UtilityService.formatCurrency(this.salePrice, 'USD') } - @hasMany(() => User) - declare users: HasMany - @beforeSave() static async slugifyUsername(plan: Plan) { if (plan.$dirty.name && !plan.$dirty.slug && !plan.slug) {