Emit communication updated events when reports change
Some checks failed
/ golint (push) Failing after 10s
Some checks failed
/ golint (push) Failing after 10s
This commit is contained in:
parent
594bf33b0a
commit
d120ed05f2
4 changed files with 36 additions and 7 deletions
|
|
@ -85,7 +85,8 @@ func PublicReportByIDWater(ctx context.Context, report_id string, is_public bool
|
|||
return &result, err
|
||||
}
|
||||
func PublicReportInvalid(ctx context.Context, user User, public_id string) error {
|
||||
report, err := querypublicreport.ReportFromPublicID(ctx, db.PGInstance.PGXPool, public_id)
|
||||
txn := db.PGInstance.PGXPool
|
||||
report, err := querypublicreport.ReportFromPublicID(ctx, txn, public_id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("query report existence: %w", err)
|
||||
}
|
||||
|
|
@ -102,10 +103,15 @@ func PublicReportInvalid(ctx context.Context, user User, public_id string) error
|
|||
report_updater.Set(tablepublicreport.Report.ReviewerID)
|
||||
report_updater.Model.Status = modelpublicreport.Reportstatustype_Invalidated
|
||||
report_updater.Set(tablepublicreport.Report.Status)
|
||||
err = report_updater.Execute(ctx, db.PGInstance.PGXPool, report.ID)
|
||||
err = report_updater.Execute(ctx, txn, report.ID)
|
||||
|
||||
log.Info().Int32("id", report.ID).Msg("Report marked as invalid")
|
||||
event.Updated(event.TypeRMOPublicReport, user.Organization.ID, public_id)
|
||||
comm, err := querypublic.CommunicationFromReportID(ctx, txn, int64(report.ID))
|
||||
if err != nil {
|
||||
return fmt.Errorf("communication from report ID %d: %w", report.ID, err)
|
||||
}
|
||||
event.Updated(event.TypeCommunication, user.Organization.ID, strconv.Itoa(int(comm.ID)))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -260,9 +266,6 @@ func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_
|
|||
}
|
||||
return nil
|
||||
}
|
||||
func PublicReportReporterUpdated(ctx context.Context, org_id int32, report_id string) {
|
||||
event.Updated(event.TypeRMOPublicReport, org_id, report_id)
|
||||
}
|
||||
func PublicReportsForOrganization(ctx context.Context, org_id int32, is_public bool) ([]types.PublicReport, error) {
|
||||
return publicreport.UnreviewedForOrganization(ctx, db.PGInstance.PGXPool, int64(org_id), is_public)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/db"
|
||||
modelcomms "source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/comms/model"
|
||||
modelpublic "source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/public/model"
|
||||
|
|
@ -15,7 +16,6 @@ import (
|
|||
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/email"
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/text"
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/types"
|
||||
//"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func DistrictForReport(ctx context.Context, report_id string) (modelpublic.Organization, error) {
|
||||
|
|
@ -89,11 +89,13 @@ func SaveReporter(ctx context.Context, txn db.Ex, report modelpublicreport.Repor
|
|||
if err != nil {
|
||||
return contact, fmt.Errorf("contact insert: %w", err)
|
||||
}
|
||||
log.Debug().Str("name", name).Int32("id", contact.ID).Msg("new contact inserted")
|
||||
} else {
|
||||
contact, err = querycomms.ContactFromID(ctx, txn, int64(*report.ReporterContactID))
|
||||
if err != nil {
|
||||
return contact, fmt.Errorf("contact query: %w", err)
|
||||
}
|
||||
log.Debug().Str("name", name).Str("old name", contact.Name).Int32("id", contact.ID).Msg("contact updated")
|
||||
if name != "" && contact.Name != name {
|
||||
err = querycomms.ContactUpdateName(ctx, txn, int64(contact.ID), name)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -3,10 +3,13 @@ package platform
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/db"
|
||||
querypublic "source.gleipnir.technology/Gleipnir/nidus-sync/db/query/public"
|
||||
querypublicreport "source.gleipnir.technology/Gleipnir/nidus-sync/db/query/publicreport"
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/lint"
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/event"
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/publicreport"
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/types"
|
||||
//"github.com/rs/zerolog/log"
|
||||
|
|
@ -72,6 +75,11 @@ func PublicreportNotificationCreate(ctx context.Context, pn PublicreportNotifica
|
|||
if err := txn.Commit(ctx); err != nil {
|
||||
return fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
PublicReportReporterUpdated(ctx, report.OrganizationID, pn.ReportID)
|
||||
event.Updated(event.TypeRMOPublicReport, report.OrganizationID, pn.ReportID)
|
||||
comm, err := querypublic.CommunicationFromReportID(ctx, db.PGInstance.PGXPool, int64(report.ID))
|
||||
if err != nil {
|
||||
return fmt.Errorf("communication from report ID %d: %w", report.ID, err)
|
||||
}
|
||||
event.Updated(event.TypeCommunication, report.OrganizationID, strconv.Itoa(int(comm.ID)))
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue