Support unmodified meta objects in frontend api
This commit is contained in:
@@ -22,9 +22,9 @@ function buildAuthHeader(): Record<string, string> | undefined {
|
||||
return {};
|
||||
}
|
||||
|
||||
function buildBody(data?: Record<string, any>) {
|
||||
function buildBody(data?: Record<string, any>, skipDecamelize = false) {
|
||||
if (data) {
|
||||
return JSON.stringify(decamelizeKeys(data));
|
||||
return JSON.stringify(skipDecamelize ? data : decamelizeKeys(data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,10 +57,12 @@ export async function get(
|
||||
interface PostArgs {
|
||||
url: string;
|
||||
data?: any;
|
||||
skipCamelize?: boolean;
|
||||
skipDecamelize?: boolean;
|
||||
}
|
||||
|
||||
export async function post(
|
||||
{ url, data }: PostArgs,
|
||||
{ url, data, skipCamelize, skipDecamelize }: PostArgs,
|
||||
abortController?: AbortController,
|
||||
) {
|
||||
const apiUrl = buildUrl({ url });
|
||||
@@ -70,17 +72,19 @@ export async function post(
|
||||
[contentTypeHeader]: "application/json",
|
||||
};
|
||||
const signal = abortController?.signal;
|
||||
const body = buildBody(data);
|
||||
const body = buildBody(data, skipDecamelize);
|
||||
const response = await fetch(apiUrl, { method, headers, body, signal });
|
||||
return processResponse(response);
|
||||
return processResponse(response, skipCamelize);
|
||||
}
|
||||
|
||||
interface PutArgs {
|
||||
url: string;
|
||||
data?: any;
|
||||
skipCamelize?: boolean;
|
||||
skipDecamelize?: boolean;
|
||||
}
|
||||
export async function put(
|
||||
{ url, data }: PutArgs,
|
||||
{ url, data, skipCamelize, skipDecamelize }: PutArgs,
|
||||
abortController?: AbortController,
|
||||
) {
|
||||
const apiUrl = buildUrl({ url });
|
||||
@@ -90,7 +94,7 @@ export async function put(
|
||||
[contentTypeHeader]: "application/json",
|
||||
};
|
||||
const signal = abortController?.signal;
|
||||
const body = buildBody(data);
|
||||
const body = buildBody(data, skipDecamelize);
|
||||
const response = await fetch(apiUrl, { method, headers, body, signal });
|
||||
return processResponse(response);
|
||||
return processResponse(response, skipCamelize);
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import { decamelizeKeys } from "humps";
|
||||
|
||||
import * as api from "./base";
|
||||
import { DNSProvider } from "./models";
|
||||
|
||||
@@ -5,10 +7,19 @@ export async function createDNSProvider(
|
||||
data: DNSProvider,
|
||||
abortController?: AbortController,
|
||||
): Promise<DNSProvider> {
|
||||
// Because the meta property of the data should not be decamelized,
|
||||
// we're going to decamelize the rest here instead of in base.ts
|
||||
let dcData: any = decamelizeKeys(data);
|
||||
if (typeof data.meta !== "undefined") {
|
||||
dcData.meta = data.meta;
|
||||
}
|
||||
|
||||
const { result } = await api.post(
|
||||
{
|
||||
url: "/dns-providers",
|
||||
data,
|
||||
data: dcData,
|
||||
skipCamelize: true,
|
||||
skipDecamelize: true,
|
||||
},
|
||||
abortController,
|
||||
);
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import { decamelizeKeys } from "humps";
|
||||
|
||||
import * as api from "./base";
|
||||
import { DNSProvider } from "./models";
|
||||
|
||||
@@ -9,9 +11,18 @@ export async function setDNSProvider(
|
||||
delete data.id;
|
||||
}
|
||||
|
||||
// Because the meta property of the data should not be decamelized,
|
||||
// we're going to decamelize the rest here instead of in base.ts
|
||||
let dcData: any = decamelizeKeys(data);
|
||||
if (typeof data.meta !== "undefined") {
|
||||
dcData.meta = data.meta;
|
||||
}
|
||||
|
||||
const { result } = await api.put({
|
||||
url: `/dns-providers/${id}`,
|
||||
data,
|
||||
data: dcData,
|
||||
skipCamelize: true,
|
||||
skipDecamelize: true,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user