Skip to content

Commit

Permalink
* Update maxDuration read from stripe as integer
Browse files Browse the repository at this point in the history
  • Loading branch information
emmdim committed Jan 31, 2025
1 parent 54976ad commit 921755c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
6 changes: 3 additions & 3 deletions db/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ type PlanLimits struct {
MaxProcesses int `json:"maxProcesses" bson:"maxProcesses"`
MaxCensus int `json:"maxCensus" bson:"maxCensus"`
// Max process duration in days
MaxDuration string `json:"maxDuration" bson:"maxDuration"`
CustomURL bool `json:"customURL" bson:"customURL"`
Drafts int `json:"drafts" bson:"drafts"`
MaxDuration int `json:"maxDuration" bson:"maxDuration"`
CustomURL bool `json:"customURL" bson:"customURL"`
Drafts int `json:"drafts" bson:"drafts"`
}

type VotingTypes struct {
Expand Down
17 changes: 2 additions & 15 deletions subscriptions/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package subscriptions

import (
"fmt"
"strconv"

"github.com/vocdoni/saas-backend/db"
"go.vocdoni.io/proto/build/go/models"
Expand Down Expand Up @@ -74,11 +73,8 @@ func (p *Subscriptions) hasElectionMetadataPermissions(process *models.NewProces
}

// check PROCESS DURATION
duration, err := daysDurationToSeconds(plan.Organization.MaxDuration)
if err != nil {
return false, fmt.Errorf("could not convert duration to seconds: %v", err)
}
if process.Process.Duration > duration {
duration := plan.Organization.MaxDuration * 24 * 60 * 60
if process.Process.Duration > uint32(duration) {
return false, fmt.Errorf("duration is greater than the allowed")
}

Expand Down Expand Up @@ -177,12 +173,3 @@ func (p *Subscriptions) HasDBPersmission(userEmail, orgAddress string, permissio
}
return false, fmt.Errorf("permission not found")
}

// In the plan the duration is given in a string
func daysDurationToSeconds(duration string) (uint32, error) {
num, err := strconv.ParseUint(duration, 10, 32)
if err != nil {
return 0, err
}
return uint32(num * 24 * 60 * 60), nil
}

0 comments on commit 921755c

Please sign in to comment.