2026-03-12 17:44:02 +07:00
|
|
|
'use server'
|
|
|
|
|
|
|
|
|
|
import { getSessionData } from '@/app/actions/session';
|
2026-04-07 19:05:44 +07:00
|
|
|
import { API_BASE_URL, createComplaintSchema, createCaseSchema } from '@/app/actions/definitions';
|
2026-03-12 17:44:02 +07:00
|
|
|
|
|
|
|
|
export async function getViolationSearchStatus() {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/global-search/actual-task`, {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Authorization': `Bearer ${token}`,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
2026-03-13 13:42:07 +07:00
|
|
|
const text = await response.text();
|
|
|
|
|
|
|
|
|
|
if (text) {
|
|
|
|
|
try {
|
|
|
|
|
const parsed = JSON.parse(text);
|
2026-03-26 17:30:30 +07:00
|
|
|
|
2026-03-13 13:42:07 +07:00
|
|
|
return parsed;
|
|
|
|
|
} catch (e) {
|
2026-03-26 17:30:30 +07:00
|
|
|
|
2026-03-13 13:42:07 +07:00
|
|
|
return {
|
|
|
|
|
status: text === 'Task not found' ? 'task-not-found' : text
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2026-03-12 17:44:02 +07:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function startGlobalMonitoring(monitoringType: 'monitoring' | 'all_files') {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/global-search/start`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
2026-03-13 13:42:07 +07:00
|
|
|
searchType: monitoringType,
|
|
|
|
|
...(monitoringType === 'all_files' && { fileIds: [] })
|
|
|
|
|
|
2026-03-12 17:44:02 +07:00
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Authorization': `Bearer ${token}`,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
2026-03-13 13:42:07 +07:00
|
|
|
const parsed: {
|
|
|
|
|
taskId: string,
|
|
|
|
|
status: string,
|
|
|
|
|
totalFiles: number
|
|
|
|
|
} = await response.json();
|
|
|
|
|
|
|
|
|
|
if (parsed?.status === 'ACCEPTED') {
|
2026-03-12 17:44:02 +07:00
|
|
|
return parsed
|
|
|
|
|
} else {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
2026-03-16 17:12:52 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getViolationFilesArray() {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/global-search/violation-summary`, {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Authorization': `Bearer ${token}`,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
2026-03-27 22:31:34 +07:00
|
|
|
|
2026-03-16 17:12:52 +07:00
|
|
|
if (parsed.length) {
|
|
|
|
|
return parsed;
|
|
|
|
|
} else {
|
|
|
|
|
throw parsed;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* статистика нурешений */
|
|
|
|
|
export async function fetchViolationStats() {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 30010,
|
|
|
|
|
message_body: {
|
|
|
|
|
token: token
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
|
|
|
|
if (parsed) {
|
|
|
|
|
return parsed;
|
|
|
|
|
} else {
|
|
|
|
|
throw null;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 14:05:55 +07:00
|
|
|
export async function getFileViolations(fileId: string, page: number, status?: string, violationId?: string) {
|
2026-03-18 18:09:33 +07:00
|
|
|
const token = await getSessionData('token');
|
2026-03-16 17:12:52 +07:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 30009,
|
|
|
|
|
message_body: {
|
|
|
|
|
file_id: fileId,
|
|
|
|
|
page: page,
|
|
|
|
|
size: 5,
|
2026-04-22 14:05:55 +07:00
|
|
|
sort_direction: 'desc',
|
2026-03-27 16:45:58 +07:00
|
|
|
token: token,
|
2026-04-22 14:05:55 +07:00
|
|
|
status: status,
|
|
|
|
|
...(violationId && { action: 'getByViolationId' }),
|
|
|
|
|
...(violationId && { violation_id: violationId })
|
2026-03-16 17:12:52 +07:00
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
2026-03-27 22:31:34 +07:00
|
|
|
|
2026-03-16 17:12:52 +07:00
|
|
|
if (parsed.message_body) {
|
|
|
|
|
return parsed.message_body;
|
|
|
|
|
} else {
|
|
|
|
|
throw null;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
2026-03-18 18:09:33 +07:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 12:49:46 +07:00
|
|
|
export async function fetchViolationAnalyticStatistic(group: 'domain' | 'tld') {
|
2026-03-18 18:09:33 +07:00
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 30009,
|
|
|
|
|
message_body: {
|
2026-03-19 12:49:46 +07:00
|
|
|
group_by: group,
|
|
|
|
|
action: "group",
|
|
|
|
|
token: token,
|
|
|
|
|
sort_direction: 'desc'
|
2026-03-18 18:09:33 +07:00
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
2026-03-19 12:49:46 +07:00
|
|
|
|
|
|
|
|
if (parsed?.message_body) {
|
|
|
|
|
return parsed?.message_body;
|
|
|
|
|
} else {
|
|
|
|
|
throw null;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchViolationStatistic() {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 30010,
|
|
|
|
|
message_body: {
|
|
|
|
|
token: token,
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
|
|
|
|
|
|
|
|
|
if (parsed?.message_body) {
|
|
|
|
|
return parsed?.message_body;
|
2026-03-18 18:09:33 +07:00
|
|
|
} else {
|
|
|
|
|
throw null;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
2026-03-26 17:30:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface complainBody {
|
|
|
|
|
previousText: string,
|
2026-03-27 15:10:06 +07:00
|
|
|
violationID: string | null,
|
|
|
|
|
success: boolean,
|
2026-03-31 14:47:39 +07:00
|
|
|
errorMessage?: Record<string, string> | null
|
2026-03-26 17:30:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function createComplaint(
|
|
|
|
|
state: complainBody | undefined,
|
|
|
|
|
formData: FormData
|
|
|
|
|
): Promise<complainBody> {
|
|
|
|
|
const email = await getSessionData('email');
|
|
|
|
|
const violationId = formData.get('violationId') as string || '';
|
2026-03-31 14:47:39 +07:00
|
|
|
const textArea = formData.get('note') as string || '';
|
|
|
|
|
|
|
|
|
|
const validatedFields = createComplaintSchema.safeParse({
|
|
|
|
|
textArea
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!validatedFields.success) {
|
|
|
|
|
const errors: Record<string, string> = {}
|
|
|
|
|
JSON.parse(validatedFields.error.message).forEach((obj: {
|
|
|
|
|
message: string,
|
|
|
|
|
path: string
|
|
|
|
|
}) => {
|
|
|
|
|
if (errors[obj.path[0]]) {
|
|
|
|
|
errors[obj.path[0]] = `${errors[obj.path[0]]} ${obj.message}`;
|
|
|
|
|
} else {
|
|
|
|
|
errors[obj.path[0]] = obj.message;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
violationID: violationId,
|
|
|
|
|
previousText: textArea,
|
|
|
|
|
success: false,
|
|
|
|
|
errorMessage: errors
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-26 17:30:30 +07:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 30013,
|
|
|
|
|
message_body: {
|
|
|
|
|
action: 'create',
|
|
|
|
|
violation_id: violationId,
|
2026-03-31 14:47:39 +07:00
|
|
|
text: textArea,
|
2026-03-26 17:30:30 +07:00
|
|
|
email: email
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
|
|
|
|
|
|
|
|
|
if (parsed?.message_code === 0) {
|
|
|
|
|
return {
|
2026-03-27 15:10:06 +07:00
|
|
|
violationID: violationId,
|
2026-03-31 14:47:39 +07:00
|
|
|
previousText: textArea,
|
2026-03-26 17:30:30 +07:00
|
|
|
success: true
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
throw parsed;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
2026-03-31 14:47:39 +07:00
|
|
|
} catch (error) {
|
|
|
|
|
const errors: Record<string, string> = {}
|
|
|
|
|
|
2026-03-27 15:10:06 +07:00
|
|
|
if (error && typeof error === 'object' && 'message_code' in error) {
|
|
|
|
|
const err = error as { message_code: number };
|
|
|
|
|
if (err.message_code === 2) {
|
2026-03-31 14:47:39 +07:00
|
|
|
errors['server'] = 'the-complaint-has-not-been-registered'
|
|
|
|
|
|
2026-03-27 15:10:06 +07:00
|
|
|
return {
|
|
|
|
|
violationID: violationId,
|
2026-03-31 14:47:39 +07:00
|
|
|
previousText: textArea,
|
2026-03-27 15:10:06 +07:00
|
|
|
success: false,
|
2026-03-31 14:47:39 +07:00
|
|
|
errorMessage: errors
|
2026-03-27 15:10:06 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-31 14:47:39 +07:00
|
|
|
errors['server'] = 'error-save';
|
2026-03-27 15:10:06 +07:00
|
|
|
|
2026-03-26 17:30:30 +07:00
|
|
|
return {
|
2026-03-27 15:10:06 +07:00
|
|
|
violationID: violationId,
|
2026-03-31 14:47:39 +07:00
|
|
|
previousText: textArea,
|
2026-03-27 15:10:06 +07:00
|
|
|
success: false,
|
2026-03-31 14:47:39 +07:00
|
|
|
errorMessage: errors
|
2026-03-26 17:30:30 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchComplainInfo(id: number) {
|
2026-04-22 14:05:55 +07:00
|
|
|
const token = await getSessionData('token');
|
2026-03-26 17:30:30 +07:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 30013,
|
|
|
|
|
message_body: {
|
|
|
|
|
action: 'get_by_violation',
|
2026-04-22 14:05:55 +07:00
|
|
|
violation_id: id,
|
|
|
|
|
token
|
2026-03-26 17:30:30 +07:00
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
|
|
|
|
|
|
|
|
|
if (parsed?.message_code === 0) {
|
|
|
|
|
return {
|
|
|
|
|
body: parsed?.message_body
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw parsed;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return {
|
|
|
|
|
errorMessage: 'error'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 13:50:41 +07:00
|
|
|
export type MatchStatus = 'NEW' | 'SHOWED' | 'LEGAL_IN_WORK' | 'COMPLAINT_IN_WORK' | 'COMPLAINT_AND_LEGAL_IN_WORK' | 'AUTHORIZED_USE';
|
|
|
|
|
|
|
|
|
|
export async function updateMatchStatus(id: number, status: MatchStatus) {
|
2026-03-26 17:30:30 +07:00
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 30009,
|
|
|
|
|
message_body: {
|
|
|
|
|
action: 'updateStatus',
|
|
|
|
|
violation_id: id,
|
|
|
|
|
status: status,
|
|
|
|
|
token: token
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
|
|
|
|
|
2026-03-27 13:50:41 +07:00
|
|
|
if (parsed?.message_body.status) {
|
2026-03-26 17:30:30 +07:00
|
|
|
return true
|
|
|
|
|
} else {
|
|
|
|
|
throw parsed;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2026-04-07 19:05:44 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchCaseInfo(id: number) {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
/* body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 30017,
|
|
|
|
|
message_body: {
|
|
|
|
|
action: 'get_byId',
|
|
|
|
|
token: token,
|
|
|
|
|
id: id
|
|
|
|
|
}
|
|
|
|
|
}), */
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 30017,
|
|
|
|
|
message_body: {
|
|
|
|
|
action: 'get_all',
|
|
|
|
|
token: token,
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
pageNumber: 0,
|
2026-04-20 16:08:10 +07:00
|
|
|
sortBy: "createdAt",
|
2026-04-07 19:05:44 +07:00
|
|
|
sortDir: "desc",
|
|
|
|
|
violation_id: id
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
|
|
|
|
|
|
|
|
|
if (parsed?.message_code === 0) {
|
|
|
|
|
return {
|
|
|
|
|
body: parsed?.message_body
|
|
|
|
|
}
|
|
|
|
|
} else if (parsed?.message_code !== 0 && parsed?.message_desc === 'Law case not found') {
|
|
|
|
|
return {
|
|
|
|
|
body: null
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw parsed;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return {
|
|
|
|
|
errorMessage: 'error'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface caseBody {
|
|
|
|
|
previousText: string,
|
|
|
|
|
previousCaseTitle: string,
|
|
|
|
|
violationID: string | null,
|
|
|
|
|
success: boolean,
|
|
|
|
|
errorMessage?: Record<string, string> | null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function createCase(
|
|
|
|
|
state: caseBody | undefined,
|
|
|
|
|
formData: FormData
|
|
|
|
|
): Promise<caseBody> {
|
|
|
|
|
const email = await getSessionData('email');
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
const violationId = formData.get('violationId') as string || '';
|
|
|
|
|
const textArea = formData.get('note') as string || '';
|
|
|
|
|
const caseTitle = formData.get('caseTitle') as string || '';
|
|
|
|
|
const amount = formData.get('amount') as string || '';
|
|
|
|
|
|
|
|
|
|
const validatedFields = createCaseSchema.safeParse({
|
|
|
|
|
textArea,
|
|
|
|
|
caseTitle
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!validatedFields.success) {
|
|
|
|
|
const errors: Record<string, string> = {}
|
|
|
|
|
JSON.parse(validatedFields.error.message).forEach((obj: {
|
|
|
|
|
message: string,
|
|
|
|
|
path: string
|
|
|
|
|
}) => {
|
|
|
|
|
if (errors[obj.path[0]]) {
|
|
|
|
|
errors[obj.path[0]] = `${errors[obj.path[0]]} ${obj.message}`;
|
|
|
|
|
} else {
|
|
|
|
|
errors[obj.path[0]] = obj.message;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
violationID: violationId,
|
|
|
|
|
previousText: textArea,
|
|
|
|
|
previousCaseTitle: caseTitle,
|
|
|
|
|
success: false,
|
|
|
|
|
errorMessage: errors
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 30017,
|
|
|
|
|
message_body: {
|
|
|
|
|
action: 'create',
|
|
|
|
|
violation_id: violationId,
|
|
|
|
|
description: textArea,
|
|
|
|
|
email: email,
|
|
|
|
|
token: token,
|
|
|
|
|
name: caseTitle,
|
|
|
|
|
priority: 'HIGH',
|
|
|
|
|
amount: Number(amount)
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
|
|
|
|
|
|
|
|
|
if (parsed?.message_code === 0) {
|
|
|
|
|
return {
|
|
|
|
|
violationID: violationId,
|
|
|
|
|
previousCaseTitle: caseTitle,
|
|
|
|
|
previousText: textArea,
|
|
|
|
|
success: true
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
throw parsed;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const errors: Record<string, string> = {}
|
|
|
|
|
|
|
|
|
|
if (error && typeof error === 'object' && 'message_code' in error) {
|
|
|
|
|
const err = error as { message_code: number };
|
|
|
|
|
if (err.message_code === 2) {
|
|
|
|
|
errors['server'] = 'the-complaint-has-not-been-registered'
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
violationID: violationId,
|
|
|
|
|
previousText: textArea,
|
|
|
|
|
previousCaseTitle: caseTitle,
|
|
|
|
|
success: false,
|
|
|
|
|
errorMessage: errors
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
errors['server'] = 'error-save';
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
violationID: violationId,
|
|
|
|
|
previousText: textArea,
|
|
|
|
|
previousCaseTitle: caseTitle,
|
|
|
|
|
success: false,
|
|
|
|
|
errorMessage: errors
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-16 17:34:14 +07:00
|
|
|
}
|
|
|
|
|
|
2026-04-20 16:08:10 +07:00
|
|
|
export interface ComplaintsCaseQueryParams {
|
|
|
|
|
page?: number,
|
|
|
|
|
size?: number,
|
|
|
|
|
sort_by?: string,
|
|
|
|
|
sort_direction?: 'desc' | 'asc'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchLastCase(params: ComplaintsCaseQueryParams) {
|
2026-04-16 17:34:14 +07:00
|
|
|
const token = await getSessionData('token');
|
2026-04-20 16:08:10 +07:00
|
|
|
const { page, size, sort_by, sort_direction } = params;
|
2026-04-16 17:34:14 +07:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 30017,
|
|
|
|
|
message_body: {
|
|
|
|
|
action: "get_all",
|
2026-04-20 16:08:10 +07:00
|
|
|
token: token,
|
|
|
|
|
page,
|
|
|
|
|
size,
|
|
|
|
|
sort_by,
|
|
|
|
|
sort_direction
|
2026-04-16 17:34:14 +07:00
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
2026-04-20 16:08:10 +07:00
|
|
|
|
|
|
|
|
if (parsed.message_code === 0) {
|
|
|
|
|
return parsed.message_body;
|
2026-04-16 17:34:14 +07:00
|
|
|
} else {
|
|
|
|
|
throw null;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-20 16:08:10 +07:00
|
|
|
export async function fetchLastComplaint(params: ComplaintsCaseQueryParams) {
|
2026-04-16 17:34:14 +07:00
|
|
|
const token = await getSessionData('token');
|
2026-04-20 16:08:10 +07:00
|
|
|
const { page, size, sort_by, sort_direction } = params;
|
2026-04-16 17:34:14 +07:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
2026-04-20 16:08:10 +07:00
|
|
|
msg_id: 30013,
|
2026-04-16 17:34:14 +07:00
|
|
|
message_body: {
|
|
|
|
|
action: "get_all",
|
2026-04-20 16:08:10 +07:00
|
|
|
token: token,
|
|
|
|
|
page,
|
|
|
|
|
size,
|
|
|
|
|
sort_by,
|
|
|
|
|
sort_direction
|
2026-04-16 17:34:14 +07:00
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
2026-04-20 16:08:10 +07:00
|
|
|
|
|
|
|
|
if (parsed.message_code === 0) {
|
|
|
|
|
return parsed.message_body;
|
2026-04-16 17:34:14 +07:00
|
|
|
} else {
|
|
|
|
|
throw null;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
2026-03-12 17:44:02 +07:00
|
|
|
}
|