Skip to content

Commit

Permalink
fixed: build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgobich committed Dec 22, 2024
1 parent 50e928c commit f57bc21
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 27 deletions.
3 changes: 2 additions & 1 deletion app/actions/plans/destroy_plan.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion app/actions/plans/get_paginated_plans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Params = Infer<typeof planIndexValidator>
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)
Expand Down
2 changes: 1 addition & 1 deletion app/actions/posts/destroy_post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/actions/users/update_user_role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 1 addition & 6 deletions app/controllers/collections_controller.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
4 changes: 2 additions & 2 deletions app/dtos/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions app/dtos/post_form.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
6 changes: 5 additions & 1 deletion app/middleware/auth_middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
13 changes: 7 additions & 6 deletions app/models/plan.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -60,6 +61,9 @@ export default class Plan extends BaseModel {
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime

@hasMany(() => User)
declare users: HasMany<typeof User>

@computed()
get mode() {
if (Env.get('NODE_ENV') === 'production') {
Expand Down Expand Up @@ -128,9 +132,6 @@ export default class Plan extends BaseModel {
return UtilityService.formatCurrency(this.salePrice, 'USD')
}

@hasMany(() => User)
declare users: HasMany<typeof User>

@beforeSave()
static async slugifyUsername(plan: Plan) {
if (plan.$dirty.name && !plan.$dirty.slug && !plan.slug) {
Expand Down

0 comments on commit f57bc21

Please sign in to comment.