define defaults on the model, simplify create relay payload
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
ref
|
||||
todo.md
|
||||
node_modules
|
||||
target
|
||||
data
|
||||
|
||||
@@ -36,6 +36,20 @@ pub struct Tenant {
|
||||
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)]
|
||||
pub struct Relay {
|
||||
pub id: String,
|
||||
@@ -58,3 +72,29 @@ pub struct Relay {
|
||||
pub push_enabled: 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 subdomain: String,
|
||||
pub plan: String,
|
||||
pub info_name: Option<String>,
|
||||
pub info_icon: Option<String>,
|
||||
pub info_description: Option<String>,
|
||||
pub policy_public_join: Option<i64>,
|
||||
pub policy_strip_signatures: Option<i64>,
|
||||
pub groups_enabled: Option<i64>,
|
||||
pub management_enabled: Option<i64>,
|
||||
pub blossom_enabled: Option<i64>,
|
||||
pub livekit_enabled: Option<i64>,
|
||||
pub push_enabled: Option<i64>,
|
||||
pub info_name: String,
|
||||
pub info_icon: String,
|
||||
pub info_description: String,
|
||||
pub policy_public_join: i64,
|
||||
pub policy_strip_signatures: i64,
|
||||
pub groups_enabled: i64,
|
||||
pub management_enabled: i64,
|
||||
pub blossom_enabled: i64,
|
||||
pub livekit_enabled: i64,
|
||||
pub push_enabled: i64,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -116,20 +116,17 @@ pub async fn create_relay(
|
||||
schema: relay_id.clone(),
|
||||
subdomain: payload.subdomain,
|
||||
plan: payload.plan,
|
||||
stripe_subscription_item_id: None,
|
||||
status: RELAY_STATUS_ACTIVE.to_string(),
|
||||
sync_error: String::new(),
|
||||
info_name: payload.info_name.unwrap_or_default(),
|
||||
info_icon: payload.info_icon.unwrap_or_default(),
|
||||
info_description: payload.info_description.unwrap_or_default(),
|
||||
policy_public_join: payload.policy_public_join.unwrap_or(0),
|
||||
policy_strip_signatures: payload.policy_strip_signatures.unwrap_or(0),
|
||||
groups_enabled: payload.groups_enabled.unwrap_or(1),
|
||||
management_enabled: payload.management_enabled.unwrap_or(1),
|
||||
blossom_enabled: payload.blossom_enabled.unwrap_or(0),
|
||||
livekit_enabled: payload.livekit_enabled.unwrap_or(0),
|
||||
push_enabled: payload.push_enabled.unwrap_or(1),
|
||||
synced: 0,
|
||||
info_name: payload.info_name,
|
||||
info_icon: payload.info_icon,
|
||||
info_description: payload.info_description,
|
||||
policy_public_join: payload.policy_public_join,
|
||||
policy_strip_signatures: payload.policy_strip_signatures,
|
||||
groups_enabled: payload.groups_enabled,
|
||||
management_enabled: payload.management_enabled,
|
||||
blossom_enabled: payload.blossom_enabled,
|
||||
livekit_enabled: payload.livekit_enabled,
|
||||
push_enabled: payload.push_enabled,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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_strip_signatures = parse_bool_default(relay.policy_strip_signatures, 0);
|
||||
relay.groups_enabled = parse_bool_default(relay.groups_enabled, 1);
|
||||
|
||||
@@ -73,12 +73,9 @@ pub async fn create_tenant(
|
||||
|
||||
let tenant = Tenant {
|
||||
pubkey: pubkey.clone(),
|
||||
nwc_url: String::new(),
|
||||
nwc_error: None,
|
||||
created_at: Utc::now().timestamp(),
|
||||
stripe_customer_id,
|
||||
stripe_subscription_id: None,
|
||||
past_due_at: None,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
match api.command.create_tenant(&tenant).await {
|
||||
|
||||
Reference in New Issue
Block a user