firefish/packages/backend-rs/src/util/note.rs

26 lines
720 B
Rust
Raw Normal View History

use crate::database::{JsDbConn, NapiDbErrExt};
use crate::model::entity::note;
use sea_orm::prelude::*;
/**
* Returns true if user {user_id}
* has any renote of note {renote_id}
* except the specified renote {excluded_note_id}
*/
#[napi_derive::napi]
pub async fn has_other_renote_of_this_note(
conn: &JsDbConn,
user_id: String,
renote_id: String,
excluded_note_id: String,
) -> napi::Result<bool> {
note::Entity::find()
.filter(note::Column::UserId.eq(user_id))
.filter(note::Column::RenoteId.eq(renote_id))
.filter(note::Column::Id.ne(excluded_note_id))
.one(conn.inner())
.await
.map(|row| row.is_some())
.map_err(NapiDbErrExt::into)
}