Files
doormile_backend/scratch/seed_pin_customer.go
Suriyakumarvijayanayagam 29e189b7e0 chore: seed a PIN-ready test customer (+919000001234 / 1234)
scratch/seed_pin_customer.go (//go:build ignore, idempotent) — one customer with
PIN 1234 already set, for testing the interim /customer/auth/verify-pin flow.
Phone stored in normalised +91 form so CxPinLogin/CxVerifyPin find it. Run
against live: appcustomerid 300.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WRaFH5hMRqmUQvVPQsyjZD
2026-09-21 16:26:49 +05:30

71 lines
1.8 KiB
Go

//go:build ignore
// seed_pin_customer.go — one ready-to-use customer for testing the interim PIN
// login flow: phone +919000001234, PIN 1234, already set. Idempotent (re-running
// just re-asserts the PIN to 1234).
//
// The phone is stored in NORMALISED +91 form, because CxPinLogin/CxVerifyPin
// normalise the entered number to +91 before the DB lookup — a bare 10-digit
// row would never be found.
//
// Run: go run scratch/seed_pin_customer.go
package main
import (
"fmt"
"log"
"doormile/config"
"doormile/db"
"doormile/models"
"doormile/utils"
"github.com/joho/godotenv"
)
func main() {
_ = godotenv.Load()
cfg := config.Load()
db.Connect(cfg)
if db.DB == nil {
log.Fatal("DB connection is nil")
}
const phone = "+919000001234" // customer types 9000001234; it normalises to this
pinHash, err := utils.HashPassword("1234")
if err != nil {
log.Fatalf("hash: %v", err)
}
var c models.AppCustomer
if db.DB.Where("phone = ?", phone).First(&c).Error != nil {
c = models.AppCustomer{
Firstname: "Test",
Lastname: "PinCustomer",
Phone: phone,
Email: "test.pin@doormile.in",
Loginpinhash: pinHash,
Defaultlatitude: 11.0168,
Defaultlongitude: 76.9558,
Defaultpincode: "641012",
Status: "Active",
Configid: 1001,
}
if err := db.DB.Create(&c).Error; err != nil {
log.Fatalf("create: %v", err)
}
fmt.Println("created customer with PIN 1234")
} else {
c.Loginpinhash = pinHash
c.Status = "Active"
if err := db.DB.Save(&c).Error; err != nil {
log.Fatalf("update: %v", err)
}
fmt.Println("customer already existed — PIN re-asserted to 1234")
}
fmt.Printf("\n✅ ready: appcustomerid=%d phone=%s login-as=9000001234 pin=1234\n",
c.Appcustomerid, c.Phone)
}