Skip to content

Commit

Permalink
chore: add middleware names
Browse files Browse the repository at this point in the history
  • Loading branch information
edobrb committed May 30, 2022
1 parent 1c80029 commit 53a22eb
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dal/dao/middlewares/audit/audit.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function audit<T extends DAOGenerics>(
) => { changes: T['update']; insert: PartialDeep<T['insert']> },
): DAOMiddleware<T> {
return buildMiddleware({
name: 'Typetta - Audit',
beforeInsert: async (params, context) => {
return {
continue: true,
Expand Down
1 change: 1 addition & 0 deletions src/dal/dao/middlewares/computedFields/computedFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function computedField<T extends DAOGenerics, P1 extends AnyProjection<T[
compute: (record: ModelProjection<T, P1>, params: FindParams<T>) => Promise<PartialDeep<T['model']>>
}): DAOMiddleware<T> {
return {
name: 'Typetta - Computed field',
before: projectionDependency<T>(options).before,
after: async (args) => {
if (args.operation === 'find') {
Expand Down
1 change: 1 addition & 0 deletions src/dal/dao/middlewares/projection/projectionDependecy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DAOMiddleware } from '../middlewares.types'

export function projectionDependency<T extends DAOGenerics>(options: { fieldsProjection: AnyProjection<T['projection']>; requiredProjection: AnyProjection<T['projection']> }): DAOMiddleware<T> {
return {
name: 'Typetta - Projection dependency',
before: async (args) => {
if (args.operation === 'find') {
if (isProjectionIntersected(args.params.projection ? (args.params.projection as GenericProjection) : true, options.fieldsProjection ? (options.fieldsProjection as GenericProjection) : true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function securityPolicy<
}

return {
name: 'Typetta - Security',
before: async (args, context) => {
const relatedSecurityContext = getRelatedSecurityContext(context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { buildMiddleware } from '../utils/builder'

export function softDelete<T extends DAOGenerics>(input: (args: MiddlewareInput<T>, context: MiddlewareContext<T>) => { filter?: T['filter']; changes?: T['update'] } | void): DAOMiddleware<T> {
return buildMiddleware({
name: 'Typetta - Soft delete',
beforeDelete: async (params, context) => {
const i = input({ operation: 'delete', params }, context)
if (!i || !i.changes) {
Expand Down
1 change: 1 addition & 0 deletions src/dal/dao/middlewares/utils/default.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { buildMiddleware } from './builder'

export function defaultValueMiddleware<T extends DAOGenerics, K extends keyof T['model']>(field: K, value: (metadata: T['metadata'] | undefined) => T['model'][K]): DAOMiddleware<T> {
return buildMiddleware({
name: 'Typetta - Default value',
beforeInsert: async (params, context) => {
if (params.record[field] === undefined) {
return { continue: true, params: { ...params, record: { ...params.record, [field]: value(context.metadata) } } }
Expand Down

0 comments on commit 53a22eb

Please sign in to comment.