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"
//"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)
}

View file

@ -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),

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

View file

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

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
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"`
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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