135135import 'reflect-metadata' ;
136136import { BodyguardOwner , UserRole } from './enums' ;
137137
138+ const CanReadAllSymbol = Symbol ( 'CanReadAll' ) ;
139+ const CanWriteAllSymbol = Symbol ( 'CanWriteAll' ) ;
138140const CanReadSymbol = Symbol ( 'CanRead' ) ;
139141const CanWriteSymbol = Symbol ( 'CanWrite' ) ;
140142const BodyguardKeySymbol = Symbol ( 'BodyguardKey' ) ;
@@ -153,19 +155,19 @@ const CanReadRelationSymbol = Symbol('CanReadRelationSymbol');
153155 * function will ignore. Use getCanRead() instead for authorization.
154156 * @param target Object to test
155157 */
156- export function getCanReadAll ( target : any ) {
157- return target . canReadAll ;
158+ export function getCanReadAll ( target : any ) : string {
159+ return Reflect . getMetadata ( CanReadAllSymbol , target . constructor ) ;
158160}
159161
160162/**
161- * Get if all members are writable
163+ * Get if all members are writableF
162164 * NOTE: This function only checks if the CanWriteAll() decorator is present.
163165 * Individual fields may have fine-grain access rights, which this
164166 * function will ignore. Use getCanWrite() instead for authorization.
165167 * @param target Object to test
166168 */
167- export function getCanWriteAll ( target : any ) {
168- return target . canWriteAll ;
169+ export function getCanWriteAll ( target : any ) : string {
170+ return Reflect . getMetadata ( CanWriteAllSymbol , target . constructor ) ;
169171}
170172
171173/**
@@ -175,9 +177,7 @@ export function getCanWriteAll(target: any) {
175177export function CanReadAll (
176178 who : BodyguardOwner | UserRole = BodyguardOwner . Anyone
177179) {
178- return ( constructor ) => {
179- constructor . prototype . canReadAll = who ;
180- } ;
180+ return Reflect . metadata ( CanReadAllSymbol , who ) ;
181181}
182182
183183/**
@@ -187,9 +187,7 @@ export function CanReadAll(
187187export function CanWriteAll (
188188 who : BodyguardOwner | UserRole = BodyguardOwner . Anyone
189189) {
190- return ( constructor ) => {
191- constructor . prototype . canWriteAll = who ;
192- } ;
190+ return Reflect . metadata ( CanWriteAllSymbol , who ) ;
193191}
194192
195193/**
0 commit comments