Skip to content

Commit

Permalink
Merge branch 'release-1.0.0' of github.com:tekdi/shiksha-admin into r…
Browse files Browse the repository at this point in the history
…elease-1.0.0
  • Loading branch information
suvarnakale committed Nov 5, 2024
2 parents 461da1c + af50c8f commit d23879b
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 57 deletions.
16 changes: 8 additions & 8 deletions src/services/CohortService/cohortService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface UpdateCohortMemberStatusParams {
membershipId: string | number;
}
export const getCohortList = async (data: cohortListData): Promise<any> => {
let apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohort/search`;
let apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohort/search`;

try {
const response = await post(apiUrl, data);
Expand All @@ -37,7 +37,7 @@ export const updateCohortUpdate = async (
cohortDetails: any
): Promise<any> => {
// const { name, status, type } = cohortDetails;
let apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohort/update/${userId}`;
let apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohort/update/${userId}`;

try {
const response = await put(apiUrl, cohortDetails);
Expand All @@ -52,7 +52,7 @@ export const getFormRead = async (
context: string,
contextType: string
): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/form/read?context=${context}&contextType=${contextType}`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/form/read?context=${context}&contextType=${contextType}`;
try {
let response = await get(apiUrl);
const sortedFields = response?.data?.result.fields?.sort(
Expand All @@ -71,7 +71,7 @@ export const getFormRead = async (
}
};
export const createUser = async (userData: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/create`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/create`;
try {
const response = await post(apiUrl, userData);
return response?.data?.result;
Expand All @@ -82,7 +82,7 @@ export const createUser = async (userData: any): Promise<any> => {
};

export const createCohort = async (userData: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohort/create`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohort/create`;
try {
const response = await post(apiUrl, userData);
return response?.data;
Expand All @@ -97,7 +97,7 @@ export const fetchCohortMemberList = async ({
offset,
filters,
}: CohortMemberList): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohortmember/list`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohortmember/list`;
try {
const response = await post(apiUrl, {
limit,
Expand All @@ -115,7 +115,7 @@ export const fetchCohortMemberList = async ({


export const bulkCreateCohortMembers = async (payload: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohortmember/bulkCreate`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohortmember/bulkCreate`;
try {
const response = await post(apiUrl, payload);
return response.data;
Expand All @@ -131,7 +131,7 @@ export const updateCohortMemberStatus = async ({
statusReason,
membershipId,
}: UpdateCohortMemberStatusParams): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohortmember/update/${membershipId}`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohortmember/update/${membershipId}`;
try {
const response = await put(apiUrl, {
status: memberStatus,
Expand Down
68 changes: 37 additions & 31 deletions src/services/CreateUserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { get, post, patch } from "./RestClient";
import { createUserParam } from "../utils/Interfaces";
import axios from "axios";
import { AxiosRequestConfig, AxiosResponse } from "axios";
import { tenantId } from "../../app.config";

export interface UserDetailParam {
userData?: object;
Expand All @@ -10,58 +11,63 @@ export interface UserDetailParam {
}
export const getFormRead = async (
context: string,
contextType: string,
contextType: string
): Promise<any> => {
try {
const response = await axios.get(
`${process.env.NEXT_PUBLIC_BASE_URL}/form/read`,
{
params: {
context,
contextType,
},
paramsSerializer: (params) => {
return Object.entries(params)
?.map(([key, value]) => `${key}=${value}`)
.join("&");
},
headers: { tenantId: "ef99949b-7f3a-4a5f-806a-e67e683e38f3" },
},
);
if (typeof window !== "undefined" && window.localStorage) {
const token = localStorage.getItem("token");
const response = await axios.get(
`${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/form/read`,
{
params: {
context,
contextType,
},
paramsSerializer: (params) => {
return Object.entries(params)
?.map(([key, value]) => `${key}=${value}`)
.join("&");
},
headers: {
tenantId: tenantId,
Authorization: `Bearer ${token}`,
},
}
);

const sortedFields = response?.data?.result.fields?.sort(
(a: { order: string }, b: { order: string }) =>
parseInt(a.order) - parseInt(b.order),
);
const formData = {
formid: response?.data?.result?.formid,
title: response?.data?.result?.title,
fields: sortedFields,
};
return formData;
const sortedFields = response?.data?.result.fields?.sort(
(a: { order: string }, b: { order: string }) =>
parseInt(a.order) - parseInt(b.order)
);
const formData = {
formid: response?.data?.result?.formid,
title: response?.data?.result?.title,
fields: sortedFields,
};
return formData;
}
} catch (error) {
console.error("error in getting cohort details", error);
// throw error;
}
};


export const createUser = async (userData: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/create`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/create`;
try {
const response = await post(apiUrl, userData);
return response?.data?.result;
} catch (error) {
console.error('error in getting cohort list', error);
console.error("error in getting cohort list", error);
// throw error;
}
};

export const updateUser = async (
userId: string,
{ userData, customFields }: UserDetailParam,
{ userData, customFields }: UserDetailParam
): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/update/${userId}`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/update/${userId}`;
try {
const response = await patch(apiUrl, { userData, customFields });
return response;
Expand Down
2 changes: 1 addition & 1 deletion src/services/DeleteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const deleteUser = async (
userId: string,
userData: object,
): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/update/${userId}`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/update/${userId}`;
try {
const response = await patch(apiUrl, userData);
return response?.data;
Expand Down
2 changes: 1 addition & 1 deletion src/services/GetCohortList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { get } from "./RestClient";
export const getCohortList = async (
userId: string | string[],
): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohort/mycohorts/${userId}`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohort/mycohorts/${userId}`;
try {
const response = await get(apiUrl);
return response?.data;
Expand Down
3 changes: 2 additions & 1 deletion src/services/Interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from "axios";
import { refresh } from "./LoginService";
import { tenantId } from "../../app.config";

const instance = axios.create();

Expand Down Expand Up @@ -36,7 +37,7 @@ instance.interceptors.request.use(
}
// config.headers.tenantid = '4783a636-1191-487a-8b09-55eca51b5036';
// config.headers.tenantid = 'fbe108db-e236-48a7-8230-80d34c370800';
config.headers.tenantid = "ef99949b-7f3a-4a5f-806a-e67e683e38f3";
config.headers.tenantid = tenantId;
return config;
},
(error) => {
Expand Down
8 changes: 4 additions & 4 deletions src/services/LoginService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const login = async ({
username,
password,
}: LoginParams): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/auth/login`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/auth/login`;

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

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

export const getUserId = async (): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/auth`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/auth`;
try {
const response = await get(apiUrl);
return response?.data?.result;
Expand Down
14 changes: 7 additions & 7 deletions src/services/MasterDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const getStateBlockDistrictList = async ({
optionName,
sort,
}: StateListParam): Promise<any> => {
const apiUrl = `${process.env.NEXT_PUBLIC_BASE_URL}/fields/options/read`;
const apiUrl = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/fields/options/read`;

const requestBody: StateListParam = {
fieldName,
Expand Down Expand Up @@ -70,7 +70,7 @@ export const getDistrictsForState = async ({
optionName?: string;
sort?: [string, string];
}): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/fields/options/read`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/fields/options/read`;

const requestBody: {
limit?: number;
Expand Down Expand Up @@ -119,7 +119,7 @@ export const getBlocksForDistricts = async ({
optionName?: string;
sort?: [string, string];
}): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/fields/options/read`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/fields/options/read`;

const requestBody: {
limit?: number;
Expand Down Expand Up @@ -158,7 +158,7 @@ export const getCenterList = async ({
limit,
offset,
}: CenterListParam): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohort/search`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohort/search`;
try {
const response = await post(apiUrl, {
filters,
Expand All @@ -176,7 +176,7 @@ export const deleteOption = async (
type: "states" | "districts" | "blocks",
option: string
): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/fields/options/delete/${type}?option=${option}`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/fields/options/delete/${type}?option=${option}`;
const requestBody = {};
const requestHeaders = {};

Expand All @@ -196,7 +196,7 @@ export const createOrUpdateOption = async (
}
// stateId?: string
): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/fields/update/${fieldId}`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/fields/update/${fieldId}`;

console.log("API URL:", apiUrl);
console.log("Request Body:", { fieldParams });
Expand All @@ -219,7 +219,7 @@ export const updateCohort = async (
cohortId: string,
cohortDetails: any
): Promise<any> => {
let apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohort/update/${cohortId}`;
let apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohort/update/${cohortId}`;

try {
const response = await put(apiUrl, cohortDetails);
Expand Down
2 changes: 1 addition & 1 deletion src/services/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const sendCredentialService = async ({
replacements,
email,
}: SendCredentialsRequest): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_NOTIFICATION_BASE_URL}/notification/send`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/notification/send`;
try {
const response = await post(apiUrl, {
isQueue,
Expand Down
6 changes: 3 additions & 3 deletions src/services/UserList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const userList = async ({
offset,
fields,
}: userListParam): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/list`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/list`;
try {
const response = await post(apiUrl, {
limit,
Expand All @@ -47,7 +47,7 @@ export const cohortMemberList = async ({
offset,
fields,
}: userListParam): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohortmember/list`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohortmember/list`;
try {
const response = await post(apiUrl, {
limit,
Expand All @@ -67,7 +67,7 @@ export const getUserDetailsInfo = async (
userId?: string | string[],
fieldValue: boolean = true
): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/read/${userId}?fieldvalue=${fieldValue}`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/read/${userId}?fieldvalue=${fieldValue}`;
try {
const response = await get(apiUrl);
return response?.data?.result;
Expand Down

0 comments on commit d23879b

Please sign in to comment.