chore: (wip) suspend bindings

This commit is contained in:
Paul Makles
2024-08-29 20:17:35 +01:00
parent 949a0cf649
commit ae2194cce8
2 changed files with 30 additions and 2 deletions

View File

@@ -89,11 +89,19 @@ struct ResultBinding<T> {
}
macro_rules! shim {
($cx: ident, $name: ident, $( $variable: ident $type: ident $id: expr )+, | $db: ident | $closure: expr, $( $arg: expr, )+) => {
($cx: ident, $name: ident, $( $variable: ident $type: ident $id: expr )*, $( $model: ident $modelType: ident $modelId: expr )*, | $db: ident | $closure: expr, $( $arg: expr, )+) => {
fn $name(mut cx: FunctionContext) -> JsResult<JsPromise> {
$(
let $variable = cx.argument::<$type>($id)?.value(&mut cx);
)+
)*
$(
let mut $model = if let Model::$modelType(value) = cx.argument::<JsBox<Model>>($modelId)?.give() {
value
} else {
unreachable!()
};
)*
let (db, channel) = cx.this::<JsBox<DatabaseBinding>>()?.take();
let (deferred, promise) = cx.promise();
@@ -158,6 +166,7 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
proc_channels_create_dm,
user_a JsString 0
user_b JsString 1,
,
|db| async move {
let user_a = db.fetch_user(&user_a).await?;
let user_b = db.fetch_user(&user_b).await?;
@@ -166,5 +175,16 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
&userA, &userB,
);
shim!(
cx,
proc_users_suspend,
,
user User 0,
|db| async move {
user.suspend(&db).await
},
&user,
);
Ok(())
}

View File

@@ -662,6 +662,14 @@ impl User {
}
}
/// Suspend the user
pub async fn suspend(&mut self, db: &Database) -> Result<()> {
// Remove sessions (logout all)
// Mark user as suspended
// Disable account
Ok(())
}
/// Mark as deleted
pub async fn mark_deleted(&mut self, db: &Database) -> Result<()> {
self.update(