Skip to content

Commit

Permalink
added single invoice by hash support for republishing
Browse files Browse the repository at this point in the history
  • Loading branch information
frnandu committed May 9, 2024
1 parent badb700 commit 47333eb
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cmd/invoice-republishing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ func main() {
fmt.Println("Failed to load .env file")
}
logger := lib.Logger(c.LogFilePath)
startDate, endDate, err := loadStartAndEndIdFromEnv()
if err != nil {
logger.Fatalf("Could not load start and end id from env %v", err)
}

err = envconfig.Process("", c)
if err != nil {
logger.Fatalf("Error loading environment variables: %v", err)
Expand Down Expand Up @@ -63,7 +60,20 @@ func main() {
defer rabbitmqClient.Close()

result := []models.Invoice{}
err = dbConn.NewSelect().Model(&result).Where("settled_at > ?", startDate).Where("settled_at < ?", endDate).Scan(context.Background())

singleInvoiceHash := os.Getenv("REPUBLISH_INVOICE_HASH")

if singleInvoiceHash != "" {
err = dbConn.NewSelect().Model(&result).Where("r_hash = ?", singleInvoiceHash).Scan(context.Background())
} else {
startDate, endDate, err1 := loadStartAndEndIdFromEnv()

if err1 != nil {
logger.Fatalf("Could not load start and end id from env %v", err1)
}

err = dbConn.NewSelect().Model(&result).Where("settled_at > ?", startDate).Where("settled_at < ?", endDate).Scan(context.Background())
}
if err != nil {
logger.Fatal(err)
}
Expand Down

0 comments on commit 47333eb

Please sign in to comment.