prorm API Reference
    Preparing search index...

    Function withPermissions

    • A higher-order helper that wraps a controller function and automatically applies permission filtering on the result.

      Example:

      const getUser = withPermissions(User, async (id: number) => { return User.findByPk(id); });

      const safeUser = await getUser(1, 'guest'); // safeUser has only the fields 'guest' is allowed to see

      Type Parameters

      • T extends (...args: any[]) => Promise<any>

      Parameters

      • ModelClass: Function

        The model class whose permissions to apply

      • fn: T

        The async controller function (last arg must be role string)

      Returns (...args: [...Parameters<T>[], string]) => Promise<Record<string, any> | null>