Skip to content

Commit

Permalink
fix(gateway: wigal): replace \n with ^ when rendering response
Browse files Browse the repository at this point in the history
  • Loading branch information
ephrimlawrence committed May 2, 2024
1 parent 13001d9 commit aefdcdd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
70 changes: 34 additions & 36 deletions src/gateways/wigal.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,38 @@ import { Gateway } from "./base.gateway";
import { State } from "@src/models";

export class WigalGateway extends Gateway {
get sessionId(): string {
return this.request.query?.sessionid!;
}

async handleRequest(): Promise<State | undefined> {
let _state = await this.state;

_state ??= new State();

_state.mode = this.request.query?.mode as any; //todo: validate
_state.msisdn = this.request.query?.msisdn!;
_state.sessionId = this.request.query?.sessionid!;
_state.userData = this.request.query?.userdata!;

// await this.session.setState(this.sessionId, _state);
this.request.state = _state;
this.request.input = this.request.query?.userdata!;
this.request.msisdn = _state.msisdn;

return _state;
}

async handleResponse(_req: Request, res: Response): Promise<void> {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end(await this.wigalResponse());
return;
}

private async wigalResponse(): Promise<string> {
const data = (await this.state)!;
return `${this.request.query?.network}|${data?.mode}|${data?.msisdn}|${
data?.sessionId
}|${this.response.data}|${this.request.query?.username}|${
this.request.query?.trafficid
}|${data?.menu?.nextMenu || ""}`;
}
get sessionId(): string {
return this.request.query?.sessionid!;
}

async handleRequest(): Promise<State | undefined> {
let _state = await this.state;

_state ??= new State();

_state.mode = this.request.query?.mode as any; //todo: validate
_state.msisdn = this.request.query?.msisdn!;
_state.sessionId = this.request.query?.sessionid!;
_state.userData = this.request.query?.userdata!;

// await this.session.setState(this.sessionId, _state);
this.request.state = _state;
this.request.input = this.request.query?.userdata!;
this.request.msisdn = _state.msisdn;

return _state;
}

async handleResponse(_req: Request, res: Response): Promise<void> {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end(await this.wigalResponse());
return;
}

private async wigalResponse(): Promise<string> {
const data = (await this.state)!;
return `${this.request.query?.network}|${data?.mode}|${data?.msisdn}|${data?.sessionId
}|${this.response.data?.replace('\n', '^') ?? ''}|${this.request.query?.username}|${this.request.query?.trafficid
}|${data?.menu?.nextMenu || ""}`;
}
}
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type FormInput = {
validate: Validation;
display: string | ((req: Request) => Promise<string> | string);
handler?: (req: Request) => Promise<void>;
next_input?: string | ((req: Request) => Promise<string>);
next_input?: string | ((req: Request) => Promise<string> | string);
end?: boolean | ((req: Request) => boolean);
next_menu?: NextMenu;
};
Expand Down

0 comments on commit aefdcdd

Please sign in to comment.