feat(profile): add counterparty card with dadata search and cart gating

This commit is contained in:
Ruslan Bakiev
2026-04-02 16:47:27 +07:00
parent f4a4b41dd5
commit d72de0f8c3
10 changed files with 879 additions and 41 deletions

View File

@@ -0,0 +1,45 @@
type DadataBankSuggestion = {
value: string;
unrestricted_value?: string;
data?: {
bic?: string;
correspondent_account?: string;
};
};
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig(event);
const token = String(config.dadataApiToken || '').trim();
if (!token) {
throw createError({
statusCode: 500,
statusMessage: 'DADATA_API_TOKEN is not configured.',
});
}
const body = await readBody<{ query?: string }>(event);
const query = String(body?.query ?? '').trim();
if (query.length < 2) {
return { suggestions: [] as DadataBankSuggestion[] };
}
const response = await $fetch<{ suggestions?: DadataBankSuggestion[] }>(
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/bank',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Token ${token}`,
},
body: {
query,
count: 10,
},
},
);
return {
suggestions: response.suggestions ?? [],
};
});

View File

@@ -0,0 +1,53 @@
type DadataPartySuggestion = {
value: string;
unrestricted_value?: string;
data?: {
inn?: string;
kpp?: string;
ogrn?: string;
address?: {
value?: string;
};
management?: {
name?: string;
post?: string;
};
};
};
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig(event);
const token = String(config.dadataApiToken || '').trim();
if (!token) {
throw createError({
statusCode: 500,
statusMessage: 'DADATA_API_TOKEN is not configured.',
});
}
const body = await readBody<{ query?: string }>(event);
const query = String(body?.query ?? '').trim();
if (query.length < 2) {
return { suggestions: [] as DadataPartySuggestion[] };
}
const response = await $fetch<{ suggestions?: DadataPartySuggestion[] }>(
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/party',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Token ${token}`,
},
body: {
query,
count: 10,
},
},
);
return {
suggestions: response.suggestions ?? [],
};
});