mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-06-30 11:23:33 +00:00
No Duplicating Tags (#2505)
* Error when trying to make tags with same name * Formatting
This commit is contained in:
parent
89645edc73
commit
a63d66da4c
|
@ -88,6 +88,22 @@ pub(crate) fn mount() -> AlphaRouter<Ctx> {
|
|||
.procedure("create", {
|
||||
R.with2(library())
|
||||
.mutation(|(_, library), args: TagCreateArgs| async move {
|
||||
// Check if tag with the same name already exists
|
||||
let existing_tag = library
|
||||
.db
|
||||
.tag()
|
||||
.find_many(vec![tag::name::equals(Some(args.name.clone()))])
|
||||
.select(tag::select!({ id }))
|
||||
.exec()
|
||||
.await?;
|
||||
|
||||
if !existing_tag.is_empty() {
|
||||
return Err(rspc::Error::new(
|
||||
ErrorCode::Conflict,
|
||||
"Tag with the same name already exists".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let created_tag = args.exec(&library).await?;
|
||||
|
||||
invalidate_query!(library, "tags.list");
|
||||
|
|
Loading…
Reference in a new issue