Send submit PUT on compliance report flow, create communication then
This makes it so that people don't see compliance reports as they're being formulated in the communication workbench
This commit is contained in:
parent
a82732a49c
commit
7f71ff9a2e
9 changed files with 50 additions and 37 deletions
|
|
@ -76,7 +76,7 @@ func (ts templateSystemEmbed) loadTemplateSubdir(subdir string) error {
|
|||
}
|
||||
|
||||
func (ts templateSystemEmbed) addSubdirTemplates(t *template.Template, subdir string) error {
|
||||
var err error = fs.WalkDir(ts.sourceFS, subdir, func(path string, d fs.DirEntry, err error) error {
|
||||
var err = fs.WalkDir(ts.sourceFS, subdir, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil || d.IsDir() {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ func (l *defaultLogEntry) Panic(v interface{}, stack []byte) {
|
|||
}
|
||||
|
||||
func init() {
|
||||
color := !(runtime.GOOS == "windows")
|
||||
color := runtime.GOOS != "windows"
|
||||
|
||||
DefaultLogger = RequestLogger(&DefaultLogFormatter{Logger: log.New(os.Stdout, "", log.LstdFlags), NoColor: !color})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package platform
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
|
|
|||
|
|
@ -173,6 +173,22 @@ func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("find compliance %d: %w", report.ID, err)
|
||||
}
|
||||
// Don't allow modifying of the submission date if it's set
|
||||
if compliance_setter.Submitted.IsValue() {
|
||||
if compliance.Submitted.IsValue() {
|
||||
compliance_setter.Submitted.Unset()
|
||||
} else {
|
||||
comm := &model.Communication{
|
||||
SourceReportID: &report.ID,
|
||||
}
|
||||
comm, err := querypublic.CommunicationInsert(ctx, txn, comm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("insert communication: %w", err)
|
||||
}
|
||||
log.Debug().Int32("id", comm.ID).Msg("inserted new communication")
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid attempting to perform an empty update
|
||||
if report_setter.LatlngAccuracyValue.IsValue() ||
|
||||
report_setter.ReporterEmail.IsValue() ||
|
||||
|
|
@ -389,14 +405,18 @@ func publicReportCreate(ctx context.Context, setter_report models.PublicreportRe
|
|||
UserID: omitnull.FromPtr[int32](nil),
|
||||
}).One(ctx, txn)
|
||||
|
||||
comm := &model.Communication{
|
||||
SourceReportID: &result.ID,
|
||||
// Only create communication entries for compliance when they're submitted
|
||||
report_type := setter_report.ReportType.MustGet()
|
||||
if report_type != enums.PublicreportReporttypeCompliance {
|
||||
comm := &model.Communication{
|
||||
SourceReportID: &result.ID,
|
||||
}
|
||||
comm, err = querypublic.CommunicationInsert(ctx, txn, comm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("insert communication: %w", err)
|
||||
}
|
||||
log.Debug().Int32("id", comm.ID).Msg("inserted new communication")
|
||||
}
|
||||
comm, err = querypublic.CommunicationInsert(ctx, txn, comm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("insert communication: %w", err)
|
||||
}
|
||||
log.Debug().Int32("id", comm.ID).Msg("inserted new communication")
|
||||
|
||||
txn.Commit(ctx)
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func HandleTextMessage(ctx context.Context, source string, destination string, c
|
|||
if err != nil {
|
||||
return fmt.Errorf("Failed to get phone status")
|
||||
}
|
||||
is_visible_to_llm := !(status == enums.CommsPhonestatustypeUnconfirmed)
|
||||
is_visible_to_llm := status != enums.CommsPhonestatustypeUnconfirmed
|
||||
|
||||
l, err := models.CommsTextLogs.Insert(&models.CommsTextLogSetter{
|
||||
//ID:
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ type complianceR struct {
|
|||
router *router
|
||||
}
|
||||
|
||||
type publicreportComplianceForm struct {
|
||||
type publicReportComplianceForm struct {
|
||||
AccessInstructions omit.Val[string] `schema:"access_instructions" json:"access_instructions"`
|
||||
Address omit.Val[types.Address] `schema:"address" json:"address"`
|
||||
AvailabilityNotes omit.Val[string] `schema:"availability_notes" json:"availability_notes"`
|
||||
|
|
@ -42,6 +42,7 @@ type publicreportComplianceForm struct {
|
|||
PermissionType omit.Val[enums.Permissionaccesstype] `schema:"permission_type" json:"permission_type"`
|
||||
Reporter omit.Val[types.Contact] `schema:"reporter" json:"reporter"`
|
||||
ReportPhoneCanSMS omitnull.Val[bool] `schema:"report_phone_can_text" json:"report_phone_can_text"`
|
||||
Submitted omitnull.Val[time.Time] `schema:"submitted" json:"submitted"`
|
||||
WantsScheduled omitnull.Val[bool] `schema:"wants_scheduled" json:"wants_scheduled"`
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +52,7 @@ func (res *complianceR) ByID(ctx context.Context, r *http.Request, u platform.Us
|
|||
func (res *complianceR) ByIDPublic(ctx context.Context, r *http.Request, query QueryParams) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) {
|
||||
return res.byID(ctx, r, true)
|
||||
}
|
||||
func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicreportComplianceForm) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) {
|
||||
func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicReportComplianceForm) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) {
|
||||
if n.District.IsUnset() && n.MailerID.IsUnset() {
|
||||
return nil, nhttp.NewBadRequest("You must provide a district_id or mailer_id")
|
||||
}
|
||||
|
|
@ -141,7 +142,7 @@ func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicrep
|
|||
}
|
||||
return res.complianceHydrate(result, true)
|
||||
}
|
||||
func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicreportComplianceForm) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) {
|
||||
func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicReportComplianceForm) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["id"]
|
||||
if public_id == "" {
|
||||
|
|
@ -198,12 +199,10 @@ func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicr
|
|||
if prf.WantsScheduled.IsValue() {
|
||||
compliance_setter.WantsScheduled = prf.WantsScheduled
|
||||
}
|
||||
log.Debug().
|
||||
Bool("access_instructions", prf.AccessInstructions.IsValue()).
|
||||
Bool("access_instructions", prf.AccessInstructions.IsValue()).
|
||||
Bool("access_instructions", prf.AccessInstructions.IsValue()).
|
||||
Bool("access_instructions", prf.AccessInstructions.IsValue()).
|
||||
Msg("updating compliance")
|
||||
if prf.Submitted.IsValue() {
|
||||
log.Debug().Str("submitted", prf.Submitted.MustGet().String()).Msg("got submitted")
|
||||
compliance_setter.Submitted = omitnull.From(time.Now())
|
||||
}
|
||||
report, err := platform.PublicReportUpdateCompliance(ctx, public_id, &report_setter, &compliance_setter, address, location)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("platform update report compliance: %w", err)
|
||||
|
|
@ -216,22 +215,6 @@ func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicr
|
|||
return res.complianceHydrate(report, true)
|
||||
}
|
||||
|
||||
type publicreportComplianceFormSubmit struct {
|
||||
ClientID uuid.UUID `schema:"client_id" json:"client_id"`
|
||||
}
|
||||
|
||||
func (res *complianceR) Submit(ctx context.Context, r *http.Request, prf publicreportComplianceForm) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["id"]
|
||||
if public_id == "" {
|
||||
return nil, nhttp.NewBadRequest("You must provide an ID")
|
||||
}
|
||||
report, err := platform.PublicReportComplianceSubmit(ctx, public_id, true)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("submit report: %w", err)
|
||||
}
|
||||
return report, nil
|
||||
}
|
||||
func (res *complianceR) byID(ctx context.Context, r *http.Request, is_public bool) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["id"]
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ func (qp QueryParams) SortOrDefault(default_name string, ascending bool) (string
|
|||
if s == "" {
|
||||
return default_name, ascending
|
||||
}
|
||||
a := !(s[0] == '-')
|
||||
a := s[0] != '-'
|
||||
|
||||
if s[0] == '+' || s[0] == '-' {
|
||||
s = s[1:]
|
||||
|
|
|
|||
|
|
@ -183,6 +183,9 @@ function doPermission() {
|
|||
function doSubmit() {
|
||||
console.log("submit", report.value);
|
||||
storeLocal.delExistingComplianceReportURI();
|
||||
updateReport({
|
||||
submitted: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
async function updateReport(updates: ComplianceUpdate) {
|
||||
if (!(report.value && report.value.uri)) {
|
||||
|
|
|
|||
|
|
@ -196,6 +196,7 @@ export interface ComplianceUpdate {
|
|||
location?: Location;
|
||||
permission_type?: string;
|
||||
reporter?: Contact;
|
||||
submitted?: string;
|
||||
//uri: string;
|
||||
wants_scheduled?: boolean;
|
||||
}
|
||||
|
|
@ -294,6 +295,7 @@ export interface PublicReportComplianceDTO extends PublicReportDTO {
|
|||
gate_code: string;
|
||||
has_dog: boolean;
|
||||
permission_type: PermissionType;
|
||||
submitted: string;
|
||||
wants_scheduled: boolean;
|
||||
}
|
||||
export interface PublicReportComplianceOptions extends PublicReportOptions {
|
||||
|
|
@ -304,6 +306,7 @@ export interface PublicReportComplianceOptions extends PublicReportOptions {
|
|||
gate_code: string;
|
||||
has_dog: boolean;
|
||||
permission_type: PermissionType;
|
||||
submitted: string;
|
||||
wants_scheduled: boolean;
|
||||
}
|
||||
export interface PublicReportComplianceUpdate extends PublicReportUpdate {
|
||||
|
|
@ -313,6 +316,7 @@ export interface PublicReportComplianceUpdate extends PublicReportUpdate {
|
|||
gate_code?: string;
|
||||
has_dog?: boolean;
|
||||
permission_type?: PermissionType;
|
||||
submitted?: string;
|
||||
wants_scheduled?: boolean;
|
||||
}
|
||||
export class PublicReportCompliance extends PublicReport {
|
||||
|
|
@ -323,6 +327,7 @@ export class PublicReportCompliance extends PublicReport {
|
|||
gate_code: string;
|
||||
has_dog: boolean;
|
||||
permission_type: PermissionType;
|
||||
submitted?: Date;
|
||||
wants_scheduled: boolean;
|
||||
constructor(options?: PublicReportComplianceOptions) {
|
||||
super(options);
|
||||
|
|
@ -335,6 +340,9 @@ export class PublicReportCompliance extends PublicReport {
|
|||
this.permission_type = toPermissionType(
|
||||
options?.permission_type ?? PermissionType.UNSELECTED,
|
||||
);
|
||||
this.submitted = options?.submitted
|
||||
? new Date(options!.submitted)
|
||||
: undefined;
|
||||
this.wants_scheduled = options?.wants_scheduled ?? false;
|
||||
}
|
||||
static fromJSON(json: PublicReportComplianceDTO): PublicReportCompliance {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue