Skip to content

Commit f9c3983

Browse files
committed
Switched to reflect-metadata decorators
1 parent fa1dc54 commit f9c3983

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

src/bodyguard.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
import 'reflect-metadata';
136136
import { BodyguardOwner, UserRole } from './enums';
137137

138+
const CanReadAllSymbol = Symbol('CanReadAll');
139+
const CanWriteAllSymbol = Symbol('CanWriteAll');
138140
const CanReadSymbol = Symbol('CanRead');
139141
const CanWriteSymbol = Symbol('CanWrite');
140142
const 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) {
175177
export 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(
187187
export 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

Comments
 (0)