define defaults on the model, simplify create relay payload
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
ref
|
ref
|
||||||
|
todo.md
|
||||||
node_modules
|
node_modules
|
||||||
target
|
target
|
||||||
data
|
data
|
||||||
|
|||||||
@@ -36,6 +36,20 @@ pub struct Tenant {
|
|||||||
pub past_due_at: Option<i64>,
|
pub past_due_at: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Tenant {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
pubkey: String::new(),
|
||||||
|
nwc_url: String::new(),
|
||||||
|
nwc_error: None,
|
||||||
|
created_at: 0,
|
||||||
|
stripe_customer_id: String::new(),
|
||||||
|
stripe_subscription_id: None,
|
||||||
|
past_due_at: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
|
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
|
||||||
pub struct Relay {
|
pub struct Relay {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
@@ -58,3 +72,29 @@ pub struct Relay {
|
|||||||
pub push_enabled: i64,
|
pub push_enabled: i64,
|
||||||
pub synced: i64,
|
pub synced: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Relay {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
id: String::new(),
|
||||||
|
tenant: String::new(),
|
||||||
|
schema: String::new(),
|
||||||
|
subdomain: String::new(),
|
||||||
|
plan: String::new(),
|
||||||
|
stripe_subscription_item_id: None,
|
||||||
|
status: RELAY_STATUS_ACTIVE.to_string(),
|
||||||
|
sync_error: String::new(),
|
||||||
|
info_name: String::new(),
|
||||||
|
info_icon: String::new(),
|
||||||
|
info_description: String::new(),
|
||||||
|
policy_public_join: 0,
|
||||||
|
policy_strip_signatures: 0,
|
||||||
|
groups_enabled: 1,
|
||||||
|
management_enabled: 1,
|
||||||
|
blossom_enabled: 0,
|
||||||
|
livekit_enabled: 0,
|
||||||
|
push_enabled: 1,
|
||||||
|
synced: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,16 +21,16 @@ pub struct CreateRelayRequest {
|
|||||||
pub tenant: String,
|
pub tenant: String,
|
||||||
pub subdomain: String,
|
pub subdomain: String,
|
||||||
pub plan: String,
|
pub plan: String,
|
||||||
pub info_name: Option<String>,
|
pub info_name: String,
|
||||||
pub info_icon: Option<String>,
|
pub info_icon: String,
|
||||||
pub info_description: Option<String>,
|
pub info_description: String,
|
||||||
pub policy_public_join: Option<i64>,
|
pub policy_public_join: i64,
|
||||||
pub policy_strip_signatures: Option<i64>,
|
pub policy_strip_signatures: i64,
|
||||||
pub groups_enabled: Option<i64>,
|
pub groups_enabled: i64,
|
||||||
pub management_enabled: Option<i64>,
|
pub management_enabled: i64,
|
||||||
pub blossom_enabled: Option<i64>,
|
pub blossom_enabled: i64,
|
||||||
pub livekit_enabled: Option<i64>,
|
pub livekit_enabled: i64,
|
||||||
pub push_enabled: Option<i64>,
|
pub push_enabled: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@@ -116,20 +116,17 @@ pub async fn create_relay(
|
|||||||
schema: relay_id.clone(),
|
schema: relay_id.clone(),
|
||||||
subdomain: payload.subdomain,
|
subdomain: payload.subdomain,
|
||||||
plan: payload.plan,
|
plan: payload.plan,
|
||||||
stripe_subscription_item_id: None,
|
info_name: payload.info_name,
|
||||||
status: RELAY_STATUS_ACTIVE.to_string(),
|
info_icon: payload.info_icon,
|
||||||
sync_error: String::new(),
|
info_description: payload.info_description,
|
||||||
info_name: payload.info_name.unwrap_or_default(),
|
policy_public_join: payload.policy_public_join,
|
||||||
info_icon: payload.info_icon.unwrap_or_default(),
|
policy_strip_signatures: payload.policy_strip_signatures,
|
||||||
info_description: payload.info_description.unwrap_or_default(),
|
groups_enabled: payload.groups_enabled,
|
||||||
policy_public_join: payload.policy_public_join.unwrap_or(0),
|
management_enabled: payload.management_enabled,
|
||||||
policy_strip_signatures: payload.policy_strip_signatures.unwrap_or(0),
|
blossom_enabled: payload.blossom_enabled,
|
||||||
groups_enabled: payload.groups_enabled.unwrap_or(1),
|
livekit_enabled: payload.livekit_enabled,
|
||||||
management_enabled: payload.management_enabled.unwrap_or(1),
|
push_enabled: payload.push_enabled,
|
||||||
blossom_enabled: payload.blossom_enabled.unwrap_or(0),
|
..Default::default()
|
||||||
livekit_enabled: payload.livekit_enabled.unwrap_or(0),
|
|
||||||
push_enabled: payload.push_enabled.unwrap_or(1),
|
|
||||||
synced: 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let relay = prepare_relay(&api, relay).map_err(validation_error)?;
|
let relay = prepare_relay(&api, relay).map_err(validation_error)?;
|
||||||
@@ -286,9 +283,6 @@ fn prepare_relay(api: &Api, mut relay: Relay) -> Result<Relay, RelayValidationEr
|
|||||||
return Err(RelayValidationError::PremiumFeature);
|
return Err(RelayValidationError::PremiumFeature);
|
||||||
}
|
}
|
||||||
|
|
||||||
if relay.status.is_empty() {
|
|
||||||
relay.status = RELAY_STATUS_ACTIVE.to_string();
|
|
||||||
}
|
|
||||||
relay.policy_public_join = parse_bool_default(relay.policy_public_join, 0);
|
relay.policy_public_join = parse_bool_default(relay.policy_public_join, 0);
|
||||||
relay.policy_strip_signatures = parse_bool_default(relay.policy_strip_signatures, 0);
|
relay.policy_strip_signatures = parse_bool_default(relay.policy_strip_signatures, 0);
|
||||||
relay.groups_enabled = parse_bool_default(relay.groups_enabled, 1);
|
relay.groups_enabled = parse_bool_default(relay.groups_enabled, 1);
|
||||||
|
|||||||
@@ -73,12 +73,9 @@ pub async fn create_tenant(
|
|||||||
|
|
||||||
let tenant = Tenant {
|
let tenant = Tenant {
|
||||||
pubkey: pubkey.clone(),
|
pubkey: pubkey.clone(),
|
||||||
nwc_url: String::new(),
|
|
||||||
nwc_error: None,
|
|
||||||
created_at: Utc::now().timestamp(),
|
created_at: Utc::now().timestamp(),
|
||||||
stripe_customer_id,
|
stripe_customer_id,
|
||||||
stripe_subscription_id: None,
|
..Default::default()
|
||||||
past_due_at: None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match api.command.create_tenant(&tenant).await {
|
match api.command.create_tenant(&tenant).await {
|
||||||
|
|||||||
Reference in New Issue
Block a user