Skip to content

Commit

Permalink
added bodyParam
Browse files Browse the repository at this point in the history
  • Loading branch information
swarnadipa-dev committed Oct 4, 2024
1 parent 56ca32e commit 220d0cb
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class DocumentTabComponent implements OnInit, OnDestroy {
templateLabels: labelsList = {} as labelsList;
actionsImportFn: ActionsImportFunction | null = null;
activeFeature: FeaturesKey = {} as FeaturesKey;
endpointData = {} as unknown;
constructor(
public dialogService: MatDialog,
private fb: FormBuilder,
Expand Down Expand Up @@ -93,8 +94,9 @@ export class DocumentTabComponent implements OnInit, OnDestroy {
if (this.activeFeature && this.activeFeature in featureConfig) {
this.templateConfigData = featureConfig[FEATURES[featureKey]](
GENERIC_LABELS.DOCUMENT
) as FeatureData;
) as unknown as FeatureData;
this.templateLabels = this.templateConfigData?.labels;
this.endpointData = this.templateConfigData?.data;
this.genericMultiFeatureUtilitiesService.pageTitle.next(
this.templateLabels.pageTitle
);
Expand Down Expand Up @@ -218,18 +220,37 @@ export class DocumentTabComponent implements OnInit, OnDestroy {
decodeURIComponent(doc.path)
)
: doc.path;
const requestQuery =
const featureEndpointData = this.templateConfigData?.data;
let requestQueryParam = "";
let requestBodyParam = "";
if ("queryParam" in featureEndpointData) {
requestQueryParam =
this.genericMultiFeatureUtilitiesService.getRequestQuery(
this.templateConfigData.requestParams as string,
decodedPath
);
}

if ("bodyParam" in featureEndpointData) {
requestBodyParam =
this.genericMultiFeatureUtilitiesService.getRequestQuery(
this.templateConfigData.requestParams as string,
decodedPath
);
}
/* const requestQuery =
this.genericMultiFeatureUtilitiesService.getRequestQuery(
this.templateConfigData.requestQuery as string,
this.templateConfigData.requestParams as string,
decodedPath
);
); */
const featureKey = getFeatureKeyByValue(
this.activeFeature
) as FeaturesKey;
if (featureKey in FEATURES) {
this.store.dispatch(
FeatureActions.performDocumentAction({
requestQuery,
requestQueryParam,
requestBodyParam,
featureEndpoint: REST_END_POINTS[featureKey],
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export class FolderTabComponent implements OnInit, OnDestroy {
templateLabels: labelsList = {} as labelsList;
requestQuery = "";
activeFeature: FeaturesKey = {} as FeaturesKey;
requestQueryParam = "";
requestBodyParam = "";

constructor(
public dialogService: MatDialog,
Expand Down Expand Up @@ -108,7 +110,7 @@ export class FolderTabComponent implements OnInit, OnDestroy {
if (this.activeFeature && this.activeFeature in featureConfig) {
this.templateConfigData = featureConfig[FEATURES[featureKey]](
GENERIC_LABELS.FOLDER
) as FeatureData;
) as unknown as FeatureData;
this.templateLabels = this.templateConfigData?.labels;
this.genericMultiFeatureUtilitiesService.pageTitle.next(
this.templateLabels.pageTitle
Expand Down Expand Up @@ -209,11 +211,28 @@ export class FolderTabComponent implements OnInit, OnDestroy {
decodeURIComponent(this.userInput)
);

this.requestQuery =
const featureEndpointData = this.templateConfigData?.data;
if ("queryParam" in featureEndpointData) {
this.requestQueryParam =
this.genericMultiFeatureUtilitiesService.getRequestQuery(
this.templateConfigData.requestParams as string,
this.decodedUserInput
);
}

if ("bodyParam" in featureEndpointData) {
this.requestBodyParam =
this.genericMultiFeatureUtilitiesService.getRequestQuery(
this.templateConfigData.requestParams as string,
this.decodedUserInput
);
}

/* this.requestQuery =
this.genericMultiFeatureUtilitiesService.getRequestQuery(
this.templateConfigData.requestQuery as string,
this.templateConfigData.requestParams as string,
this.decodedUserInput
);
); */
this.fetchNoOfDocuments(this.requestQuery as string);
} catch (error) {
this.showActionErrorModal({
Expand Down Expand Up @@ -306,7 +325,8 @@ export class FolderTabComponent implements OnInit, OnDestroy {
if (featureKey in FEATURES) {
this.store.dispatch(
FeatureActions.performFolderAction({
requestQuery: this.requestQuery,
requestQueryParam: this.requestQueryParam,
requestBodyParam: this.requestBodyParam,
featureEndpoint: REST_END_POINTS[featureKey as FeaturesKey],
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class NXQLTabComponent implements OnInit, OnDestroy {
if (this.activeFeature && this.activeFeature in featureConfig) {
this.templateConfigData = featureConfig[FEATURES[featureKey]](
GENERIC_LABELS.NXQL
) as FeatureData;
) as unknown as FeatureData;
this.templateLabels = this.templateConfigData?.labels;
this.genericMultiFeatureUtilitiesService.pageTitle.next(
this.templateLabels.pageTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@ export interface GenericModalData {
export interface labelsList {
pageTitle: string;
submitBtnLabel: string;
nxqlQueryDefault?: string;
}

export interface FeatureData {
requestQuery: string;
requestParams: string;
labels: labelsList;
data: RequestParamType;
}

export interface RequestParamType {
queryParam: { [key: string]: any };
bodyParam: { [key: string]: any };
urlParam: { [key: string]: any };
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ELASTIC_SEARCH_LABELS } from "../../elastic-search-reindex/elastic-search-reindex.constants";
import { GENERIC_LABELS } from "./generic-multi-feature-layout.constants";
import { labelsList } from "./generic-multi-feature-layout.interface";

export const FEATURES = {
ELASTIC_SEARCH_REINDEX: "elasticsearch-reindex"
Expand All @@ -20,28 +21,35 @@ export function getFeatureKeyByValue(

export const featureMap = () => ({
[FEATURES.ELASTIC_SEARCH_REINDEX]: (tabType: string) => {
let requestQuery: string;
let labels: { pageTitle: string; submitBtnLabel: string };
let requestParams: string;
let labels: labelsList;
let data = {};

switch (tabType) {
case GENERIC_LABELS.DOCUMENT:
(requestQuery = `ecm:path='{queryParam}'`),
(requestParams = `ecm:path='{queryParam}'`),
(labels = {
pageTitle: ELASTIC_SEARCH_LABELS.DOCUMENT_REINDEX_TITLE,
submitBtnLabel: ELASTIC_SEARCH_LABELS.REINDEX_BUTTON_LABEL,
});
(data = {
queryParam: { query: requestParams}
})
break;

case GENERIC_LABELS.FOLDER:
(requestQuery = `ecm:uuid='{queryParam}' OR ecm:ancestorId='{queryParam}' ${GENERIC_LABELS.AND} ${GENERIC_LABELS.SELECT_QUERY_CONDITIONS}`),
(requestParams = `ecm:uuid='{queryParam}' OR ecm:ancestorId='{queryParam}' ${GENERIC_LABELS.AND} ${GENERIC_LABELS.SELECT_QUERY_CONDITIONS}`),
(labels = {
pageTitle: ELASTIC_SEARCH_LABELS.FOLDER_REINDEX_TITLE,
submitBtnLabel: ELASTIC_SEARCH_LABELS.REINDEX_BUTTON_LABEL,
});
(data = {
bodyParam: { query: requestParams}
})
break;

case GENERIC_LABELS.NXQL:
(requestQuery = `ecm:uuid='{queryParam}' OR ecm:ancestorId='{queryParam}' ${GENERIC_LABELS.AND} ${GENERIC_LABELS.SELECT_QUERY_CONDITIONS}`),
(requestParams = `ecm:uuid='{queryParam}' OR ecm:ancestorId='{queryParam}' ${GENERIC_LABELS.AND} ${GENERIC_LABELS.SELECT_QUERY_CONDITIONS}`),
(labels = {
pageTitle: ELASTIC_SEARCH_LABELS.NXQL_QUERY_REINDEX_TITLE,
submitBtnLabel: ELASTIC_SEARCH_LABELS.REINDEX_BUTTON_LABEL,
Expand All @@ -53,8 +61,9 @@ export const featureMap = () => ({
}

return {
requestQuery,
requestParams,
labels,
data
};
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ import { REST_END_POINTS } from "../../../../shared/constants/rest-end-ponts.con
export class GenericMultiFeatureEndpointsService {
constructor(private networkService: NetworkService) {}
performDocumentAction(
requestQuery: string | null,
featureEndpoint: string
requestQueryParam: string | null,
requestBodyParam: string | null,
featureEndpoint: string,
): Observable<ActionInfo> {
return this.networkService.makeHttpRequest<ActionInfo>(
REST_END_POINTS[featureEndpoint as keyof typeof REST_END_POINTS],
{ query: requestQuery }
{queryParam: {query: requestQueryParam}, bodyParam: {query: requestBodyParam}}
);
}

performFolderAction(
requestQuery: string | null,
featureEndpoint: string
requestQueryParam: string | null,
requestBodyParam: string | null,
featureEndpoint: string,
): Observable<ActionInfo> {
return this.networkService.makeHttpRequest<ActionInfo>(
REST_END_POINTS[featureEndpoint as keyof typeof REST_END_POINTS],
{ query: requestQuery }
{queryParam: {query: requestQueryParam}, bodyParam: {query: requestBodyParam}}
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ActionInfo } from "../generic-multi-feature-layout.interface";

export const performDocumentAction = createAction(
"[Admin] Perform Action",
props<{ requestQuery: string | null; featureEndpoint: string }>()
props<{ requestQueryParam: string | null; requestBodyParam: string | null; featureEndpoint: string }>()
);
export const onDocumentActionLaunch = createAction(
"[Admin] On Action Launch",
Expand All @@ -19,7 +19,7 @@ export const resetDocumentActionState = createAction(
);
export const performFolderAction = createAction(
"[Admin] Perform Folder Action",
props<{ requestQuery: string | null; featureEndpoint: string }>()
props<{ requestQueryParam: string | null; requestBodyParam: string | null; featureEndpoint: string }>()
);
export const onFolderActionLaunch = createAction(
"[Admin] On Folder Action Launch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const loadPerformDocumentActionEffect = createEffect(
ofType(FeatureActions.performDocumentAction),
switchMap((action) => {
return genericMultiFeatureEndpointsService
.performDocumentAction(action?.requestQuery, action?.featureEndpoint)
.performDocumentAction(action?.requestQueryParam, action?.requestBodyParam, action?.featureEndpoint)
.pipe(
map((data) => {
return FeatureActions.onDocumentActionLaunch({
Expand All @@ -41,7 +41,7 @@ export const loadPerformFolderActionEffect = createEffect(
ofType(FeatureActions.performFolderAction),
switchMap((action) => {
return genericMultiFeatureEndpointsService
.performFolderAction(action?.requestQuery, action?.featureEndpoint)
.performFolderAction(action?.requestQueryParam, action?.requestBodyParam, action?.featureEndpoint)
.pipe(
map((data) => {
return FeatureActions.onFolderActionLaunch({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,41 @@ export class NetworkService {
delete data["urlParam"];
}

if (data?.["query"]) {
url += `?query=${data["query"]}`;
// iterate & add
if (data?.["queryParam"]) {
const queryParam = data["queryParam"] as { query: string };
url += `?query=${queryParam["query"]}`;
delete data["query"];
}

/* if (data?.["bodyParam"]) {
const renamedObj = Object.fromEntries(
Object.entries(data).map(([key, value]) =>
[`query`, value]
)
)
data = renamedObj;
} */
let bodyParam = {} as { query: string };
if (data?.["bodyParam"]) {
bodyParam = data["bodyParam"] as { query: string };
}

if (
data?.["bodyParam"] &&
typeof data["bodyParam"] === "object" && // Ensure it's an object
"query" in data["bodyParam"] && // Check if "query" exists
typeof (data["bodyParam"] as Record<string, any>)["query"] === "object" && // Check if 'query' is an object
Object.keys((data["bodyParam"] as Record<string, any>)["query"]).length >
0
) {
// 'query' is an object and it is not empty
bodyParam = data["bodyParam"] as { query: string };
}

switch (method) {
case "POST":
return this.http.post<T>(url, data || {});
return this.http.post<T>(url, bodyParam["query"] || {});
break;
case "PUT":
return this.http.put<T>(url, data || {});
Expand All @@ -62,7 +89,7 @@ export class NetworkService {
case "GET":
if (data) {
Object.keys(data).forEach((key) => {
params = params.append(key, String(data[key]));
params = params.append(key, String(data?.[key]));
});
}
return this.http.get<T>(url, { params });
Expand All @@ -71,4 +98,4 @@ export class NetworkService {
throw new Error(`Unsupported HTTP method: ${method}`);
}
}
}
}

0 comments on commit 220d0cb

Please sign in to comment.