fix: изменил заявку на подбор согласно требованиям от 17.08.2026
Tests / frontend-test (push) Successful in 1m8s
Tests / frontend-test (push) Successful in 1m8s
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { AadHttpClient, HttpClientResponse } from '@microsoft/sp-http';
|
||||
import { WebPartContext } from '@microsoft/sp-webpart-base';
|
||||
import { APPROVAL_API_CLIENT_ID, DICTIONARY_API_BASE_URL } from '../config';
|
||||
import { ICompany } from './models/ICompany';
|
||||
|
||||
// GET /Dictionary/Companies — справочник компаний, ответ — плоский массив
|
||||
// { Id, Name } (без обёртки, как /Dictionary/Departments).
|
||||
async function fetchCompanies(context: WebPartContext): Promise<ICompany[]> {
|
||||
const client = await context.aadHttpClientFactory.getClient(APPROVAL_API_CLIENT_ID);
|
||||
const response: HttpClientResponse = await client.get(
|
||||
`${DICTIONARY_API_BASE_URL}/Dictionary/Companies`,
|
||||
AadHttpClient.configurations.v1
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Dictionary/Companies: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// Справочник в рамках сессии не меняется — грузим один раз и отдаём тот же
|
||||
// промис повторным вызовам (как в departments.service).
|
||||
let cache: Promise<ICompany[]> | undefined;
|
||||
export function getCompanies(context: WebPartContext): Promise<ICompany[]> {
|
||||
if (!cache) {
|
||||
cache = fetchCompanies(context).catch((e) => {
|
||||
cache = undefined;
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
Reference in New Issue
Block a user