deduplicate labels when there are case-insensitive identical names

This commit is contained in:
Hongbo Wu
2024-04-05 16:27:17 +08:00
parent 6f03b214b5
commit 25fb9fd698

View File

@ -41,21 +41,18 @@ export const findOrCreateLabels = async (
labels: CreateLabelInput[],
userId: string
): Promise<Label[]> => {
// create labels if not exist
await authTrx(
async (tx) =>
tx.withRepository(labelRepository).createLabels(labels, userId),
undefined,
userId
)
// find labels
return authTrx(
async (tx) =>
tx.withRepository(labelRepository).findByNames(
labels.map((l) => l.name),
userId
),
async (tx) => {
const repo = tx.withRepository(labelRepository)
// create labels if not exist
await repo.createLabels(labels, userId)
// find labels by names
return repo.findBy({
name: In(labels.map((l) => l.name)),
user: { id: userId },
})
},
undefined,
userId
)