legacy-appointment-deletions.mjs 886 B

1234567891011
  1. import {readFileSync} from 'node:fs';
  2. export function buildAppointmentDeletionGateway(company,windows=[]){
  3. const code=readFileSync(new URL('../cloud/legacy-appointment-deletions.js',import.meta.url),'utf8').replaceAll('__COMPANY_ID__',JSON.stringify(company)).replaceAll('__WINDOWS__',JSON.stringify(windows));
  4. new Function(code);return code;
  5. }
  6. export function patchAppointmentDeletionCapability(code){
  7. if(code.includes("appointmentDeletionVersion:'confirmed-ids-v1'"))return code;
  8. const handler=code.indexOf('async function handler(request,response)'),at=code.indexOf(" if(p.action===",handler);
  9. if(handler<0||at<handler)throw Error('Unknown direct sync handler');
  10. return code.slice(0,at)+" if(p.action==='status'){const result=await directControl(p,co,u);return response.json({success:true,data:{...result,appointmentDeletionVersion:'confirmed-ids-v1'}});}\n"+code.slice(at);
  11. }