feat: ref codes

closes #8
This commit is contained in:
2025-03-05 11:11:57 +00:00
parent b5654a533a
commit 6b909ba5bd
8 changed files with 32 additions and 12 deletions

View File

@ -14,9 +14,11 @@ pub struct User {
pub pubkey: Vec<u8>,
/// When this user first started using the service (first login)
pub created: DateTime<Utc>,
/// Users email address for notifications
pub email: Option<String>,
pub contact_nip4: bool,
/// If user should be contacted via NIP-17 for notifications
pub contact_nip17: bool,
/// If user should be contacted via email for notifications
pub contact_email: bool,
}
@ -222,6 +224,8 @@ pub struct Vm {
pub mac_address: String,
/// Is the VM deleted
pub deleted: bool,
/// Referral code (recorded during ordering)
pub ref_code: Option<String>,
}
#[derive(FromRow, Clone, Debug, Default)]

View File

@ -69,7 +69,7 @@ impl LNVpsDb for LNVpsDbMysql {
}
async fn delete_user(&self, _id: u64) -> Result<()> {
todo!()
bail!("Deleting users is not supported")
}
async fn insert_user_ssh_key(&self, new_key: &UserSshKey) -> Result<u64> {
@ -247,7 +247,7 @@ impl LNVpsDb for LNVpsDbMysql {
}
async fn insert_vm(&self, vm: &Vm) -> Result<u64> {
Ok(sqlx::query("insert into vm(host_id,user_id,image_id,template_id,ssh_key_id,created,expires,disk_id,mac_address) values(?, ?, ?, ?, ?, ?, ?, ?, ?) returning id")
Ok(sqlx::query("insert into vm(host_id,user_id,image_id,template_id,ssh_key_id,created,expires,disk_id,mac_address,ref_code) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?) returning id")
.bind(vm.host_id)
.bind(vm.user_id)
.bind(vm.image_id)
@ -257,6 +257,7 @@ impl LNVpsDb for LNVpsDbMysql {
.bind(vm.expires)
.bind(vm.disk_id)
.bind(&vm.mac_address)
.bind(&vm.ref_code)
.fetch_one(&self.db)
.await
.map_err(Error::new)?