72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
export enum NotificationJobStatus {
|
|
PENDING = "pending",
|
|
PROCESSING = "processing",
|
|
SENT = "sent",
|
|
FAILED = "failed",
|
|
CANCELLED = "cancelled",
|
|
}
|
|
|
|
export type NotificationChannel = "whatsapp" | "email" | "system";
|
|
|
|
export type NotificationJobType =
|
|
| "creation"
|
|
| "reminder"
|
|
| "update"
|
|
| "cancellation";
|
|
|
|
export interface NotificationJobPayload {
|
|
email?: string;
|
|
phoneNumber?: string;
|
|
userId?: string;
|
|
companyOwnerId?: string;
|
|
subject?: string;
|
|
message?: string;
|
|
emailSubject?: string;
|
|
emailMessage?: string;
|
|
wapMessage?: string;
|
|
systemSubject?: string;
|
|
systemMessage?: string;
|
|
}
|
|
|
|
export interface INotificationJob {
|
|
id?: string;
|
|
companyId: string;
|
|
appointmentId: string;
|
|
clientId: string;
|
|
channel: NotificationChannel;
|
|
type: NotificationJobType;
|
|
scheduledAt: Date;
|
|
status: NotificationJobStatus;
|
|
attempts: number;
|
|
maxAttempts: number;
|
|
lastError?: string;
|
|
nextRetryAt?: Date;
|
|
providerResponse?: string;
|
|
payload?: NotificationJobPayload;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
sentAt?: Date;
|
|
}
|
|
|
|
export interface CreateJobParams {
|
|
companyId: string;
|
|
appointmentId: string;
|
|
clientId: string;
|
|
channel: NotificationChannel;
|
|
type: NotificationJobType;
|
|
scheduledAt: Date;
|
|
payload?: NotificationJobPayload;
|
|
}
|
|
|
|
export interface INotificationJobAdapter {
|
|
create(data: CreateJobParams): Promise<INotificationJob>;
|
|
findPendingDue(now: Date): Promise<INotificationJob[]>;
|
|
updateStatus(
|
|
jobId: string,
|
|
status: NotificationJobStatus,
|
|
data?: { lastError?: string; nextRetryAt?: Date; providerResponse?: string }
|
|
): Promise<void>;
|
|
cancelByAppointment(appointmentId: string): Promise<void>;
|
|
findByAppointment(appointmentId: string): Promise<INotificationJob[]>;
|
|
}
|