mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-14 16:07:42 +00:00
try fetching device before account to reduce orphaned accounts
This commit is contained in:
parent
b5438495ec
commit
143ccfc05c
1 changed files with 11 additions and 11 deletions
|
@ -43,7 +43,7 @@ func (app *application) upsertAccountHandler(w http.ResponseWriter, r *http.Requ
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.logger.WithFields(logrus.Fields{
|
app.logger.WithFields(logrus.Fields{
|
||||||
"err": err,
|
"err": err,
|
||||||
}).Info("failed to grab user details")
|
}).Info("failed to grab user details from Reddit")
|
||||||
app.errorResponse(w, r, 500, err.Error())
|
app.errorResponse(w, r, 500, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -59,21 +59,21 @@ func (app *application) upsertAccountHandler(w http.ResponseWriter, r *http.Requ
|
||||||
// Set account ID from Reddit
|
// Set account ID from Reddit
|
||||||
a.AccountID = me.ID
|
a.AccountID = me.ID
|
||||||
|
|
||||||
// Upsert account
|
|
||||||
if err := app.models.Accounts.Upsert(a); err != nil {
|
|
||||||
app.logger.WithFields(logrus.Fields{
|
|
||||||
"err": err,
|
|
||||||
}).Info("failed updating account in database")
|
|
||||||
app.errorResponse(w, r, 500, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Associate
|
// Associate
|
||||||
d, err := app.models.Devices.GetByAPNSToken(ps.ByName("apns"))
|
d, err := app.models.Devices.GetByAPNSToken(ps.ByName("apns"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.logger.WithFields(logrus.Fields{
|
app.logger.WithFields(logrus.Fields{
|
||||||
"err": err,
|
"err": err,
|
||||||
}).Info("failed fetching account devices")
|
}).Info("failed fetching device from database")
|
||||||
|
app.errorResponse(w, r, 500, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upsert account
|
||||||
|
if err := app.models.Accounts.Upsert(a); err != nil {
|
||||||
|
app.logger.WithFields(logrus.Fields{
|
||||||
|
"err": err,
|
||||||
|
}).Info("failed updating account in database")
|
||||||
app.errorResponse(w, r, 500, err.Error())
|
app.errorResponse(w, r, 500, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue