CentralBackend/models/Abonemment.js

53 lines
2.2 KiB
JavaScript

class Abonemment {
constructor(row) {
this.id = row.id;
this.status = row.status;
this.started_at = row.started_at;
this.ended_at = row.ended_at;
this.next_billing_at = row.next_billing_at;
this.billing_interval = row.billing_interval;
this.interval_count = row.interval_count;
this.price = row.price;
this.currency = row.currency;
this.is_auto_renew = !!row.is_auto_renew;
this.notes = row.notes;
this.pack_group = row.pack_group;
this.pack_breakdown = row.pack_breakdown ? (typeof row.pack_breakdown === 'string' ? JSON.parse(row.pack_breakdown) : row.pack_breakdown) : null;
this.first_name = row.first_name;
this.last_name = row.last_name;
this.email = row.email;
this.street = row.street;
this.postal_code = row.postal_code;
this.city = row.city;
this.country = row.country;
this.frequency = row.frequency;
this.referred_by = row.referred_by; // NEW
this.purchaser_user_id = row.purchaser_user_id ?? null; // NEW
this.user_id = row.user_id ?? null; // NEW: map owner user_id
this.contract_number = row.contract_number ?? null;
this.contract_storage_key = row.contract_storage_key ?? null;
// Contact / invoice fields
this.phone = row.phone ?? null;
this.recipient_name = row.recipient_name ?? null;
this.recipient_address = row.recipient_address ?? null;
this.payment_method = row.payment_method ?? null;
this.invoice_by_email = !!row.invoice_by_email;
this.invoice_same_as_shipping = row.invoice_same_as_shipping !== undefined ? !!row.invoice_same_as_shipping : true;
this.invoice_full_name = row.invoice_full_name ?? null;
this.invoice_street = row.invoice_street ?? null;
this.invoice_postal_code = row.invoice_postal_code ?? null;
this.invoice_city = row.invoice_city ?? null;
this.invoice_phone = row.invoice_phone ?? null;
this.invoice_email = row.invoice_email ?? null;
this.created_at = row.created_at;
this.updated_at = row.updated_at;
}
get isActive() { return this.status === 'active'; }
get isPaused() { return this.status === 'paused'; }
get isCanceled() { return this.status === 'canceled'; }
get isExpired() { return this.status === 'expired'; }
}
module.exports = Abonemment;