From 5e103f46a05ccb90e690bc2055664ec495a4b41f Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Thu, 21 May 2026 03:23:10 +0000 Subject: [PATCH] Fix populating water report from ID, make ContactSimple ContactSimple is the replacement for ContactReporter, which was the simplified form of a contact from a report. I made the name more generic and use it in the general report structures for consistency. --- db/query/publicreport/water.go | 8 ++- platform/event/event.go | 2 + platform/publicreport.go | 3 +- platform/publicreport/report.go | 17 ++++-- platform/publicreport/water.go | 50 ----------------- platform/types/contact.go | 12 ++-- platform/types/publicreport.go | 62 +++++++++++++++------ ts/components/CardPublicReport.vue | 6 +- ts/components/CommunicationColumnAction.vue | 4 +- ts/components/PublicReportCardWater.vue | 7 +-- ts/rmo/content/compliance/Complete.vue | 2 +- ts/rmo/content/compliance/Contact.vue | 2 +- ts/rmo/content/compliance/Submit.vue | 2 +- ts/type/api.ts | 34 ++++++----- 14 files changed, 103 insertions(+), 108 deletions(-) delete mode 100644 platform/publicreport/water.go diff --git a/db/query/publicreport/water.go b/db/query/publicreport/water.go index 6b2f7bda..49fca094 100644 --- a/db/query/publicreport/water.go +++ b/db/query/publicreport/water.go @@ -4,10 +4,10 @@ import ( "context" //"time" + "github.com/Gleipnir-Technology/jet/postgres" "source.gleipnir.technology/Gleipnir/nidus-sync/db" "source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/publicreport/model" "source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/publicreport/table" - //"github.com/Gleipnir-Technology/jet/postgres" ) func WaterInsert(ctx context.Context, txn db.Ex, m model.Water) (model.Water, error) { @@ -16,3 +16,9 @@ func WaterInsert(ctx context.Context, txn db.Ex, m model.Water) (model.Water, er RETURNING(table.Water.AllColumns) return db.ExecuteOneTx[model.Water](ctx, txn, statement) } +func WaterFromReportID(ctx context.Context, txn db.Ex, report_id int64) (model.Water, error) { + statement := table.Water.SELECT(table.Water.AllColumns). + FROM(table.Water). + WHERE(table.Water.ReportID.EQ(postgres.Int(report_id))) + return db.ExecuteOneTx[model.Water](ctx, txn, statement) +} diff --git a/platform/event/event.go b/platform/event/event.go index c03c8f83..48358b13 100644 --- a/platform/event/event.go +++ b/platform/event/event.go @@ -4,6 +4,7 @@ import ( "encoding/json" "time" + "github.com/rs/zerolog/log" "source.gleipnir.technology/Gleipnir/nidus-sync/config" ) @@ -104,6 +105,7 @@ const ( ) func Created(t ResourceType, organization_id int32, uri_id string) { + log.Debug().Int("resource type", int(t)).Int32("org", organization_id).Str("uri", uri_id).Msg("created event") go Send(Envelope{ Event: Event{ Resource: resourceString(t), diff --git a/platform/publicreport.go b/platform/publicreport.go index 0e8e5ad9..36a23277 100644 --- a/platform/publicreport.go +++ b/platform/publicreport.go @@ -81,7 +81,8 @@ func PublicReportByIDNuisance(ctx context.Context, report_id string, is_public b return publicreport.ByIDNuisance(ctx, report_id, is_public) } func PublicReportByIDWater(ctx context.Context, report_id string, is_public bool) (*types.PublicReportWater, error) { - return publicreport.ByIDWater(ctx, report_id, is_public) + result, err := publicreport.ByIDWater(ctx, report_id, is_public) + return &result, err } func PublicReportInvalid(ctx context.Context, user User, public_id string) error { report, err := querypublicreport.ReportFromPublicID(ctx, db.PGInstance.PGXPool, public_id) diff --git a/platform/publicreport/report.go b/platform/publicreport/report.go index 27fe1d86..a93c3be2 100644 --- a/platform/publicreport/report.go +++ b/platform/publicreport/report.go @@ -38,15 +38,20 @@ func ByIDNuisance(ctx context.Context, public_id string, is_public bool) (*types } return nuisance(ctx, public_id, *report) } -func ByIDWater(ctx context.Context, public_id string, is_public bool) (*types.PublicReportWater, error) { +func ByIDWater(ctx context.Context, public_id string, is_public bool) (types.PublicReportWater, error) { report, err := byID(ctx, public_id, is_public) if err != nil { - return nil, fmt.Errorf("base report byid: %w", err) + return types.PublicReportWater{}, fmt.Errorf("base report byid: %w", err) } if report == nil { - return nil, nil + return types.PublicReportWater{}, nil } - return water(ctx, public_id, *report) + txn := db.PGInstance.PGXPool + water, err := querypublicreport.WaterFromReportID(ctx, txn, int64(report.ID)) + if err != nil { + return types.PublicReportWater{}, fmt.Errorf("water from report id %d: %w", report.ID, err) + } + return types.PublicReportWaterFromModel(*report, water), nil } func UnreviewedForOrganization(ctx context.Context, txn db.Ex, org_id int64, is_public bool) ([]types.PublicReport, error) { reports, err := querypublicreport.ReportsUnreviewedForOrganization(ctx, txn, org_id) @@ -143,10 +148,10 @@ func reportQueryToRows(ctx context.Context, reports []modelpublicreport.Report, DistrictID: &row.OrganizationID, District: nil, PublicID: row.PublicID, - Reporter: types.ContactReporter{ + Reporter: types.ContactSimple{ Email: row.ReporterEmail, Name: row.ReporterName, - Phone: types.PhoneReporter{ + Phone: types.PhoneSimple{ CanSMS: row.ReporterPhoneCanSms, Number: row.ReporterPhone, }, diff --git a/platform/publicreport/water.go b/platform/publicreport/water.go deleted file mode 100644 index 8b4ca6e0..00000000 --- a/platform/publicreport/water.go +++ /dev/null @@ -1,50 +0,0 @@ -package publicreport - -import ( - "context" - "fmt" - - "github.com/Gleipnir-Technology/bob" - "github.com/Gleipnir-Technology/bob/dialect/psql" - "github.com/Gleipnir-Technology/bob/dialect/psql/sm" - //"source.gleipnir.technology/Gleipnir/nidus-sync/config" - "source.gleipnir.technology/Gleipnir/nidus-sync/db" - "source.gleipnir.technology/Gleipnir/nidus-sync/platform/types" - //"source.gleipnir.technology/Gleipnir/nidus-sync/db/models" - //"github.com/google/uuid" - //"github.com/rs/zerolog/log" - "github.com/stephenafamo/scan" -) - -func water(ctx context.Context, public_id string, report types.PublicReport) (*types.PublicReportWater, error) { - row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select( - sm.Columns( - "access_comments", - "access_gate", - "access_fence", - "access_locked", - "access_dog", - "access_other", - "comments", - "has_adult", - "has_backyard_permission", - "has_larvae", - "has_pupae", - "is_reporter_confidential", - "is_reporter_owner", - "owner_email AS \"owner.email\"", - "owner_name AS \"owner.name\"", - "owner_phone AS \"owner.phone\"", - "report_id", - ), - sm.From("publicreport.water"), - sm.Where(psql.Quote("report_id").EQ( - psql.Arg(report.ID), - )), - ), scan.StructMapper[types.PublicReportWater]()) - if err != nil { - return nil, fmt.Errorf("query water: %w", err) - } - copyReportContent(report, &row.PublicReport) - return &row, nil -} diff --git a/platform/types/contact.go b/platform/types/contact.go index 3242a92f..8ab714b3 100644 --- a/platform/types/contact.go +++ b/platform/types/contact.go @@ -1,7 +1,7 @@ package types import ( -//"github.com/rs/zerolog/log" +// "github.com/rs/zerolog/log" ) type Contact struct { @@ -10,16 +10,16 @@ type Contact struct { Name string `json:"name"` Phones []Phone `json:"phones"` } -type ContactReporter struct { - Email string `json:"email"` - Name string `json:"name"` - Phone PhoneReporter `json:"phone"` +type ContactSimple struct { + Email string `json:"email"` + Name string `json:"name"` + Phone PhoneSimple `json:"phone"` } type Phone struct { E164 string `json:"e164"` CanSMS bool `json:"can_sms"` } -type PhoneReporter struct { +type PhoneSimple struct { CanSMS bool `json:"can_sms"` Number string `json:"number"` } diff --git a/platform/types/publicreport.go b/platform/types/publicreport.go index 2b508ee4..14e95863 100644 --- a/platform/types/publicreport.go +++ b/platform/types/publicreport.go @@ -2,6 +2,8 @@ package types import ( "time" + + "source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/publicreport/model" ) type PublicReport struct { @@ -15,7 +17,7 @@ type PublicReport struct { DistrictID *int32 `db:"organization_id" json:"-"` District *string `db:"-" json:"district"` PublicID string `db:"public_id" json:"public_id"` - Reporter ContactReporter `db:"reporter" json:"reporter"` + Reporter ContactSimple `db:"reporter" json:"reporter"` Status string `db:"status" json:"status"` Type string `db:"report_type" json:"type"` URI string `db:"-" json:"uri"` @@ -56,19 +58,47 @@ type PublicReportNuisance struct { } type PublicReportWater struct { PublicReport - AccessComments string `db:"access_comments" json:"access_comments"` - AccessGate bool `db:"access_gate" json:"access_gate"` - AccessFence bool `db:"access_fence" json:"access_fence"` - AccessLocked bool `db:"access_locked" json:"access_locked"` - AccessDog bool `db:"access_dog" json:"access_dog"` - AccessOther bool `db:"access_other" json:"access_other"` - Comments string `db:"comments" json:"comments"` - HasAdult bool `db:"has_adult" json:"has_adult"` - HasBackyardPermission bool `db:"has_backyard_permission" json:"has_backyard_permission"` - HasLarvae bool `db:"has_larvae" json:"has_larvae"` - HasPupae bool `db:"has_pupae" json:"has_pupae"` - IsReporterConfidential bool `db:"is_reporter_confidential" json:"is_reporter_confidential"` - IsReporterOwner bool `db:"is_reporter_owner" json:"is_reporter_owner"` - Owner Contact `db:"owner" json:"owner"` - ReportID int32 `db:"report_id" json:"-"` + AccessComments string `db:"access_comments" json:"access_comments"` + AccessGate bool `db:"access_gate" json:"access_gate"` + AccessFence bool `db:"access_fence" json:"access_fence"` + AccessLocked bool `db:"access_locked" json:"access_locked"` + AccessDog bool `db:"access_dog" json:"access_dog"` + AccessOther bool `db:"access_other" json:"access_other"` + Comments string `db:"comments" json:"comments"` + HasAdult bool `db:"has_adult" json:"has_adult"` + HasBackyardPermission bool `db:"has_backyard_permission" json:"has_backyard_permission"` + HasLarvae bool `db:"has_larvae" json:"has_larvae"` + HasPupae bool `db:"has_pupae" json:"has_pupae"` + IsReporterConfidential bool `db:"is_reporter_confidential" json:"is_reporter_confidential"` + IsReporterOwner bool `db:"is_reporter_owner" json:"is_reporter_owner"` + Owner ContactSimple `db:"owner" json:"owner"` + ReportID int32 `db:"report_id" json:"-"` +} + +func PublicReportWaterFromModel(report PublicReport, water model.Water) PublicReportWater { + return PublicReportWater{ + PublicReport: report, + AccessComments: water.AccessComments, + AccessGate: water.AccessGate, + AccessFence: water.AccessFence, + AccessLocked: water.AccessLocked, + AccessDog: water.AccessDog, + AccessOther: water.AccessOther, + Comments: water.Comments, + HasAdult: water.HasAdult, + HasBackyardPermission: water.HasBackyardPermission, + HasLarvae: water.HasLarvae, + HasPupae: water.HasPupae, + IsReporterConfidential: water.IsReporterConfidential, + IsReporterOwner: water.IsReporterOwner, + Owner: ContactSimple{ + Email: water.OwnerEmail, + Name: water.OwnerName, + Phone: PhoneSimple{ + CanSMS: false, + Number: water.OwnerPhone, + }, + }, + ReportID: water.ReportID, + } } diff --git a/ts/components/CardPublicReport.vue b/ts/components/CardPublicReport.vue index e3cf682b..000926c3 100644 --- a/ts/components/CardPublicReport.vue +++ b/ts/components/CardPublicReport.vue @@ -70,12 +70,12 @@ }} diff --git a/ts/components/CommunicationColumnAction.vue b/ts/components/CommunicationColumnAction.vue index 3e444a9b..44920cd2 100644 --- a/ts/components/CommunicationColumnAction.vue +++ b/ts/components/CommunicationColumnAction.vue @@ -79,7 +79,7 @@ v-if=" !( selectedReport?.reporter.email || - selectedReport?.reporter.phone.e164 != '' + selectedReport?.reporter.phone.number != '' ) " class="mb-3" @@ -92,7 +92,7 @@
diff --git a/ts/components/PublicReportCardWater.vue b/ts/components/PublicReportCardWater.vue index 8cec6567..7e749234 100644 --- a/ts/components/PublicReportCardWater.vue +++ b/ts/components/PublicReportCardWater.vue @@ -86,14 +86,11 @@
-
diff --git a/ts/rmo/content/compliance/Submit.vue b/ts/rmo/content/compliance/Submit.vue index 561ebc83..9546df2a 100644 --- a/ts/rmo/content/compliance/Submit.vue +++ b/ts/rmo/content/compliance/Submit.vue @@ -200,7 +200,7 @@ class="summary-value" v-if=" modelValue.reporter?.phone || - modelValue.reporter?.phone.e164 != '' + modelValue.reporter?.phone.number != '' " > {{ modelValue.reporter.phone }} diff --git a/ts/type/api.ts b/ts/type/api.ts index 79231b9b..9805a59c 100644 --- a/ts/type/api.ts +++ b/ts/type/api.ts @@ -103,23 +103,23 @@ export interface ContactDTO { phones: Phone[]; uri: string; } -export interface ContactReporterOptions { +export interface ContactSimpleOptions { email?: string; name?: string; - phone?: Phone; + phone?: PhoneSimple; uri?: string; } -export class ContactReporter { +export class ContactSimple { email: string; name: string; - phone: Phone; + phone: PhoneSimple; uri: string; - constructor(options?: ContactReporterOptions) { + constructor(options?: ContactSimpleOptions) { this.email = options?.email ?? ""; this.name = options?.name ?? ""; this.phone = options?.phone ?? { - e164: "", can_sms: true, + number: "", }; this.uri = options?.uri ?? ""; } @@ -219,7 +219,7 @@ export interface ComplianceUpdate { //images?: Image[]; location?: Location; permission_type?: string; - reporter?: ContactReporter; + reporter?: ContactSimple; submitted?: string; //uri: string; wants_scheduled?: boolean; @@ -236,7 +236,7 @@ export interface PublicReportDTO { location: Location; log: LogEntryDTO[]; public_id: string; - reporter: ContactReporter; + reporter: ContactSimple; status: string; type: string; uri: string; @@ -248,7 +248,7 @@ export interface PublicReportUpdate { images?: Image[]; location?: Location; public_id?: string; - reporter?: ContactReporter; + reporter?: ContactSimple; status?: string; type?: string; uri?: string; @@ -266,7 +266,7 @@ export interface PublicReportOptions { location: Location; log: LogEntry[]; public_id: string; - reporter: ContactReporter; + reporter: ContactSimple; status: string; type: string; uri: string; @@ -278,7 +278,7 @@ export class PublicReport { images: Image[]; log: LogEntry[]; public_id: string; - reporter: ContactReporter; + reporter: ContactSimple; status: string; type: string; uri: string; @@ -290,7 +290,7 @@ export class PublicReport { this.images = options?.images ?? []; this.log = options?.log ?? []; this.public_id = options?.public_id ?? ""; - this.reporter = options?.reporter ?? new ContactReporter(); + this.reporter = options?.reporter ?? new ContactSimple(); this.status = options?.status ?? ""; this.type = options?.type ?? ""; this.uri = options?.uri ?? ""; @@ -469,7 +469,7 @@ export interface PublicReportWaterDTO extends PublicReportDTO { has_pupae: boolean; is_reporter_confidential: boolean; is_reporter_owner: boolean; - owner: Contact; + owner: ContactSimple; } export interface PublicReportWaterOptions extends PublicReportOptions { access_comments: string; @@ -485,7 +485,7 @@ export interface PublicReportWaterOptions extends PublicReportOptions { has_pupae: boolean; is_reporter_confidential: boolean; is_reporter_owner: boolean; - owner: Contact; + owner: ContactSimple; } export class PublicReportWater extends PublicReport { access_comments: string; @@ -501,7 +501,7 @@ export class PublicReportWater extends PublicReport { has_pupae: boolean; is_reporter_confidential: boolean; is_reporter_owner: boolean; - owner: Contact; + owner: ContactSimple; constructor(options: PublicReportWaterOptions) { super(options); this.access_comments = options.access_comments; @@ -848,6 +848,10 @@ export interface Phone { can_sms: boolean; e164: string; } +export interface PhoneSimple { + can_sms: boolean; + number: string; +} export interface PhoneReporter { can_sms: boolean; number: string;