mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Fix some issue
This commit is contained in:
parent
b942303b18
commit
04cb360c2f
4 changed files with 36 additions and 46 deletions
|
|
@ -25,6 +25,7 @@ import {
|
|||
} from '../../generated/graphql'
|
||||
import {
|
||||
createGroup,
|
||||
createLabelAndRuleForGroup,
|
||||
getInviteUrl,
|
||||
getRecommendationGroups,
|
||||
joinGroup,
|
||||
|
|
@ -38,9 +39,6 @@ import { In } from 'typeorm'
|
|||
import { getPageByParam } from '../../elastic/pages'
|
||||
import { enqueueRecommendation } from '../../utils/createTask'
|
||||
import { env } from '../../env'
|
||||
import { createLabel } from '../../services/labels'
|
||||
import { createRule } from '../../services/rules'
|
||||
import { RuleActionType } from '../../entity/rule'
|
||||
|
||||
export const createGroupResolver = authorized<
|
||||
CreateGroupSuccess,
|
||||
|
|
@ -74,24 +72,7 @@ export const createGroupResolver = authorized<
|
|||
expiresInDays: input.expiresInDays,
|
||||
})
|
||||
|
||||
// create a new label for the group
|
||||
const label = await createLabel(userData, { name: input.name })
|
||||
|
||||
// create a rule to add the label to all pages in the group
|
||||
await createRule(userData, {
|
||||
name: input.name,
|
||||
actions: [
|
||||
{
|
||||
type: RuleActionType.AddLabel,
|
||||
params: [label.id],
|
||||
},
|
||||
{
|
||||
type: RuleActionType.SendNotification,
|
||||
params: [input.name],
|
||||
},
|
||||
],
|
||||
filter: `recommendedBy:${group.name}`,
|
||||
})
|
||||
await createLabelAndRuleForGroup(uid, group.name)
|
||||
|
||||
const inviteUrl = getInviteUrl(invite)
|
||||
const user = userDataToUser(userData)
|
||||
|
|
@ -285,24 +266,7 @@ export const joinGroupResolver = authorized<
|
|||
|
||||
const group = await joinGroup(user, inviteCode)
|
||||
|
||||
// create a new label for the group
|
||||
const label = await createLabel(user, { name: group.name })
|
||||
|
||||
// create a rule to add the label to all pages in the group
|
||||
await createRule(user, {
|
||||
name: group.name,
|
||||
actions: [
|
||||
{
|
||||
type: RuleActionType.AddLabel,
|
||||
params: [label.id],
|
||||
},
|
||||
{
|
||||
type: RuleActionType.SendNotification,
|
||||
params: [group.name],
|
||||
},
|
||||
],
|
||||
filter: `recommendedBy:${group.name}`,
|
||||
})
|
||||
await createLabelAndRuleForGroup(user.id, group.name)
|
||||
|
||||
return {
|
||||
group,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ import { RecommendationGroup, User as GraphqlUser } from '../generated/graphql'
|
|||
import { getRepository } from '../entity/utils'
|
||||
import { homePageURL } from '../env'
|
||||
import { userDataToUser } from '../utils/helpers'
|
||||
import { createLabel } from './labels'
|
||||
import { createRule } from './rules'
|
||||
import { RuleActionType } from '../entity/rule'
|
||||
|
||||
export const createGroup = async (input: {
|
||||
admin: User
|
||||
|
|
@ -200,3 +203,27 @@ export const leaveGroup = async (
|
|||
return true
|
||||
})
|
||||
}
|
||||
|
||||
export const createLabelAndRuleForGroup = async (
|
||||
userId: string,
|
||||
groupName: string
|
||||
) => {
|
||||
// create a new label for the group
|
||||
const label = await createLabel(userId, { name: groupName })
|
||||
|
||||
// create a rule to add the label to all pages in the group
|
||||
await createRule(userId, {
|
||||
name: groupName,
|
||||
actions: [
|
||||
{
|
||||
type: RuleActionType.AddLabel,
|
||||
params: [label.id],
|
||||
},
|
||||
{
|
||||
type: RuleActionType.SendNotification,
|
||||
params: [groupName],
|
||||
},
|
||||
],
|
||||
filter: `recommendedBy:"${groupName}"`,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ export const getLabelsByIds = async (
|
|||
}
|
||||
|
||||
export const createLabel = async (
|
||||
user: User,
|
||||
userId: string,
|
||||
label: {
|
||||
name: string
|
||||
color?: string
|
||||
|
|
@ -86,7 +86,7 @@ export const createLabel = async (
|
|||
}
|
||||
): Promise<Label> => {
|
||||
const existingLabel = await getRepository(Label).findOneBy({
|
||||
user: { id: user.id },
|
||||
user: { id: userId },
|
||||
name: ILike(label.name),
|
||||
})
|
||||
|
||||
|
|
@ -100,6 +100,6 @@ export const createLabel = async (
|
|||
|
||||
return getRepository(Label).save({
|
||||
...label,
|
||||
user: { id: user.id },
|
||||
user: { id: userId },
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import { User } from '../entity/user'
|
||||
import { Rule, RuleAction } from '../entity/rule'
|
||||
import { getRepository } from '../entity/utils'
|
||||
import { ILike } from 'typeorm'
|
||||
|
||||
export const createRule = async (
|
||||
user: User,
|
||||
userId: string,
|
||||
rule: {
|
||||
name: string
|
||||
description?: string
|
||||
|
|
@ -13,7 +12,7 @@ export const createRule = async (
|
|||
}
|
||||
): Promise<Rule> => {
|
||||
const existingRule = await getRepository(Rule).findOneBy({
|
||||
user: { id: user.id },
|
||||
user: { id: userId },
|
||||
name: ILike(rule.name),
|
||||
})
|
||||
|
||||
|
|
@ -23,6 +22,6 @@ export const createRule = async (
|
|||
|
||||
return getRepository(Rule).save({
|
||||
...rule,
|
||||
user: { id: user.id },
|
||||
user: { id: userId },
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue