Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Oct 21, 2024
1 parent b485582 commit ec67b24
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
26 changes: 26 additions & 0 deletions packages/core/framework/src/http/allowed-fields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export class AllowedFields extends Array<string> {
// temporary
nonExpandableFields = ["customers"]

#fields: string[] = []
#override: string[] = []

#shouldOverride = false

get shouldOverride(): boolean {
return this.#shouldOverride
}

extends(fields: string[]) {
this.#fields.push(...fields)
}

override(fields: string[]) {
this.#shouldOverride = true
this.#override.push(...fields)
}

getAllowed() {
return this.#shouldOverride ? this.#override : this.#fields
}
}
4 changes: 4 additions & 0 deletions packages/core/framework/src/http/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,10 @@ export class RoutesLoader {
? this.#sourceDir
: [this.#sourceDir]

this.#app.use((req, res) => {
req.allowed = new AllowedFields()
})

const promises = normalizedSourcePath.map(async (sourcePath) => {
const apiRoutesLoader = new ApiRoutesLoader({
app: this.#app,
Expand Down
3 changes: 2 additions & 1 deletion packages/core/framework/src/http/utils/validate-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export function validateAndTransformQuery<TEntity extends BaseEntity>(
next: NextFunction
) {
try {
const allowed = (req.allowed ?? queryConfig.allowed ?? []) as string[]
req.allowed.push(queryConfig.allowed)
const allowed = req.allowed as string[]
delete req.allowed
const query = normalizeQuery(req)

Expand Down

0 comments on commit ec67b24

Please sign in to comment.