mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Create a label for new group if not exists
This commit is contained in:
parent
ce7cb1efac
commit
9f260c1442
2 changed files with 31 additions and 0 deletions
|
|
@ -38,6 +38,7 @@ import { In } from 'typeorm'
|
|||
import { getPageByParam } from '../../elastic/pages'
|
||||
import { enqueueRecommendation } from '../../utils/createTask'
|
||||
import { env } from '../../env'
|
||||
import { createLabel } from '../../services/labels'
|
||||
|
||||
export const createGroupResolver = authorized<
|
||||
CreateGroupSuccess,
|
||||
|
|
@ -71,6 +72,9 @@ export const createGroupResolver = authorized<
|
|||
expiresInDays: input.expiresInDays,
|
||||
})
|
||||
|
||||
// create a new label for the group
|
||||
await createLabel(userData, { name: input.name })
|
||||
|
||||
const inviteUrl = getInviteUrl(invite)
|
||||
const user = userDataToUser(userData)
|
||||
|
||||
|
|
|
|||
|
|
@ -76,3 +76,30 @@ export const getLabelsByIds = async (
|
|||
select: ['id', 'name', 'color', 'description', 'createdAt'],
|
||||
})
|
||||
}
|
||||
|
||||
export const createLabel = async (
|
||||
user: User,
|
||||
label: {
|
||||
name: string
|
||||
color?: string
|
||||
description?: string
|
||||
}
|
||||
): Promise<Label> => {
|
||||
const existingLabel = await getRepository(Label).findOneBy({
|
||||
user: { id: user.id },
|
||||
name: ILike(label.name),
|
||||
})
|
||||
|
||||
if (existingLabel) {
|
||||
return existingLabel
|
||||
}
|
||||
|
||||
// create a new label and assign a random color if not provided
|
||||
label.color =
|
||||
label.color || `#${Math.floor(Math.random() * 16777215).toString(16)}`
|
||||
|
||||
return getRepository(Label).save({
|
||||
...label,
|
||||
user: { id: user.id },
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue