diff --git a/platform/publicreport.go b/platform/publicreport.go index 27ca8349..577d2609 100644 --- a/platform/publicreport.go +++ b/platform/publicreport.go @@ -193,6 +193,7 @@ func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_ compliance_setter.HasDog.IsValue() || compliance_setter.PermissionType.IsValue() || compliance_setter.ReportPhoneCanText.IsValue() || + compliance_setter.Submitted.IsValue() || compliance_setter.WantsScheduled.IsValue() { err = compliance.Update(ctx, txn, compliance_setter) if err != nil { diff --git a/platform/publicreport/compliance.go b/platform/publicreport/compliance.go index dbb01346..c4aa3789 100644 --- a/platform/publicreport/compliance.go +++ b/platform/publicreport/compliance.go @@ -27,6 +27,7 @@ func compliance(ctx context.Context, public_id string, report types.PublicReport models.PublicreportCompliances.Columns.PermissionType, models.PublicreportCompliances.Columns.ReportID, models.PublicreportCompliances.Columns.ReportPhoneCanText, + models.PublicreportCompliances.Columns.Submitted, models.PublicreportCompliances.Columns.WantsScheduled, ), //sm.From(psql.Quote("publicreport", "compliance")).As("publicreport.compliance"), diff --git a/resource/communication.go b/resource/communication.go index 18b0bdb7..d0cfbf5c 100644 --- a/resource/communication.go +++ b/resource/communication.go @@ -7,7 +7,8 @@ import ( "time" "github.com/Gleipnir-Technology/nidus-sync/config" - "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/publicreport/model" + modelpublic "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/model" + modelpublicreport "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/publicreport/model" nhttp "github.com/Gleipnir-Technology/nidus-sync/http" "github.com/Gleipnir-Technology/nidus-sync/platform" "github.com/google/uuid" @@ -26,10 +27,15 @@ func Communication(r *router) *communicationR { } type communication struct { - Created time.Time `json:"created"` - ID int32 `json:"id"` - Source string `json:"source"` - Type string `json:"type"` + Closed *time.Time `json:"closed"` + ClosedBy string `json:"closed_by"` + Created time.Time `json:"created"` + ID int32 `json:"id"` + Opened *time.Time `json:"opened"` + OpenedBy string `json:"opened_by"` + Response string `json:"response"` + Source string `json:"source"` + Type string `json:"type"` } func toImageURLs(m map[string][]uuid.UUID, id string) []string { @@ -58,7 +64,7 @@ func (res *communicationR) List(ctx context.Context, r *http.Request, user platf if err != nil { return nil, nhttp.NewError("public reports from IDs: %w", err) } - public_report_id_to_report := make(map[int32]*model.Report, 0) + public_report_id_to_report := make(map[int32]*modelpublicreport.Report, 0) for _, pr := range public_reports { public_report_id_to_report[pr.ID] = pr } @@ -89,11 +95,28 @@ func (res *communicationR) List(ctx context.Context, r *http.Request, user platf } source_uri = "text" } + closed_by, err := userURI(res.router, comm.ClosedBy) + if err != nil { + return nil, nhttp.NewError("gen closed_by URI: %w", err) + } + opened_by, err := userURI(res.router, comm.OpenedBy) + if err != nil { + return nil, nhttp.NewError("gen opened_by URI: %w", err) + } + response, err := responseURI(res.router, comm) + if err != nil { + return nil, nhttp.NewError("gen response URI: %w", err) + } result[i] = &communication{ - Created: comm.Created, - ID: comm.ID, - Source: source_uri, - Type: type_, + Closed: comm.Closed, + ClosedBy: closed_by, + Created: comm.Created, + ID: comm.ID, + Opened: comm.Opened, + OpenedBy: opened_by, + Response: response, + Source: source_uri, + Type: type_, } } _by_created := func(a, b *communication) int { @@ -112,6 +135,21 @@ func (res *communicationR) List(ctx context.Context, r *http.Request, user platf func emailURI(r *router, id int32) (string, error) { return "fake email uri", nil } +func responseURI(r *router, comm *modelpublic.Communication) (string, error) { + if comm.ResponseEmailLogID != nil { + return emailURI(r, *comm.ResponseEmailLogID) + } else if comm.ResponseTextLogID != nil { + return textURI(r, *comm.ResponseTextLogID) + } else { + return "", nil + } +} func textURI(r *router, id int32) (string, error) { return "fake text uri", nil } +func userURI(r *router, id *int32) (string, error) { + if id == nil { + return "", nil + } + return r.IDToURI("user.ByIDGet", int(*id)) +} diff --git a/ts/type/api.ts b/ts/type/api.ts index 882120ba..5a21eceb 100644 --- a/ts/type/api.ts +++ b/ts/type/api.ts @@ -306,7 +306,7 @@ export interface PublicReportComplianceOptions extends PublicReportOptions { gate_code: string; has_dog: boolean; permission_type: PermissionType; - submitted: string; + submitted?: Date; wants_scheduled: boolean; } export interface PublicReportComplianceUpdate extends PublicReportUpdate { @@ -350,6 +350,7 @@ export class PublicReportCompliance extends PublicReport { ...json, created: new Date(json.created), log: json.log.map((l: LogEntryDTO) => LogEntry.fromJSON(l)), + submitted: json.submitted ? new Date(json.submitted) : undefined, }); } }