forked from unimatrix/web
Merge branch 'main' of https://www.dunerealms.com/git/unimatrix/MC into dev/kit-atelier-v3
This commit is contained in:
commit
d5edec1907
1 changed files with 28 additions and 13 deletions
|
|
@ -117,7 +117,7 @@ export function createPostbankApi(central,bank,settings={},deps={}){
|
|||
}
|
||||
if(['/api/bank/admin/credit/decision','/api/bank/admin/credit/recover'].includes(path)){
|
||||
if(request.method!=='POST')return reply({message:'Method not allowed.'},405);if(request.headers.get('origin')!==origin)return reply({message:'Request origin rejected.'},403);if(!/^application\/json(?:;|$)/i.test(request.headers.get('content-type')||''))return reply({message:'JSON required.'},415);if(url.search)return reply({message:'Account overrides are not accepted.'},400);if(!creditEnabled)return reply({message:'Credit processing is not active.'},409);
|
||||
try{const raw=await request.text();if(raw.length>2500)return reply({message:'Request too large.'},413);const input=JSON.parse(raw),fresh=await auth(request);if(!fresh||fresh.id!==user.id)return reply({message:'Your session changed.'},403);if(!(await authority(fresh)).manageAdmin)return reply({message:'Bank management permission is required.'},403);const recovery=path.endsWith('/recover');if(recovery?input.action!=='recover':!['approve','decline'].includes(input.action))return reply({message:'Unknown staff credit action.'},400);return reply(await (recovery?creditEngine.requestRepayment(fresh,input,{revalidate:()=>auth(request)}):creditEngine.decision(fresh,input,{revalidate:()=>auth(request)})));}catch(error){return reply({message:error.status?error.message:'The credit instruction could not be confirmed.'},error.status||503);}
|
||||
try{const raw=await request.text();if(raw.length>2500)return reply({message:'Request too large.'},413);const input=JSON.parse(raw),fresh=await auth(request);if(!fresh||fresh.id!==user.id)return reply({message:'Your session changed.'},403);if(!(await authority(fresh)).manageAdmin)return reply({message:'Bank management permission is required.'},403);const recovery=path.endsWith('/recover');if(recovery?input.action!=='recover':!['approve','decline'].includes(input.action))return reply({message:'Unknown staff credit action.'},400);const result=await (recovery?creditEngine.requestRepayment(fresh,input,{revalidate:()=>auth(request)}):creditEngine.decision(fresh,input,{revalidate:()=>auth(request)}));if(!recovery){void bank.query("UPDATE pb_credit_support_jobs SET next_attempt=0 WHERE loan_id=? AND state<>'closed'",[input.loanId]).then(()=>creditSupport.process({loanId:input.loanId,limit:1})).catch(()=>{});return reply({...result,notice:input.action==='approve'?'Approval recorded. The linked Support ticket is updating. The borrower must accept the offer before payment at a four-hour bank window.':'Rejection recorded. The linked Support ticket is updating.'});}return reply(result);}catch(error){return reply({message:error.status?error.message:'The credit instruction could not be confirmed.'},error.status||503);}
|
||||
}
|
||||
if(['/api/bank/authorisations','/api/bank/authorisations/lookup','/api/bank/authorisations/change','/api/bank/admin/authorisations','/api/bank/admin/authorisations/lookup','/api/bank/admin/authorisations/change'].includes(path)){
|
||||
const staff=path.startsWith('/api/bank/admin/');
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff