Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
intrn(query): include certain info in post automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Oct 10, 2022
1 parent 4b4e2d3 commit 82d9515
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions database/queries/post/include_defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import type { FindOptions, IncludeOptions } from "%/types/dependent"

import Log from "$!/singletons/log"

import Role from "%/models/role"
import User from "%/models/user"
import Department from "%/models/department"
import AttachedRole from "%/models/attached_role"
import isUndefined from "$/type_guards/is_undefined"
import ProfilePicture from "%/models/profile_picture"
import PostAttachment from "%/models/post_attachment"

/**
* Includes default models
*/
export default function<T>(
currentState: FindOptions<T>,
unusedConstraints: { [key: string]: any }
): FindOptions<T> {
const newState = { ...currentState }

if (isUndefined(newState.include)) {
newState.include = []
}

const castInclude = newState.include as IncludeOptions[]
castInclude.push({
"include": [
{
"include": [
{
"model": ProfilePicture,
"required": false
}
],
"model": User,
"required": true
},
{
"model": Role,
"required": true
}
],
"model": AttachedRole,
"required": true
})
castInclude.push({
"model": Department,
"required": true
})
castInclude.push({
"model": PostAttachment,
"required": false
})

Log.trace("pipeline", "applied default includer")

return newState
}

0 comments on commit 82d9515

Please sign in to comment.