fixed subscription to transaction creation

This commit is contained in:
Fran Jurmanović
2021-06-20 17:19:52 +02:00
parent c251015497
commit 276771f349
2 changed files with 21 additions and 84 deletions

View File

@@ -90,9 +90,11 @@ func (as *SubscriptionService) SubToTrans(subModel *models.Subscription) {
}
if len(*transactions) > 0 {
as.Db.Model(transactions).Insert()
subModel.LastTransactionDate = (*transactions)[len(*transactions)-1].TransactionDate
as.Db.Model(subModel).WherePK().Update()
for _, trans := range *transactions {
_, err := as.Db.Model(&trans).Where("? = ?", pg.Ident("transaction_date"), trans.TransactionDate).Where("? = ?", pg.Ident("subscription_id"), trans.SubscriptionID).OnConflict("DO NOTHING").SelectOrInsert()
if err != nil {
as.Db.Model(subModel).Set("? = ?", pg.Ident("last_transaction_date"), trans.TransactionDate).WherePK().Update()
}
}
}
}