From 5ef4e8479deb6adef4255e17ca15717d9221dd8b Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Tue, 13 Dec 2022 16:35:39 +0800 Subject: [PATCH] Create one rule for all pages in the group to have the label and another rule for the recommended page to send a notification --- packages/api/src/services/groups.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/api/src/services/groups.ts b/packages/api/src/services/groups.ts index 73454c0a5..3725b3215 100644 --- a/packages/api/src/services/groups.ts +++ b/packages/api/src/services/groups.ts @@ -235,13 +235,22 @@ export const createLabelAndRuleForGroup = async ( 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, + const addLabelPromise = createRule(userId, { + name: `Add label ${groupName} to all pages in group ${groupName}`, actions: [ { type: RuleActionType.AddLabel, params: [label.id], }, + ], + // always add the label to pages in the group + filter: `recommendedBy:"${groupName}"`, + }) + + // create a rule to send a notification when a page is recommended + const sendNotificationPromise = createRule(userId, { + name: `Send notification when a page is recommended to ${groupName}`, + actions: [ { type: RuleActionType.SendNotification, params: [ @@ -257,4 +266,6 @@ export const createLabelAndRuleForGroup = async ( // add a condition to check if the page is created filter: `event:created recommendedBy:"${groupName}"`, }) + + await Promise.all([addLabelPromise, sendNotificationPromise]) }