legacy-appointment-deletions.mjs 967 B

123456789101112
  1. import {readFileSync} from 'node:fs';
  2. export function buildAppointmentDeletionGateway(company,windows=[]){
  3. const read=name=>readFileSync(new URL('../cloud/'+name+'.js',import.meta.url),'utf8');
  4. const code=(read('legacy-writing-sync-ownership')+'\n'+read('legacy-appointment-deletions')).replaceAll('__COMPANY_ID__',JSON.stringify(company)).replaceAll('__WINDOWS__',JSON.stringify(windows));
  5. new Function(code);return code;
  6. }
  7. export function patchAppointmentDeletionCapability(code){
  8. if(code.includes("appointmentDeletionVersion:'confirmed-ids-v1'"))return code;
  9. const handler=code.indexOf('async function handler(request,response)'),at=code.indexOf(" if(p.action===",handler);
  10. if(handler<0||at<handler)throw Error('Unknown direct sync handler');
  11. 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);
  12. }