Skip to content

Commit

Permalink
No Duplicating Tags (#2505)
Browse files Browse the repository at this point in the history
* Error when trying to make tags with same name

* Formatting
  • Loading branch information
Rocky43007 authored May 24, 2024
1 parent 89645ed commit a63d66d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/src/api/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit a63d66d

Please sign in to comment.