diff --git a/internal/controller/datacenter.go b/internal/controller/datacenter.go index b4d28fcb..f195459f 100644 --- a/internal/controller/datacenter.go +++ b/internal/controller/datacenter.go @@ -169,8 +169,15 @@ func (c DatacenterController) DeleteDatacentersDatacenterID(params datacenters.D return datacenters.NewDeleteDatacentersDatacenterIDDefault(403).WithPayload(utils.PolicyForbidden) } - // todo: check for related members - sql := c.db.Rebind(`UPDATE datacenter SET provisioning_status = 'PENDING_DELETE' WHERE id = ?`) + var count int + sql := c.db.Rebind(`SELECT count(*) FROM member WHERE datacenter_id = ?`) + if err := c.db.Get(&count, sql, datacenter.ID); err != nil { + panic(err) + } else if count > 0 { + return datacenters.NewDeleteDatacentersDatacenterIDDefault(409).WithPayload(utils.DatacenterInUse) + } + + sql = c.db.Rebind(`UPDATE datacenter SET provisioning_status = 'PENDING_DELETE' WHERE id = ?`) res, err := c.db.Exec(sql, params.DatacenterID) if err != nil { var pe *pq.Error diff --git a/internal/driver/akamai/domain.go b/internal/driver/akamai/domain.go index 81114ec5..0be7dc9b 100644 --- a/internal/driver/akamai/domain.go +++ b/internal/driver/akamai/domain.go @@ -83,7 +83,8 @@ func (s *AkamaiAgent) FetchAndSyncDomains(domains []string) error { var datacenters []string for _, domain := range res { for _, datacenter := range domain.Datacenters { - if datacenter.ProvisioningStatus != models.DatacenterProvisioningStatusACTIVE { + if datacenter.ProvisioningStatus != models.DatacenterProvisioningStatusACTIVE && + datacenter.ProvisioningStatus != models.DatacenterProvisioningStatusPENDINGDELETE { datacenters = append(datacenters, datacenter.Id) } }