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

Issue feat PS-3869:Change endPoints of middlewear APIs to Interface endpoint #681

Open
wants to merge 1 commit into
base: release-1.2.0
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/services/AcademicYearService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { post } from './RestClient';

export const getAcademicYear = async (): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/academicyears/list`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/academicyears/list`;
try {
const response = await post(apiUrl,{});
return response?.data?.result;
Expand Down
6 changes: 3 additions & 3 deletions src/services/AssesmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const getAssessmentList = async ({
pagination,
filters,
}: AssessmentListParam): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/v1/tracking/assessment/list`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/tracking/assessment/list`;
try {
const response = await post(apiUrl, { pagination, filters, sort });
return response?.data;
Expand Down Expand Up @@ -52,7 +52,7 @@ export const getDoIdForAssessmentDetails = async ({
};

export const getAssessmentStatus = async (body: IAssessmentStatusOptions) => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/v1/tracking/assessment/search/status`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/tracking/assessment/search/status`;
try {
const response = await post(apiUrl, body);
return response?.data?.data;
Expand All @@ -64,7 +64,7 @@ export const getAssessmentStatus = async (body: IAssessmentStatusOptions) => {
};

export const searchAssessment = async (body: ISearchAssessment) => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/v1/tracking/assessment/search`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/tracking/assessment/search`;
try {
const response = await post(apiUrl, body);
return response?.data?.data;
Expand Down
8 changes: 4 additions & 4 deletions src/services/AttendanceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const bulkAttendance = async ({
contextId,
userAttendance,
}: BulkAttendanceParams): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/api/v1/attendance/bulkAttendance`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/account/attendance/bulkAttendance`;
try {
const response = await post(apiUrl, {
attendanceDate,
Expand All @@ -189,7 +189,7 @@ export const markAttendance = async ({
contextId,
attendance,
}: MarkAttendanceParams): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/api/v1/attendance`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/attendance/create`;
try {
const response = await post(apiUrl, {
userId,
Expand All @@ -210,7 +210,7 @@ const postAttendanceList = async ({
filters = {},
facets,
}: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/api/v1/attendance/list`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/account/attendance/list`;
filters.context = "cohort"; // Ensure context is added to filters
try {
const response = await post(apiUrl, { limit, page, filters, facets });
Expand Down Expand Up @@ -308,7 +308,7 @@ export const classesMissedAttendancePercentList = async ({
facets,
sort,
}: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/api/v1/attendance/list`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/account/attendance/list`;
filters.context = "cohort"; // Add context to filters
try {
const response = await post(apiUrl, { filters, facets, sort });
Expand Down
10 changes: 5 additions & 5 deletions src/services/CohortServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const cohortList = async ({
offset,
filters,
}: CohortListParam): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohort/search`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/cohort/search`;
try {
const response = await post(apiUrl, { limit, offset, filters });
return response?.data?.result;
Expand All @@ -18,7 +18,7 @@ export const cohortList = async ({
};

export const getCohortDetails = async (cohortId: string): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohort/cohortHierarchy/${cohortId}`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/cohort/cohortHierarchy/${cohortId}`;
try {
const response = await get(apiUrl);
return response?.data?.result;
Expand All @@ -33,7 +33,7 @@ export const getCohortList = async (
filters: { [key: string]: string } = {},
isCustomFields: boolean = false
): Promise<any> => {
let apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohort/mycohorts/${userId}?children=true`;
let apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/cohort/mycohorts/${userId}?children=true`;
const filterParams = new URLSearchParams(filters).toString();
if (filterParams) {
apiUrl += `&${filterParams}`;
Expand Down Expand Up @@ -63,7 +63,7 @@ export const getCohortList = async (
};

export const bulkCreateCohortMembers = async (payload: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohortmember/bulkCreate`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/cohortmember/bulkCreate`;
try {
const response = await post(apiUrl, payload);
return response.data;
Expand All @@ -78,7 +78,7 @@ export const getCohortSearch = async ({
limit = 20,
offset = 0,
}: GetCohortSearchParams): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohort/search`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/cohort/search`;

const data = {
filters: {
Expand Down
6 changes: 3 additions & 3 deletions src/services/CreateUserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { post } from './RestClient';
// };

export const createUser = async (userData: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/create`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/account/create`;
try {
const response = await post(apiUrl, userData);
return response?.data?.result;
Expand All @@ -28,7 +28,7 @@ export const createUser = async (userData: any): Promise<any> => {
};

export const userNameExist = async (userData: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/suggestUsername`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/suggestUsername`;
try {
const response = await post(apiUrl, userData);
return response?.data?.result;
Expand All @@ -39,7 +39,7 @@ export const userNameExist = async (userData: any): Promise<any> => {
};

export const createCohort = async (userData: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohort/create`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/cohort/create`;
try {
const response = await post(apiUrl, userData);
return response?.data?.result;
Expand Down
6 changes: 3 additions & 3 deletions src/services/EventService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const getEventList = async ({
offset,
filters,
}: scheduleEventParam): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/event-service/event/v1/list`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/event/list`;
try {
const response = await post(apiUrl, { limit, offset, filters });
return response?.data?.result;
Expand All @@ -17,7 +17,7 @@ export const getEventList = async ({
};

export const createEvent = async (apiBody: CreateEvent): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/event-service/event/v1/create`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/event/create`;
try {
const response = await post(apiUrl, apiBody);
return response?.data;
Expand All @@ -31,7 +31,7 @@ export const editEvent = async (
eventRepetitionId: string,
apiBody: EditEvent
): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/event-service/event/v1/${eventRepetitionId}`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/event/${eventRepetitionId}`;
try {
const response = await patch(apiUrl, apiBody);
return response?.data;
Expand Down
2 changes: 1 addition & 1 deletion src/services/FormService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { deleteApi } from './RestClient';
export const deleteFormFields = async (
fieldValues: { fieldId: string; itemId: string }[]
): Promise<any> => {
const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/fields/values/delete`;
const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/fields/values/delete`;

try {
const response = await deleteApi(apiUrl, { fieldValues }, {});
Expand Down
12 changes: 6 additions & 6 deletions src/services/LoginService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const login = async ({
username,
password,
}: LoginParams): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/auth/login`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/account/login`;

try {
const response = await post(apiUrl, { username, password });
Expand All @@ -28,7 +28,7 @@ export const login = async ({
export const refresh = async ({
refresh_token,
}: RefreshParams): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/auth/refresh`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/auth/refresh`;
try {
const response = await post(apiUrl, { refresh_token });
return response?.data;
Expand All @@ -39,7 +39,7 @@ export const refresh = async ({
};

export const logout = async (refreshToken: string): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/auth/logout`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/auth/logout`;
try {
const response = await post(apiUrl, { refresh_token: refreshToken });
return response;
Expand All @@ -51,7 +51,7 @@ export const logout = async (refreshToken: string): Promise<any> => {

export const resetPassword = async (
newPassword: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/reset-password`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/reset-password`;
Comment on lines 52 to +54
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve type safety by adding proper interfaces for password-related functions.

Several functions use any type which reduces type safety:

  • resetPassword
  • forgotPasswordAPI
  • resetPasswordLink
+interface PasswordReset {
+  newPassword: string;
+}

+interface ForgotPassword {
+  newPassword: string;
+  token: string;
+}

+interface PasswordResetLink {
+  username: string;
+}

-export const resetPassword = async (newPassword: any): Promise<any> => {
+export const resetPassword = async (newPassword: PasswordReset): Promise<void> => {

Also applies to: 64-66, 77-79

try {
const response = await post(apiUrl, { newPassword });
return response?.data;
Expand All @@ -63,7 +63,7 @@ export const resetPassword = async (

export const forgotPasswordAPI = async (
newPassword: any , token: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/forgot-password`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/forgot-password`;
try {
const response = await post(apiUrl, { newPassword, token });
return response?.data;
Expand All @@ -76,7 +76,7 @@ export const forgotPasswordAPI = async (

export const resetPasswordLink = async (
username: any , ): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/password-reset-link`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/password-reset-link`;
try {
let redirectUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || ''
if(redirectUrl === '' && typeof window !== 'undefined' ){
Expand Down
8 changes: 4 additions & 4 deletions src/services/ManageUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getFacilitatorList = async ({
page,
filters,
}: FacilitatorListParam): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/list`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/list`;
try {
const response = await post(apiUrl, { limit, page, filters });
return response?.data?.result;
Expand All @@ -24,7 +24,7 @@ export const assignCentersToFacilitator = async ({
userId,
cohortId,
}: AssignCentersToFacilitatorListParam): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohortmember/bulkCreate`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/cohortmember/bulkCreate`;
try {
const response = await post(apiUrl, { userId, cohortId });
return response?.data?.result;
Expand All @@ -38,7 +38,7 @@ export const updateFacilitator = async (
userId: string,
userData: FacilitatorDeleteUserData
): Promise<any> => {
const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/update/${userId}`;
const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/update/${userId}`;
try {
const response = await patch(apiUrl, { userData });
return response.data.result;
Expand All @@ -52,7 +52,7 @@ export const renameFacilitator = async (
userId: string,
name: string
): Promise<any> => {
const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohort/update/${userId}`;
const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/cohort/update/${userId}`;
try {
const response = await put(apiUrl, { name });
return response.data.result;
Expand Down
6 changes: 3 additions & 3 deletions src/services/MyClassDetailsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const fetchCohortMemberList = async ({
page,
filters,
}: CohortMemberList): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohortmember/list`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/cohortmember/list`;
try {
const response = await post(apiUrl, {
limit,
Expand All @@ -34,7 +34,7 @@ export const getMyUserList = async ({
filters,
fields,
}: UserList): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/list`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/list`;
try {
const response = await post(apiUrl, {
limit,
Expand Down Expand Up @@ -96,7 +96,7 @@ export const updateCohortMemberStatus = async ({
membershipId,
dynamicBody = {},
}: UpdateCohortMemberStatusParams): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohortmember/update/${membershipId}`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/cohortmember/update/${membershipId}`;

// Utility to stringify only the values of the customFields
const prepareCustomFields = (customFields: any[]): any[] => {
Expand Down
8 changes: 4 additions & 4 deletions src/services/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const sendCredentialService = async ({
email,
push
}: SendCredentialsRequest): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/notification/send`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/notification/send`;
try {
const response = await post(apiUrl, {
isQueue,
Expand Down Expand Up @@ -90,7 +90,7 @@ export const UpdateDeviceNotification = async (
userId: string,
headers: { tenantId: any; Authorization: string }
): Promise<any> => {
const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/update/${userId}`;
const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/update/${userId}`;

try {
const response = await axios.patch(apiUrl, { userData }, { headers });
Expand All @@ -107,7 +107,7 @@ export const readUserId = async (
userId?: string | string[],
fieldValue?: boolean
): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/read/${userId}?fieldvalue=false`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/read/${userId}?fieldvalue=false`;
try {
const response = await get(apiUrl);
return response?.data;
Expand All @@ -124,7 +124,7 @@ export const sendNotification = async ({
key,
push
}: SendCredentialsRequest): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/notification/send`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/notification/send`;
try {
const response = await post(apiUrl, {
isQueue,
Expand Down
6 changes: 3 additions & 3 deletions src/services/ProfileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios';
import { get, patch } from './RestClient';

export const getUserId = async (): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/auth`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/auth`;

try {
const token = localStorage.getItem('token');
Expand All @@ -27,7 +27,7 @@ export const editEditUser = async (
userId?: string | string[],
userDetails?: object
): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/update/${userId}`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/update/${userId}`;
try {
const response = await patch(apiUrl, userDetails);
return response?.data;
Expand All @@ -41,7 +41,7 @@ export const getUserDetails = async (
userId?: string | string[],
fieldValue?: boolean
): Promise<any> => {
let apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/read/${userId}`;
let apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/read/${userId}`;
apiUrl = fieldValue ? `${apiUrl}?fieldvalue=true` : apiUrl;

try {
Expand Down
2 changes: 1 addition & 1 deletion src/services/TrackingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const getContentTrackingStatus = async (reqBody: ContentStatus) => {
};

export const createContentTracking = async (reqBody: ContentCreate) => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/v1/tracking/content/create`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/tracking/content/create`;
try {
const response = await post(apiUrl, reqBody);
return response?.data;
Expand Down