Koleksi Orders menyimpan order state, shipping, payment, address, dan follow-up config. Field followup_step melacak checkpoint percakapan, proof_pending_verification menahan reminder tertentu.
Model
models/orders.js:197 — orderSchema, mongoose.model("Orders", orderSchema).
Field utama
| Field | Tipe | Catatan |
|---|---|---|
id | String | Primary key (UUID) — require: true |
order_number | String | require: true |
device_id | String | Device WhatsApp + order scope |
customer_id | String | Customer scope |
sequence | Number | Rawan race — latest value + increment tanpa atomic counter |
payment_method | String | Dideklarasikan dua kali (lihat di bawah) |
store_id | String | Tenant scope |
total_price | Number | Default 0 — jumlah item snapshot, belum termasuk shipping bila code pemanggil menambah shipping terpisah |
constraint_customer | String | Default null |
team_id | String | require: true |
progress_order | String | require: true |
progress_follow_up | String | require: true |
order_via | String | Default "whatsapp" |
followup_step | String | Default null — checkpoint aktif (lihat di bawah) |
last_follow_up_date | Date | require: true |
last_progress_order | String | require: true |
status | String | Default "pending" — pending, process, cancel |
payment_status | String | Default "unpaid" — unpaid, paid |
rating | Number | Default 0 |
proof_transaction | String | Default null — URL bukti transfer |
proof_pending_verification | Boolean | Default false — menahan reminder tertentu |
message_status | Object | welcome, follow_up_1–follow_up_4 |
utm_source … utm_content | String | UTM tracking |
created_at, updated_at | Date | Mongoose timestamps |
Shipping
shipping: {
name, description, etd, // String, default null
service, code, resi, // String, default null
cost: Number, default null,
courier: Schema.Types.Mixed, // default null
}Addresses
addresses: {
id: Number, default null,
province, city, district, subdistrict, postal_code, village, address: String
}variant_product
variant_product: {
name_variant, sku, id: String,
harga_normal, hpp, stok, harga_spesial, berat: Number,
}Follow-up config (followUp)
followUpSchema (models/orders.js:6-195) — Mustache template per metode pembayaran:
| Checkpoint | Sub-key | Fungsi |
|---|---|---|
welcome | bank_transfer, cod, epayment | Pesan welcome + detail order |
order_detail | sama | Pesanan detail |
follow_up_1–follow_up_4 | sama | Reminder bertahap |
processing | sama | Pembayaran diterima, proses packing |
completed | sama | Pesanan selesai |
up_selling | sama | Promo |
redirect | sama | Redirect ke admin |
Setiap sub-key memiliki:
| Field | Tipe | Catatan |
|---|---|---|
text | String | Mustache template — {{product_name}}, {{total_price}}, {{bank_accounts}}, dll. |
image | String | Default null — optional attachment URL |
otomatic_send | Boolean | Default false |
Follow-up checkpoint valid
Checkpoint yang aktif di setOrderFollowup:
| Checkpoint | Butuh order? |
|---|---|
call_to_order | ❌ |
ask_product_qty | ❌ |
ask_shipping_address | ✅ |
ask_shipping_method | ✅ |
ask_payment_method | ✅ |
confirm_order | ✅ |
payment_reminder | ✅ |
Lihat Order Flow untuk detail alur.
message_status
message_status: {
welcome: String, // default null
follow_up_1: String, // default null
follow_up_2: String, // default null
follow_up_3: String, // default null
follow_up_4: String, // default null
}Inkonsistensi yang diketahui
Relasi
| Relasi | Field |
|---|---|
Orders → Order_Items | order_items.order_id = orders.id (custom string, bukan _id) |
Orders → customers | orders.customer_id = customers.id |
Orders → carts | via customer_id (cart dihapus saat checkout) |
Orders → agents | via store_id + agent context |
Cara akses di service
// service/order.js
const order = await Order.findOne({ id: orderNumber, store_id: storeId });
const items = await OrderItem.find({ order_id: order.id });Kembali ke
- Schema Index — daftar semua koleksi
- Order Flow — alur checkout lengkap
- Follow-up Scheduler — cara reminder dikirim