Skip to content

Commit

Permalink
refactor services and implement http caching
Browse files Browse the repository at this point in the history
  • Loading branch information
devadathanmb committed Oct 31, 2023
1 parent 8a8d753 commit 9d9a952
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 30 deletions.
13 changes: 13 additions & 0 deletions src/config/axiosConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Axios from "axios";
import { setupCache } from "axios-cache-interceptor";
import * as https from "https";

const agent = new https.Agent({
rejectUnauthorized: false,
});

const axios = setupCache(Axios, {
methods: ["post"],
});

export { axios, agent };
7 changes: 1 addition & 6 deletions src/services/fetchAnnouncements.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import axios from "axios";
import * as https from "https";
import { axios, agent } from "../config/axiosConfig";
import { ANOUNCEMENTS_URL } from "../constants/constants";
import { Announcement } from "../types/types";
import ServerError from "../errors/ServerError";
import InvalidDataError from "../errors/InvalidDataError";

const agent = new https.Agent({
rejectUnauthorized: false,
});

async function fetchAnnouncements(
pageNumber: number,
dataSize: number,
Expand Down
7 changes: 1 addition & 6 deletions src/services/fetchAttachment.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import axios from "axios";
import * as https from "https";
import { axios, agent } from "../config/axiosConfig";
import { ATTACHMENT_URL } from "../constants/constants";
import InvalidDataError from "../errors/InvalidDataError";
import ServerError from "../errors/ServerError";

const agent = new https.Agent({
rejectUnauthorized: false,
});

async function fetchAttachment(encryptId: string): Promise<any> {
try {
const response = await axios.post(
Expand Down
7 changes: 1 addition & 6 deletions src/services/fetchCourses.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import axios from "axios";
import * as https from "https";
import { axios, agent } from "../config/axiosConfig";
import { COURSES_URL } from "../constants/constants";
import { Course } from "../types/types";
import InvalidDataError from "../errors/InvalidDataError";
import ServerError from "../errors/ServerError";

const agent = new https.Agent({
rejectUnauthorized: false,
});

async function fetchCourses(): Promise<Course[]> {
try {
const response = await axios.post(COURSES_URL, "data=programs", {
Expand Down
7 changes: 1 addition & 6 deletions src/services/fetchPublishedResults.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import axios from "axios";
import * as https from "https";
import { axios, agent } from "../config/axiosConfig";
import { PUBLISHED_RESULTS_URL } from "../constants/constants";
import { PublishedResultData } from "../types/types";
import ServerError from "../errors/ServerError";
import InvalidDataError from "../errors/InvalidDataError";
import DataNotFoundError from "../errors/DataNotFoundError";

const agent = new https.Agent({
rejectUnauthorized: false,
});

async function fetchPublishedResults(
courseId: number,
): Promise<PublishedResultData[]> {
Expand Down
7 changes: 1 addition & 6 deletions src/services/fetchResult.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import axios from "axios";
import * as https from "https";
import { axios, agent } from "../config/axiosConfig";
import { RESULT_URL } from "../constants/constants";
import InvalidDataError from "../errors/InvalidDataError";
import { ResultDetails, ResultSummary } from "../types/types";
import ServerError from "../errors/ServerError";

const agent = new https.Agent({
rejectUnauthorized: false,
});

async function fetchResult(
dob: string,
regisNo: string,
Expand Down

0 comments on commit 9d9a952

Please sign in to comment.