Skip to content

Commit

Permalink
return organization info when it is created, api docs updated
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Jan 16, 2025
1 parent 073b62f commit 5ded7d3
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 22 deletions.
92 changes: 74 additions & 18 deletions api/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ This endpoint only returns the addresses of the organizations where the current
"role": "admin",
"organization": {
"address": "0x...",
"name": "Test Organization",
"website": "",
"createdAt": "2025-01-16T11:56:04Z",
"type": "community",
"description": "My amazing testing organization",
"size": 10,
Expand All @@ -326,16 +327,25 @@ This endpoint only returns the addresses of the organizations where the current
"subdomain": "mysubdomain",
"timezone": "GMT+2",
"active": true,
"communications": false,
"parent": {
"...": "..."
"...": "..."
},
"subscription":{
"PlanID":3,
"StartDate":"2024-11-07T15:25:49.218Z",
"RenewalDate":"2025-11-07T15:25:49.218Z",
"Active":true,
"MaxCensusSize":10
"subscription": {
"planID": 2,
"startDate": "2025-01-16T11:56:04.079Z",
"renewalDate": "0001-01-01T00:00:00Z",
"lastPaymentDate": "0001-01-01T00:00:00Z",
"active": true,
"maxCensusSize": 50,
"email": ""
},
"counters": {
"sentSMS": 0,
"sentEmails": 0,
"subOrgs": 0,
"members": 0
}
}
}
]
Expand Down Expand Up @@ -481,6 +491,41 @@ If the user want to create a sub org, the address of the root organization must
}
```

* **Response**
```json
{
"address": "0x23eE5d3ECE54a275FD75cF25E77C3bBeCe3CF3f7",
"website": "",
"createdAt": "2025-01-16T11:56:04Z",
"type": "community",
"size": "10",
"color": "#ff0000",
"subdomain": "mysubdomain",
"country": "Spain",
"timezone": "GMT+2",
"active": true,
"communications": false,
"parent": {
"...": {}
},
"subscription": {
"planID": 2,
"startDate": "2025-01-16T11:56:04.079Z",
"renewalDate": "0001-01-01T00:00:00Z",
"lastPaymentDate": "0001-01-01T00:00:00Z",
"active": true,
"maxCensusSize": 50,
"email": ""
},
"counters": {
"sentSMS": 0,
"sentEmails": 0,
"subOrgs": 0,
"members": 0
}
}
```

* **Errors**

| HTTP Status | Error code | Message |
Expand Down Expand Up @@ -536,23 +581,34 @@ Only the following parameters can be changed. Every parameter is optional.
* **Response**
```json
{
"address": "0x1234",
"name": "Test Organization",
"website": "https://[...].com",
"address": "0x23eE5d3ECE54a275FD75cF25E77C3bBeCe3CF3f7",
"website": "",
"createdAt": "2025-01-16T11:56:04Z",
"type": "community",
"description": "My amazing testing organization",
"size": "10",
"color": "#ff0000",
"logo": "https://[...].png",
"header": "https://[...].png",
"subdomain": "mysubdomain",
"country": "Germany",
"country": "Spain",
"timezone": "GMT+2",
"Language": "EN",
"active": true,
"communications": true,
"communications": false,
"parent": {
"...": "..."
"...": {}
},
"subscription": {
"planID": 2,
"startDate": "2025-01-16T11:56:04.079Z",
"renewalDate": "0001-01-01T00:00:00Z",
"lastPaymentDate": "0001-01-01T00:00:00Z",
"active": true,
"maxCensusSize": 50,
"email": ""
},
"counters": {
"sentSMS": 0,
"sentEmails": 0,
"subOrgs": 0,
"members": 0
}
}
```
Expand Down
10 changes: 6 additions & 4 deletions api/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ func (a *API) createOrganizationHandler(w http.ResponseWriter, r *http.Request)
return
}
parentOrg := ""
var dbParentOrg *db.Organization
if orgInfo.Parent != nil {
dbParentOrg, _, err := a.db.Organization(orgInfo.Parent.Address, false)
dbParentOrg, _, err = a.db.Organization(orgInfo.Parent.Address, false)
if err != nil {
if err == db.ErrNotFound {
ErrOrganizationNotFound.Withf("parent organization not found").Write(w)
Expand Down Expand Up @@ -79,7 +80,7 @@ func (a *API) createOrganizationHandler(w http.ResponseWriter, r *http.Request)
MaxCensusSize: defaultPlan.Organization.MaxCensus,
}
// create the organization
if err := a.db.SetOrganization(&db.Organization{
dbOrg := &db.Organization{
Address: signer.AddressString(),
Creator: user.Email,
CreatedAt: time.Now(),
Expand All @@ -96,7 +97,8 @@ func (a *API) createOrganizationHandler(w http.ResponseWriter, r *http.Request)
TokensRemaining: 0,
Parent: parentOrg,
Subscription: *subscription,
}); err != nil {
}
if err := a.db.SetOrganization(dbOrg); err != nil {
if err == db.ErrAlreadyExists {
ErrInvalidOrganizationData.WithErr(err).Write(w)
return
Expand All @@ -105,7 +107,7 @@ func (a *API) createOrganizationHandler(w http.ResponseWriter, r *http.Request)
return
}
// send the organization back to the user
httpWriteOK(w)
httpWriteJSON(w, organizationFromDB(dbOrg, dbParentOrg))
}

// organizationInfoHandler handles the request to get the information of an
Expand Down

0 comments on commit 5ded7d3

Please sign in to comment.