diff --git a/packages/api/src/generated/graphql.ts b/packages/api/src/generated/graphql.ts index 64cf263eb..663313b57 100644 --- a/packages/api/src/generated/graphql.ts +++ b/packages/api/src/generated/graphql.ts @@ -1651,6 +1651,7 @@ export type Rule = { __typename?: 'Rule'; actions: Array; createdAt: Scalars['Date']; + enabled: Scalars['Boolean']; id: Scalars['ID']; name?: Maybe; query: Scalars['String']; @@ -1970,6 +1971,7 @@ export enum SetRuleErrorCode { export type SetRuleInput = { actions: Array; + enabled: Scalars['Boolean']; id?: InputMaybe; name?: InputMaybe; query: Scalars['String']; @@ -4402,6 +4404,7 @@ export type RevokeApiKeySuccessResolvers = { actions?: Resolver, ParentType, ContextType>; createdAt?: Resolver; + enabled?: Resolver; id?: Resolver; name?: Resolver, ParentType, ContextType>; query?: Resolver; diff --git a/packages/api/src/generated/schema.graphql b/packages/api/src/generated/schema.graphql index b9d2b685b..a802be59d 100644 --- a/packages/api/src/generated/schema.graphql +++ b/packages/api/src/generated/schema.graphql @@ -1159,6 +1159,7 @@ type RevokeApiKeySuccess { type Rule { actions: [RuleAction!]! createdAt: Date! + enabled: Boolean! id: ID! name: String query: String! @@ -1454,6 +1455,7 @@ enum SetRuleErrorCode { input SetRuleInput { actions: [RuleActionInput!]! + enabled: Boolean! id: ID name: String query: String! diff --git a/packages/api/src/resolvers/rules/index.ts b/packages/api/src/resolvers/rules/index.ts new file mode 100644 index 000000000..9d4e9a0aa --- /dev/null +++ b/packages/api/src/resolvers/rules/index.ts @@ -0,0 +1,25 @@ +import { authorized } from '../../utils/helpers' +import { + MutationSetRuleArgs, + SetRuleError, + SetRuleSuccess, +} from '../../generated/graphql' + +export const setRulesResolver = authorized< + SetRuleSuccess, + SetRuleError, + MutationSetRuleArgs +>(async (_, { input }, { claims, log }) => { + log.info('Setting rules', { + input, + labels: { + source: 'resolver', + resolver: 'setRulesResolver', + uid: claims.uid, + }, + }) + + return { + rules, + } +}) diff --git a/packages/api/src/schema.ts b/packages/api/src/schema.ts index ba6906250..007ed31b1 100755 --- a/packages/api/src/schema.ts +++ b/packages/api/src/schema.ts @@ -1961,6 +1961,7 @@ const schema = gql` name: String query: String! actions: [RuleAction!]! + enabled: Boolean! createdAt: Date! updatedAt: Date! } @@ -1991,6 +1992,7 @@ const schema = gql` name: String query: String! actions: [RuleActionInput!]! + enabled: Boolean! } input RuleActionInput { diff --git a/packages/db/migrations/0099.do.rules.sql b/packages/db/migrations/0099.do.rules.sql new file mode 100755 index 000000000..659d94980 --- /dev/null +++ b/packages/db/migrations/0099.do.rules.sql @@ -0,0 +1,19 @@ +-- Type: DO +-- Name: rules +-- Description: Create rules table which contains user defines rules and actions + +BEGIN; + +CREATE TABLE omnivore.rules ( + id uuid PRIMARY KEY DEFAULT uuid_generate_v1mc(), + user_id uuid NOT NULL REFERENCES omnivore.user ON DELETE CASCADE, + name text NOT NULL, + description text, + query text NOT NULL, + actions text NOT NULL, + enabled boolean NOT NULL DEFAULT true, + created_at timestamptz NOT NULL DEFAULT current_timestamp, + updated_at timestamptz NOT NULL DEFAULT current_timestamp, +); + +COMMIT; diff --git a/packages/db/migrations/0099.undo.rules.sql b/packages/db/migrations/0099.undo.rules.sql new file mode 100755 index 000000000..bc2c32f13 --- /dev/null +++ b/packages/db/migrations/0099.undo.rules.sql @@ -0,0 +1,9 @@ +-- Type: UNDO +-- Name: rules +-- Description: Create rules table which contains user defines rules and actions + +BEGIN; + +DROP TABLE IF EXISTS omnivore.rules; + +COMMIT;