oportunidades 8
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-14 08:25:30 +02:00
parent 287e991486
commit ba1c0340ea
9112 changed files with 2199795 additions and 856 deletions
@@ -0,0 +1,38 @@
export class ProfileValidationError extends Error {
constructor(
message: string,
public readonly fields: Record<string, string>,
) {
super(message);
}
}
export async function profileJson(
url: string,
data: object = {},
method: 'GET' | 'POST' = 'POST',
) {
const cookie = document.cookie
.split('; ')
.find((c) => c.startsWith('XSRF-TOKEN='));
const response = await fetch(url, {
method,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-XSRF-TOKEN': cookie ? decodeURIComponent(cookie.slice(11)) : '',
},
...(method === 'GET' ? {} : { body: JSON.stringify(data) }),
});
const result = await response.json();
if (!response.ok)
throw new ProfileValidationError(
result.message ?? 'A ação não foi concluída.',
Object.fromEntries(
Object.entries(result.errors ?? {}).map(([key, value]) => [
key,
Array.isArray(value) ? value.join(' ') : String(value),
]),
),
);
return result;
}