No Duplicating Tags (#2505)

* Error when trying to make tags with same name

* Formatting
This commit is contained in:
Arnab Chakraborty 2024-05-24 14:20:20 -04:00 committed by GitHub
parent 89645edc73
commit a63d66da4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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");