old version placed
This commit is contained in:
43
apicalls/validations/validationProcesser.ts
Normal file
43
apicalls/validations/validationProcesser.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { console } from "inspector";
|
||||
|
||||
interface ValidationInterface {
|
||||
required: string[];
|
||||
title: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface HeadersAndValidationsInterface {
|
||||
headers: Object;
|
||||
validation: ValidationInterface;
|
||||
language: string;
|
||||
properties: Object;
|
||||
}
|
||||
|
||||
class HeadersAndValidations {
|
||||
headers: Object;
|
||||
validation: ValidationInterface;
|
||||
language: string;
|
||||
validated: any = {};
|
||||
|
||||
constructor({
|
||||
headers,
|
||||
validation,
|
||||
language,
|
||||
}: HeadersAndValidationsInterface) {
|
||||
this.headers = headers;
|
||||
this.validation = validation;
|
||||
this.language = language;
|
||||
this.parseProcesser();
|
||||
}
|
||||
|
||||
parseProcesser() {
|
||||
Object.entries(this.validation).map(([key, value]) => {
|
||||
this.validated[key] = {
|
||||
required: !value.required,
|
||||
fieldType: value?.type,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export { HeadersAndValidations };
|
||||
67
apicalls/validations/validations.tsx
Normal file
67
apicalls/validations/validations.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
"use server";
|
||||
import { fetchData, fetchDataWithToken } from "@/apicalls/api-fetcher";
|
||||
import { baseUrl, cookieObject, tokenSecret } from "@/apicalls/basics";
|
||||
|
||||
import { HeadersAndValidations } from "@/apicalls/validations/validationProcesser";
|
||||
|
||||
const headersAndValidationEndpoint = `${baseUrl}/validations/endpoint`;
|
||||
|
||||
interface EndpointInterface {
|
||||
endpoint: string;
|
||||
}
|
||||
|
||||
async function retrieveHeadersEndpoint({ endpoint }: EndpointInterface) {
|
||||
const selectResponse: any = await fetchDataWithToken(
|
||||
headersAndValidationEndpoint,
|
||||
{
|
||||
endpoint: endpoint,
|
||||
},
|
||||
"POST",
|
||||
false
|
||||
);
|
||||
if (selectResponse.status === 200) {
|
||||
return {
|
||||
status: selectResponse.status,
|
||||
headers: selectResponse?.headers,
|
||||
message: selectResponse.message,
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: selectResponse.status,
|
||||
headers: {},
|
||||
message: selectResponse.message,
|
||||
};
|
||||
}
|
||||
|
||||
async function retrieveHeadersAndValidationByEndpoint({
|
||||
endpoint,
|
||||
}: EndpointInterface) {
|
||||
console.log("endpoint", endpoint);
|
||||
const selectResponse: any = await fetchDataWithToken(
|
||||
headersAndValidationEndpoint,
|
||||
{
|
||||
endpoint: endpoint,
|
||||
},
|
||||
"POST",
|
||||
false
|
||||
);
|
||||
if (selectResponse.status === 200) {
|
||||
const responseParsed = new HeadersAndValidations(selectResponse);
|
||||
return {
|
||||
status: selectResponse.status,
|
||||
headers: responseParsed.headers,
|
||||
validated: responseParsed.validated,
|
||||
language: responseParsed.language,
|
||||
message: selectResponse.message,
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: selectResponse.status,
|
||||
message: selectResponse.message,
|
||||
|
||||
headers: null,
|
||||
validated: null,
|
||||
};
|
||||
}
|
||||
|
||||
export { retrieveHeadersAndValidationByEndpoint, retrieveHeadersEndpoint };
|
||||
Reference in New Issue
Block a user