/opt/mawid/apps/api/src/waitlist
Edit: /opt/mawid/apps/api/src/waitlist/waitlist-reply.service.ts (805B)
import { Injectable } from '@nestjs/common';
import { WaitlistService } from './waitlist.service';
const BUTTON_RE = /^wl_(yes|no):([a-z0-9]+)$/i;
/** Routes waitlist offer button taps (wl_yes / wl_no) to the waitlist service. */
@Injectable()
export class WaitlistReplyService {
constructor(private readonly waitlist: WaitlistService) {}
/** Returns true when the message was a waitlist button and has been handled. */
async tryHandle(clinicId: string, patientId: string, body: string): Promise
{
const match = BUTTON_RE.exec(body.trim());
if (!match) return false;
const [, answer, holdId] = match;
return answer.toLowerCase() === 'yes'
? this.waitlist.acceptHold(clinicId, patientId, holdId)
: this.waitlist.declineHold(clinicId, patientId, holdId);
}
}