шлется на реальный сервер (#2)
build-and-deploy / prepare (push) Successful in 0s
build-and-deploy / build-and-push (., Dockerfile, hr-appeals-web) (push) Successful in 8s
Tests / frontend-test (push) Successful in 11s
build-and-deploy / build-and-push (server, server/Dockerfile, hr-appeals-auth) (push) Successful in 4s
build-and-deploy / deploy (push) Successful in 15s

Co-authored-by: Mariya Trishina <trishina.mariya@tnsu.kz>
Reviewed-on: http://git.tnsu.kz/gorbenko.pavel/hr-appeals/pulls/2
This commit was merged in pull request #2.
This commit is contained in:
2026-08-24 08:54:41 +00:00
parent 7f6f42a96b
commit dea024f3a9
23 changed files with 660 additions and 73 deletions
+77
View File
@@ -0,0 +1,77 @@
import { resolveCompanyName } from './companies';
import { config } from './config';
import { getAppOnlyToken } from './graphAuth';
const SHAREPOINT_API_URL = 'https://api.tnsu.kz/SharePoint/ListItem';
export type AppealKind = 'complaint' | 'suggestion' | 'other';
const KIND_LABELS: Record<AppealKind, string> = {
complaint: 'Обращение',
suggestion: 'Предложение',
other: 'Другое'
};
export interface IFeedbackSubmission {
company: string;
isAnonymous: boolean;
fullName: string;
position: string;
wantsFeedback: boolean;
kind: AppealKind;
kindOther: string;
situation: string;
suggestion: string;
}
// Имена полей — internal name столбцов списка SharePoint (Company/Name/Position/
// Type/IssueDescription/SuggestionText/WantsFeedback), не отображаемые названия.
async function buildFields(data: IFeedbackSubmission): Promise<Record<string, unknown>> {
const typeLabel = data.kind === 'other' ? data.kindOther : KIND_LABELS[data.kind];
const name = data.isAnonymous ? '' : data.fullName;
const fields: Record<string, unknown> = {
Title: name ? `${typeLabel} — ${name}` : typeLabel,
Company: await resolveCompanyName(data.company),
Name: name,
Position: data.isAnonymous ? '' : data.position,
Type: typeLabel,
IssueDescription: data.situation,
SuggestionText: data.suggestion,
WantsFeedback: data.wantsFeedback
};
// Состав полей зависит от вида обращения и анонимности, поэтому часть строк
// заведомо пустая (у предложения нет описания ситуации, у анонимного — ФИО).
// Такие поля не отправляем вовсе: пустая строка в списке выглядит как
// заполненное значение, а не как «поля не было». WantsFeedback при этом
// остаётся всегда — false здесь осмысленное значение, а не пустота.
return Object.fromEntries(
Object.entries(fields)
.map(([key, value]) => [key, typeof value === 'string' ? value.trim() : value])
.filter(([, value]) => value !== '')
);
}
export async function submitFeedback(data: IFeedbackSubmission): Promise<void> {
const token = await getAppOnlyToken();
const response = await fetch(SHAREPOINT_API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify({
siteUrl: config.sharepointSiteUrl,
listName: config.sharepointListName,
fields: await buildFields(data)
})
});
if (!response.ok) {
throw new Error(
`api.tnsu.kz вернул ошибку при создании элемента списка: ${response.status} ${await response.text()}`
);
}
}