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.
This commit is contained in:
Eli Ribble 2026-05-21 03:23:10 +00:00
parent 75d0283453
commit 5e103f46a0
No known key found for this signature in database
14 changed files with 103 additions and 108 deletions

View file

@ -4,10 +4,10 @@ import (
"context" "context"
//"time" //"time"
"github.com/Gleipnir-Technology/jet/postgres"
"source.gleipnir.technology/Gleipnir/nidus-sync/db" "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/model"
"source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/publicreport/table" "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) { 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) RETURNING(table.Water.AllColumns)
return db.ExecuteOneTx[model.Water](ctx, txn, statement) 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)
}

View file

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"time" "time"
"github.com/rs/zerolog/log"
"source.gleipnir.technology/Gleipnir/nidus-sync/config" "source.gleipnir.technology/Gleipnir/nidus-sync/config"
) )
@ -104,6 +105,7 @@ const (
) )
func Created(t ResourceType, organization_id int32, uri_id string) { 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{ go Send(Envelope{
Event: Event{ Event: Event{
Resource: resourceString(t), Resource: resourceString(t),

View file

@ -81,7 +81,8 @@ func PublicReportByIDNuisance(ctx context.Context, report_id string, is_public b
return publicreport.ByIDNuisance(ctx, report_id, is_public) return publicreport.ByIDNuisance(ctx, report_id, is_public)
} }
func PublicReportByIDWater(ctx context.Context, report_id string, is_public bool) (*types.PublicReportWater, error) { 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 { func PublicReportInvalid(ctx context.Context, user User, public_id string) error {
report, err := querypublicreport.ReportFromPublicID(ctx, db.PGInstance.PGXPool, public_id) report, err := querypublicreport.ReportFromPublicID(ctx, db.PGInstance.PGXPool, public_id)

View file

@ -38,15 +38,20 @@ func ByIDNuisance(ctx context.Context, public_id string, is_public bool) (*types
} }
return nuisance(ctx, public_id, *report) 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) report, err := byID(ctx, public_id, is_public)
if err != nil { 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 { 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) { 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) reports, err := querypublicreport.ReportsUnreviewedForOrganization(ctx, txn, org_id)
@ -143,10 +148,10 @@ func reportQueryToRows(ctx context.Context, reports []modelpublicreport.Report,
DistrictID: &row.OrganizationID, DistrictID: &row.OrganizationID,
District: nil, District: nil,
PublicID: row.PublicID, PublicID: row.PublicID,
Reporter: types.ContactReporter{ Reporter: types.ContactSimple{
Email: row.ReporterEmail, Email: row.ReporterEmail,
Name: row.ReporterName, Name: row.ReporterName,
Phone: types.PhoneReporter{ Phone: types.PhoneSimple{
CanSMS: row.ReporterPhoneCanSms, CanSMS: row.ReporterPhoneCanSms,
Number: row.ReporterPhone, Number: row.ReporterPhone,
}, },

View file

@ -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
}

View file

@ -1,7 +1,7 @@
package types package types
import ( import (
//"github.com/rs/zerolog/log" // "github.com/rs/zerolog/log"
) )
type Contact struct { type Contact struct {
@ -10,16 +10,16 @@ type Contact struct {
Name string `json:"name"` Name string `json:"name"`
Phones []Phone `json:"phones"` Phones []Phone `json:"phones"`
} }
type ContactReporter struct { type ContactSimple struct {
Email string `json:"email"` Email string `json:"email"`
Name string `json:"name"` Name string `json:"name"`
Phone PhoneReporter `json:"phone"` Phone PhoneSimple `json:"phone"`
} }
type Phone struct { type Phone struct {
E164 string `json:"e164"` E164 string `json:"e164"`
CanSMS bool `json:"can_sms"` CanSMS bool `json:"can_sms"`
} }
type PhoneReporter struct { type PhoneSimple struct {
CanSMS bool `json:"can_sms"` CanSMS bool `json:"can_sms"`
Number string `json:"number"` Number string `json:"number"`
} }

View file

@ -2,6 +2,8 @@ package types
import ( import (
"time" "time"
"source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/publicreport/model"
) )
type PublicReport struct { type PublicReport struct {
@ -15,7 +17,7 @@ type PublicReport struct {
DistrictID *int32 `db:"organization_id" json:"-"` DistrictID *int32 `db:"organization_id" json:"-"`
District *string `db:"-" json:"district"` District *string `db:"-" json:"district"`
PublicID string `db:"public_id" json:"public_id"` 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"` Status string `db:"status" json:"status"`
Type string `db:"report_type" json:"type"` Type string `db:"report_type" json:"type"`
URI string `db:"-" json:"uri"` URI string `db:"-" json:"uri"`
@ -56,19 +58,47 @@ type PublicReportNuisance struct {
} }
type PublicReportWater struct { type PublicReportWater struct {
PublicReport PublicReport
AccessComments string `db:"access_comments" json:"access_comments"` AccessComments string `db:"access_comments" json:"access_comments"`
AccessGate bool `db:"access_gate" json:"access_gate"` AccessGate bool `db:"access_gate" json:"access_gate"`
AccessFence bool `db:"access_fence" json:"access_fence"` AccessFence bool `db:"access_fence" json:"access_fence"`
AccessLocked bool `db:"access_locked" json:"access_locked"` AccessLocked bool `db:"access_locked" json:"access_locked"`
AccessDog bool `db:"access_dog" json:"access_dog"` AccessDog bool `db:"access_dog" json:"access_dog"`
AccessOther bool `db:"access_other" json:"access_other"` AccessOther bool `db:"access_other" json:"access_other"`
Comments string `db:"comments" json:"comments"` Comments string `db:"comments" json:"comments"`
HasAdult bool `db:"has_adult" json:"has_adult"` HasAdult bool `db:"has_adult" json:"has_adult"`
HasBackyardPermission bool `db:"has_backyard_permission" json:"has_backyard_permission"` HasBackyardPermission bool `db:"has_backyard_permission" json:"has_backyard_permission"`
HasLarvae bool `db:"has_larvae" json:"has_larvae"` HasLarvae bool `db:"has_larvae" json:"has_larvae"`
HasPupae bool `db:"has_pupae" json:"has_pupae"` HasPupae bool `db:"has_pupae" json:"has_pupae"`
IsReporterConfidential bool `db:"is_reporter_confidential" json:"is_reporter_confidential"` IsReporterConfidential bool `db:"is_reporter_confidential" json:"is_reporter_confidential"`
IsReporterOwner bool `db:"is_reporter_owner" json:"is_reporter_owner"` IsReporterOwner bool `db:"is_reporter_owner" json:"is_reporter_owner"`
Owner Contact `db:"owner" json:"owner"` Owner ContactSimple `db:"owner" json:"owner"`
ReportID int32 `db:"report_id" json:"-"` 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,
}
} }

View file

@ -70,12 +70,12 @@
}}</a> }}</a>
</label> </label>
<label <label
v-if="report.reporter.phone.e164 != ''" v-if="report.reporter.phone.number != ''"
class="form-label text-muted small mb-0" class="form-label text-muted small mb-0"
> >
<i class="bi bi-phone"></i> <i class="bi bi-phone"></i>
<a :href="'tel:+' + report.reporter.phone.e164">{{ <a :href="'tel:+' + report.reporter.phone.number">{{
report.reporter.phone.e164 report.reporter.phone.number
}}</a> }}</a>
</label> </label>
</div> </div>

View file

@ -79,7 +79,7 @@
v-if=" v-if="
!( !(
selectedReport?.reporter.email || selectedReport?.reporter.email ||
selectedReport?.reporter.phone.e164 != '' selectedReport?.reporter.phone.number != ''
) )
" "
class="mb-3" class="mb-3"
@ -92,7 +92,7 @@
<div <div
v-if=" v-if="
selectedReport?.reporter.email || selectedReport?.reporter.email ||
selectedReport?.reporter.phone.e164 != '' selectedReport?.reporter.phone.number != ''
" "
class="mb-3" class="mb-3"
> >

View file

@ -86,14 +86,11 @@
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label <label v-if="report.owner.email" class="form-label text-muted small mb-0">
v-if="report.owner.emails.length"
class="form-label text-muted small mb-0"
>
<i class="bi bi-envelope"></i> <i class="bi bi-envelope"></i>
</label> </label>
<label <label
v-if="report.owner.phones.length" v-if="report.owner.phone.number"
class="form-label text-muted small mb-0" class="form-label text-muted small mb-0"
> >
<i class="bi bi-phone"></i> <i class="bi bi-phone"></i>

View file

@ -248,7 +248,7 @@ const hasCompleteResponse = computed(() => {
r.images.length > 0 || r.images.length > 0 ||
r.permission_type == PermissionType.GRANTED || r.permission_type == PermissionType.GRANTED ||
r.reporter.name || r.reporter.name ||
r.reporter.phone.e164 != "" || r.reporter.phone.number != "" ||
r.reporter.email r.reporter.email
) { ) {
return true; return true;

View file

@ -61,7 +61,7 @@
id="contact-phone" id="contact-phone"
name="phone" name="phone"
placeholder="(555) 123-4567" placeholder="(555) 123-4567"
v-model="modelValue.reporter.phone.e164" v-model="modelValue.reporter.phone.number"
/> />
</div> </div>

View file

@ -200,7 +200,7 @@
class="summary-value" class="summary-value"
v-if=" v-if="
modelValue.reporter?.phone || modelValue.reporter?.phone ||
modelValue.reporter?.phone.e164 != '' modelValue.reporter?.phone.number != ''
" "
> >
{{ modelValue.reporter.phone }} {{ modelValue.reporter.phone }}

View file

@ -103,23 +103,23 @@ export interface ContactDTO {
phones: Phone[]; phones: Phone[];
uri: string; uri: string;
} }
export interface ContactReporterOptions { export interface ContactSimpleOptions {
email?: string; email?: string;
name?: string; name?: string;
phone?: Phone; phone?: PhoneSimple;
uri?: string; uri?: string;
} }
export class ContactReporter { export class ContactSimple {
email: string; email: string;
name: string; name: string;
phone: Phone; phone: PhoneSimple;
uri: string; uri: string;
constructor(options?: ContactReporterOptions) { constructor(options?: ContactSimpleOptions) {
this.email = options?.email ?? ""; this.email = options?.email ?? "";
this.name = options?.name ?? ""; this.name = options?.name ?? "";
this.phone = options?.phone ?? { this.phone = options?.phone ?? {
e164: "",
can_sms: true, can_sms: true,
number: "",
}; };
this.uri = options?.uri ?? ""; this.uri = options?.uri ?? "";
} }
@ -219,7 +219,7 @@ export interface ComplianceUpdate {
//images?: Image[]; //images?: Image[];
location?: Location; location?: Location;
permission_type?: string; permission_type?: string;
reporter?: ContactReporter; reporter?: ContactSimple;
submitted?: string; submitted?: string;
//uri: string; //uri: string;
wants_scheduled?: boolean; wants_scheduled?: boolean;
@ -236,7 +236,7 @@ export interface PublicReportDTO {
location: Location; location: Location;
log: LogEntryDTO[]; log: LogEntryDTO[];
public_id: string; public_id: string;
reporter: ContactReporter; reporter: ContactSimple;
status: string; status: string;
type: string; type: string;
uri: string; uri: string;
@ -248,7 +248,7 @@ export interface PublicReportUpdate {
images?: Image[]; images?: Image[];
location?: Location; location?: Location;
public_id?: string; public_id?: string;
reporter?: ContactReporter; reporter?: ContactSimple;
status?: string; status?: string;
type?: string; type?: string;
uri?: string; uri?: string;
@ -266,7 +266,7 @@ export interface PublicReportOptions {
location: Location; location: Location;
log: LogEntry[]; log: LogEntry[];
public_id: string; public_id: string;
reporter: ContactReporter; reporter: ContactSimple;
status: string; status: string;
type: string; type: string;
uri: string; uri: string;
@ -278,7 +278,7 @@ export class PublicReport {
images: Image[]; images: Image[];
log: LogEntry[]; log: LogEntry[];
public_id: string; public_id: string;
reporter: ContactReporter; reporter: ContactSimple;
status: string; status: string;
type: string; type: string;
uri: string; uri: string;
@ -290,7 +290,7 @@ export class PublicReport {
this.images = options?.images ?? []; this.images = options?.images ?? [];
this.log = options?.log ?? []; this.log = options?.log ?? [];
this.public_id = options?.public_id ?? ""; this.public_id = options?.public_id ?? "";
this.reporter = options?.reporter ?? new ContactReporter(); this.reporter = options?.reporter ?? new ContactSimple();
this.status = options?.status ?? ""; this.status = options?.status ?? "";
this.type = options?.type ?? ""; this.type = options?.type ?? "";
this.uri = options?.uri ?? ""; this.uri = options?.uri ?? "";
@ -469,7 +469,7 @@ export interface PublicReportWaterDTO extends PublicReportDTO {
has_pupae: boolean; has_pupae: boolean;
is_reporter_confidential: boolean; is_reporter_confidential: boolean;
is_reporter_owner: boolean; is_reporter_owner: boolean;
owner: Contact; owner: ContactSimple;
} }
export interface PublicReportWaterOptions extends PublicReportOptions { export interface PublicReportWaterOptions extends PublicReportOptions {
access_comments: string; access_comments: string;
@ -485,7 +485,7 @@ export interface PublicReportWaterOptions extends PublicReportOptions {
has_pupae: boolean; has_pupae: boolean;
is_reporter_confidential: boolean; is_reporter_confidential: boolean;
is_reporter_owner: boolean; is_reporter_owner: boolean;
owner: Contact; owner: ContactSimple;
} }
export class PublicReportWater extends PublicReport { export class PublicReportWater extends PublicReport {
access_comments: string; access_comments: string;
@ -501,7 +501,7 @@ export class PublicReportWater extends PublicReport {
has_pupae: boolean; has_pupae: boolean;
is_reporter_confidential: boolean; is_reporter_confidential: boolean;
is_reporter_owner: boolean; is_reporter_owner: boolean;
owner: Contact; owner: ContactSimple;
constructor(options: PublicReportWaterOptions) { constructor(options: PublicReportWaterOptions) {
super(options); super(options);
this.access_comments = options.access_comments; this.access_comments = options.access_comments;
@ -848,6 +848,10 @@ export interface Phone {
can_sms: boolean; can_sms: boolean;
e164: string; e164: string;
} }
export interface PhoneSimple {
can_sms: boolean;
number: string;
}
export interface PhoneReporter { export interface PhoneReporter {
can_sms: boolean; can_sms: boolean;
number: string; number: string;