fix: LABEL_ALREADY_EXIST bug occured during label creation
* comparing both user_id and label name when looking for an existing matching label
This commit is contained in:
@ -46,9 +46,12 @@ export const labelRepository = appDataSource.getRepository(Label).extend({
|
||||
return this.findOneBy({ id })
|
||||
},
|
||||
|
||||
findByName(name: string) {
|
||||
findByName(name: string, userId: string) {
|
||||
return this.createQueryBuilder()
|
||||
.where('LOWER(name) = LOWER(:name)', { name }) // case insensitive
|
||||
.where('user_id = :userId AND LOWER(name) = LOWER(:name)', {
|
||||
name,
|
||||
userId,
|
||||
}) // case insensitive
|
||||
.getOne()
|
||||
},
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@ export const createLabelResolver = authorized<
|
||||
CreateLabelError,
|
||||
MutationCreateLabelArgs
|
||||
>(async (_, { input }, { authTrx, uid }) => {
|
||||
const existingLabel = await labelRepository.findByName(input.name)
|
||||
const existingLabel = await labelRepository.findByName(input.name, uid)
|
||||
if (existingLabel) {
|
||||
return {
|
||||
errorCodes: [CreateLabelErrorCode.LabelAlreadyExists],
|
||||
|
||||
Reference in New Issue
Block a user