Skip to content

Commit

Permalink
save worker info in component prop
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwalguptaofficial committed Jan 14, 2024
1 parent ec8a74e commit 21307b4
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/abstracts/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export abstract class Guard extends Component {
}

get workerName() {
return this['componentProp_'].workerName;
return this['componentProp_'].workerInfo.workerName;
}

abstract check(...args): Promise<IHttpResult | void>;
Expand Down
2 changes: 1 addition & 1 deletion src/abstracts/shield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Component } from "./component";

export abstract class Shield extends Component {
get workerName() {
return this['componentProp_'].workerName;
return this['componentProp_'].workerInfo.workerName;
}

get logger(): Logger {
Expand Down
3 changes: 1 addition & 2 deletions src/handlers/request_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,10 @@ export class RequestHandler extends RequestHandlerHelper {

this.componentProps.param = routeMatchInfo.params;
this.componentProps.controllerName = routeMatchInfo.controllerName;
this.componentProps.workerName = workerInfo.workerName;
this.componentProps.workerInfo = workerInfo;

const shieldResult = await this.executeShieldsProtection_();
if (shieldResult) return shieldResult;

const guardResult = await this.executeGuardsCheck_(
workerInfo.guards
);
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/test/init_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const initController = (controllerInstance: Controller, data?: IControlle
param: data.param || {},
data: data.data || {},
file: new FileManager(data.file || {}),
workerName: (data as any).workerName,
workerInfo: {
workerName: (data as any).workerName
} as any,
global: FORT_GLOBAL,
cache: cacheManager
};
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/component_prop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FortGlobal } from "../constants";
import { SessionManager } from "../utils";
import { TComponentQuery } from "../types";
import { CacheManager } from "../utils/cache_manager";
import { IWorkerInfo } from "./worker_info";

export interface IComponentProp {
request: http.IncomingMessage;
Expand All @@ -15,8 +16,8 @@ export interface IComponentProp {
param?: { [key: string]: string };
data: { [key: string]: any };
file?: FileManager;
workerName?: string;
controllerName?: string;
global: FortGlobal;
cache: CacheManager;
workerInfo?: IWorkerInfo;
}
1 change: 1 addition & 0 deletions src/providers/cache_guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IHttpResult } from "../interfaces";

export class CacheGuard extends Guard {
async check(...args: any[]): Promise<void | IHttpResult> {

Check warning on line 5 in src/providers/cache_guard.ts

View workflow job for this annotation

GitHub Actions / build

'args' is defined but never used

Check warning on line 5 in src/providers/cache_guard.ts

View workflow job for this annotation

GitHub Actions / build

'args' is defined but never used
const cache = this['componentProp_'].workerInfo.cache;

Check warning on line 6 in src/providers/cache_guard.ts

View workflow job for this annotation

GitHub Actions / build

'cache' is assigned a value but never used

Check warning on line 6 in src/providers/cache_guard.ts

View workflow job for this annotation

GitHub Actions / build

'cache' is assigned a value but never used
// get cache condition from routes
// and check if condition exist

Expand Down

0 comments on commit 21307b4

Please sign in to comment.