Save access information to database
This commit is contained in:
parent
ba76c8b1db
commit
083c4ddae9
6 changed files with 94 additions and 30 deletions
|
|
@ -97,7 +97,7 @@ func PublicReportMessageCreate(ctx context.Context, user User, public_id, messag
|
|||
return nil, errors.New("no contact methods available")
|
||||
}
|
||||
}
|
||||
func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_setter models.PublicreportReportSetter, address *types.Address, location *types.Location) (*types.PublicReportCompliance, error) {
|
||||
func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_setter *models.PublicreportReportSetter, compliance_setter *models.PublicreportComplianceSetter, address *types.Address, location *types.Location) (*types.PublicReportCompliance, error) {
|
||||
txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create txn: %w", err)
|
||||
|
|
@ -107,16 +107,34 @@ func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("query report existence: %w", err)
|
||||
}
|
||||
compliance, err := models.FindPublicreportCompliance(ctx, txn, report.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("find compliance %d: %w", report.ID, err)
|
||||
}
|
||||
// Avoid attempting to perform an empty update
|
||||
if report_setter.LatlngAccuracyValue.IsValue() ||
|
||||
report_setter.ReporterEmail.IsValue() ||
|
||||
report_setter.ReporterName.IsValue() ||
|
||||
report_setter.ReporterPhone.IsValue() {
|
||||
err = report.Update(ctx, txn, &report_setter)
|
||||
err = report.Update(ctx, txn, report_setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("update report: %w", err)
|
||||
}
|
||||
}
|
||||
// Avoid attempting to perform an empty update
|
||||
if compliance_setter.AccessInstructions.IsValue() ||
|
||||
compliance_setter.AvailabilityNotes.IsValue() ||
|
||||
compliance_setter.Comments.IsValue() ||
|
||||
compliance_setter.GateCode.IsValue() ||
|
||||
compliance_setter.HasDog.IsValue() ||
|
||||
compliance_setter.PermissionType.IsValue() ||
|
||||
compliance_setter.ReportPhoneCanText.IsValue() ||
|
||||
compliance_setter.WantsScheduled.IsValue() {
|
||||
err = compliance.Update(ctx, txn, compliance_setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("update compliance: %w", err)
|
||||
}
|
||||
}
|
||||
if address != nil {
|
||||
err = publicReportUpdateAddress(ctx, txn, report, *address)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ func ByID(ctx context.Context, public_id string) (*types.PublicReport, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("query to rows: %w", err)
|
||||
}
|
||||
log.Debug().Str("public_id", public_id).Int("len", len(reports)).Msg("querying for publicreport by ID")
|
||||
if len(reports) != 1 {
|
||||
return nil, fmt.Errorf("reports returned: %d", len(reports))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,16 +87,6 @@ func (res *publicreportR) ImageCreate(ctx context.Context, r *http.Request, n nu
|
|||
return &image{Status: "ok"}, nil
|
||||
}
|
||||
|
||||
type publicreportComplianceForm struct {
|
||||
Address *types.Address `schema:"address"`
|
||||
ClientID string `schema:"client_id"`
|
||||
Comments *string `schema:"comments"`
|
||||
DistrictID string `schema:"district"`
|
||||
Location *types.Location `schema:"location"`
|
||||
Locator *Locator `schema:"locator"`
|
||||
Reporter *types.Contact `schema:"reporter"`
|
||||
}
|
||||
|
||||
func populateDistrictURI(report *types.PublicReport, r *router) error {
|
||||
var district_uri string
|
||||
var err error
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
||||
"github.com/gorilla/mux"
|
||||
//"github.com/rs/zerolog/log"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func Compliance(r *router) *complianceR {
|
||||
|
|
@ -96,6 +96,21 @@ func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicrep
|
|||
}, nil
|
||||
}
|
||||
|
||||
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"`
|
||||
ClientID string `schema:"client_id" json:"client_id"`
|
||||
Comments omit.Val[string] `schema:"comments" json:"comments"`
|
||||
GateCode omit.Val[string] `schema:"gate_code" json:"gate_code"`
|
||||
HasDog omitnull.Val[bool] `schema:"has_dog" json:"has_dog"`
|
||||
Location omit.Val[types.Location] `schema:"location" json:"location"`
|
||||
PermissionType omit.Val[enums.Permissionaccesstype] `schema:"permission_type" json:"permission_type"`
|
||||
Reporter omit.Val[types.Contact] `schema:"reporter" json:"reporter"`
|
||||
ReportPhoneCanText omitnull.Val[bool] `schema:"report_phone_can_text" json:"report_phone_can_text"`
|
||||
WantsScheduled omitnull.Val[bool] `schema:"wants_scheduled" json:"wants_scheduled"`
|
||||
}
|
||||
|
||||
func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicreportComplianceForm) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["id"]
|
||||
|
|
@ -103,25 +118,63 @@ func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicr
|
|||
return nil, nhttp.NewBadRequest("You must provide an ID")
|
||||
}
|
||||
report_setter := models.PublicreportReportSetter{}
|
||||
if prf.Location != nil {
|
||||
//report_setter.Latitude = omit.From(prf.Location.Latitude)
|
||||
//report_setter.Longitude = omit.From(prf.Location.Longitude)
|
||||
if prf.Location.Accuracy != nil {
|
||||
report_setter.LatlngAccuracyValue = omit.From(*prf.Location.Accuracy)
|
||||
var location *types.Location
|
||||
if prf.Location.IsValue() {
|
||||
l := prf.Location.MustGet()
|
||||
location = &l
|
||||
if location.Accuracy != nil {
|
||||
report_setter.LatlngAccuracyValue = omit.From(*location.Accuracy)
|
||||
}
|
||||
}
|
||||
if prf.Reporter != nil {
|
||||
if prf.Reporter.Email != nil {
|
||||
report_setter.ReporterEmail = omit.From(*prf.Reporter.Email)
|
||||
if prf.Reporter.IsValue() {
|
||||
reporter := prf.Reporter.MustGet()
|
||||
if reporter.Email != nil {
|
||||
report_setter.ReporterEmail = omit.From(*reporter.Email)
|
||||
}
|
||||
if prf.Reporter.Name != nil {
|
||||
report_setter.ReporterName = omit.From(*prf.Reporter.Name)
|
||||
if reporter.Name != nil {
|
||||
report_setter.ReporterName = omit.From(*reporter.Name)
|
||||
}
|
||||
if prf.Reporter.Phone != nil {
|
||||
report_setter.ReporterPhone = omit.From(*prf.Reporter.Phone)
|
||||
if reporter.Phone != nil {
|
||||
report_setter.ReporterPhone = omit.From(*reporter.Phone)
|
||||
}
|
||||
}
|
||||
report, err := platform.PublicReportUpdateCompliance(ctx, public_id, report_setter, prf.Address, prf.Location)
|
||||
var address *types.Address
|
||||
if prf.Address.IsValue() {
|
||||
a := prf.Address.MustGet()
|
||||
address = &a
|
||||
}
|
||||
compliance_setter := models.PublicreportComplianceSetter{}
|
||||
if prf.AccessInstructions.IsValue() {
|
||||
compliance_setter.AccessInstructions = prf.AccessInstructions
|
||||
}
|
||||
if prf.AvailabilityNotes.IsValue() {
|
||||
compliance_setter.AvailabilityNotes = prf.AvailabilityNotes
|
||||
}
|
||||
if prf.Comments.IsValue() {
|
||||
compliance_setter.Comments = prf.Comments
|
||||
}
|
||||
if prf.GateCode.IsValue() {
|
||||
compliance_setter.GateCode = prf.GateCode
|
||||
}
|
||||
if prf.HasDog.IsValue() {
|
||||
compliance_setter.HasDog = prf.HasDog
|
||||
}
|
||||
if prf.PermissionType.IsValue() {
|
||||
compliance_setter.PermissionType = prf.PermissionType
|
||||
}
|
||||
if prf.ReportPhoneCanText.IsValue() {
|
||||
compliance_setter.ReportPhoneCanText = prf.ReportPhoneCanText
|
||||
}
|
||||
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")
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,10 +136,10 @@ function doPermission() {
|
|||
}
|
||||
console.log("report.value.has_dog", report.value.has_dog);
|
||||
updateReport({
|
||||
access: report.value.access,
|
||||
access_instructions: report.value.access_instructions,
|
||||
gate_code: report.value.gate_code,
|
||||
has_dog: report.value.has_dog,
|
||||
permission_type: report.value.access,
|
||||
wants_scheduled: report.value.wants_scheduled,
|
||||
});
|
||||
}
|
||||
|
|
@ -181,6 +181,7 @@ async function updateReport(updates: ComplianceUpdate) {
|
|||
}
|
||||
}
|
||||
async function uploadImages(images: Image[]) {
|
||||
if (images.length == 0) return;
|
||||
isUploading.value = true;
|
||||
const formData = new FormData();
|
||||
images.map(async (image, index) => {
|
||||
|
|
|
|||
|
|
@ -134,18 +134,19 @@ export interface Image {
|
|||
uuid: string;
|
||||
}
|
||||
export interface ComplianceUpdate {
|
||||
access?: string;
|
||||
access_instructions?: string;
|
||||
address?: Address;
|
||||
availability_notes?: string;
|
||||
comments?: string;
|
||||
contact?: Contact;
|
||||
gate_code?: string;
|
||||
has_dog?: boolean;
|
||||
//id: string;
|
||||
//images?: Image[];
|
||||
location?: Location;
|
||||
permission?: Permissions;
|
||||
permission_type?: string;
|
||||
reporter?: Contact;
|
||||
//uri: string;
|
||||
report_phone_can_text?: boolean;
|
||||
wants_scheduled?: boolean;
|
||||
}
|
||||
export interface PublicReportDTO {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue