Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pay typescript fixes #145

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/api/src/auth/operations/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from "zod";

const userSchema = z.object({
name: z.string()
});

type UserAttr = z.infer<typeof userSchema>;

export const registerUser = (user: UserAttr) => {
return user;
}
15 changes: 6 additions & 9 deletions apps/pay/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ type Mutation {

class MomoAuthAPI extends RESTDataSource {
override baseURL = "https://sandbox.momodeveloper.mtn.com/";
private token: string;
private token!: string;

constructor(options: {
token?: string;
Expand All @@ -147,7 +147,7 @@ class MomoAuthAPI extends RESTDataSource {

override willSendRequest(_path: string, request: AugmentedRequest) {
request.headers["Authorisation"] = `Basic ${this.token}`;
request.headers["Ocp-Apim-Subscription-Key"] = subscriptionKey;
request.headers["Ocp-Apim-Subscription-Key"] = subscriptionKey!;
}

async createAcccessToken() {
Expand All @@ -159,19 +159,19 @@ class MomoAPI extends RESTDataSource {
override baseURL = "https://sandbox.momodeveloper.mtn.com/";
private token: string;

constructor(options) {
constructor(options: any) {
super(options);
const { token, cache, key } = options;
this.token = token;
}

override willSendRequest(_path: string, request: AugmentedRequest) {
request.headers["Authorization"] = `Bearer ${this.token}`;
request.headers["Ocp-Apim-Subscription-Key"] = subscriptionKey;
request.headers["Ocp-Apim-Subscription-Key"] = subscriptionKey!;
request.headers["X-Target-Environment"] = "sandbox";
}

async requestToPay(body) {
async requestToPay(body: any) {
try {
const resp = await this.post(`collection/v1_0/requesttopay`, {
body: { ...body?.object },
Expand Down Expand Up @@ -294,8 +294,7 @@ const server = new ApolloServer({

await server.start();

async function validateAccessToken(req, res, next) {
console.log("yerrr");
async function validateAccessToken(req: any, res: any, next: any) {
const authHeader = req.headers.authorization;

if (authHeader) {
Expand All @@ -316,9 +315,7 @@ async function validateAccessToken(req, res, next) {
}
);
req.headers.access_token = response.data.access_token;
//console.log(response.headers);
}
// req.locals.access_tokn = "yerrrrr";

// No token in the request, generate a new access token
// const newToken = dataSources.momoAPI.createAcccessToken();
Expand Down
Loading