Files
Investidor-V2/docs/investmoz/education/examples/gap-calculator.mjs
T
nala 250ac35fd1
tests / ci (push) Canceled after 0s
first commit
2026-09-28 10:01:09 +02:00

48 lines
1.5 KiB
JavaScript

// PROPOSTA DIDACTICA. Dados sinteticos; nao integrado no Laravel ou no portal.
// Nao e IA nem apuramento oficial de lacunas. Nao modela alocacao entre projectos.
export function observedGap({
demand,
available,
context,
supplyContext,
sourceValid,
}) {
if (typeof sourceValid !== 'boolean')
throw new TypeError('Validade explicita obrigatoria');
const dimensions = [
'occupation',
'qualification',
'territory',
'period',
'unit',
];
for (const key of dimensions) {
if (
typeof context?.[key] !== 'string' ||
!context[key].trim() ||
typeof supplyContext?.[key] !== 'string' ||
!supplyContext[key].trim()
) {
throw new TypeError('Contexto completo obrigatorio');
}
}
for (const value of [demand, available]) {
if (value !== null && (!Number.isSafeInteger(value) || value < 0)) {
throw new TypeError('Quantidade inteira nao negativa ou null');
}
}
if (!sourceValid) return { state: 'expired', people: null };
if (
context.unit !== 'people' ||
dimensions.some((key) => context[key] !== supplyContext[key])
) {
return { state: 'incomparable', people: null };
}
if (demand === null || available === null)
return { state: 'insufficient_data', people: null };
return {
state: 'observed_unvalidated',
people: Math.max(0, demand - available),
};
}