vchikalkin bc27e6fd33 apps/web: add getPageUrlParams
remove title from Form components props type
2023-11-16 12:32:10 +03:00

56 lines
1.3 KiB
TypeScript

import type * as t from './types';
import { urls } from '@/config/urls';
import type { makeCreateUrl } from '@/utils/url';
import type { WretchError } from 'wretch';
import wretch from 'wretch';
const api = wretch(urls.URL_UIS).errorType('json');
type CreateUrl = ReturnType<typeof makeCreateUrl>;
export async function getData(createUrl: CreateUrl) {
const url = createUrl('');
return api
.get(url)
.res<t.ResponseGetData>((cb) => cb.json())
.then((res) => res);
}
export async function getMetaData(createUrl: CreateUrl) {
const url = createUrl('/meta');
return api
.get(url)
.res<t.ResponseMetaData>((res) => res.json())
.then((res) => res);
}
export async function getConfig(createUrl: CreateUrl) {
const url = createUrl('/config');
return api
.get(url)
.res<t.ResponseConfig>((res) => res.json())
.then((res) => res);
}
export async function getConditions(createUrl: CreateUrl) {
const url = createUrl('/conditions');
return api
.get(url)
.res<t.ResponseConditions>((res) => res.text())
.then((res) => res);
}
export async function validate(createUrl: CreateUrl) {
const url = createUrl('/validate');
return api
.post(url)
.res<boolean>((res) => res.ok)
.then((res) => res)
.catch((error: WretchError) => error.json as t.HttpValidationError);
}