-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backend] finish creating decayRule module
- Loading branch information
1 parent
85f3454
commit 573f727
Showing
16 changed files
with
311 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 146 additions & 15 deletions
161
opencti-platform/opencti-graphql/src/generated/graphql.ts
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { AuthContext, AuthUser } from '../../types/user'; | ||
import { listEntitiesPaginated, storeLoadById } from '../../database/middleware-loader'; | ||
import type { EditInput, QueryDecayRulesArgs, DecayRuleAddInput } from '../../generated/graphql'; | ||
import { type BasicStoreEntityDecayRule, ENTITY_TYPE_DECAY_RULE, type StoreEntityDecayRule } from './decayRule-types'; | ||
import { createInternalObject, deleteInternalObject, editInternalObject } from '../../domain/internalObject'; | ||
|
||
export const findById = (context: AuthContext, user: AuthUser, id: string) => { | ||
return storeLoadById<BasicStoreEntityDecayRule>(context, user, id, ENTITY_TYPE_DECAY_RULE); | ||
}; | ||
|
||
export const findAll = (context: AuthContext, user: AuthUser, args: QueryDecayRulesArgs) => { | ||
return listEntitiesPaginated<BasicStoreEntityDecayRule>(context, user, [ENTITY_TYPE_DECAY_RULE], args); | ||
}; | ||
|
||
export const addDecayRule = async (context: AuthContext, user: AuthUser, input: DecayRuleAddInput) => { | ||
return createInternalObject<StoreEntityDecayRule>(context, user, input, ENTITY_TYPE_DECAY_RULE); | ||
}; | ||
|
||
export const fieldPatchDecayRule = async (context: AuthContext, user: AuthUser, id: string, input: EditInput[]) => { | ||
return editInternalObject<StoreEntityDecayRule>(context, user, id, ENTITY_TYPE_DECAY_RULE, input); | ||
}; | ||
|
||
export const deleteDecayRule = async (context: AuthContext, user: AuthUser, id: string) => { | ||
return deleteInternalObject(context, user, id, ENTITY_TYPE_DECAY_RULE); | ||
}; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { registerGraphqlSchema } from '../../graphql/schema'; | ||
import decayRuleTypeDefs from './decayRule.graphql'; | ||
import decayRuleResolvers from './decayRule-resolver'; | ||
|
||
registerGraphqlSchema({ | ||
schema: decayRuleTypeDefs, | ||
resolver: decayRuleResolvers, | ||
}); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { Resolvers } from '../../generated/graphql'; | ||
import { addDecayRule, deleteDecayRule, fieldPatchDecayRule, findAll, findById } from './decayRule-domain'; | ||
|
||
const decayRuleResolvers: Resolvers = { | ||
Query: { | ||
decayRule: (_, { id }, context) => findById(context, context.user, id), | ||
decayRules: (_, args, context) => findAll(context, context.user, args), | ||
}, | ||
Mutation: { | ||
decayRuleAdd: (_, { input }, context) => { | ||
return addDecayRule(context, context.user, input); | ||
}, | ||
decayRuleDelete: (_, { id }, context) => { | ||
return deleteDecayRule(context, context.user, id); | ||
}, | ||
decayRuleFieldPatch: (_, { id, input }, context) => { | ||
return fieldPatchDecayRule(context, context.user, id, input); | ||
}, | ||
} | ||
}; | ||
|
||
export default decayRuleResolvers; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
type DecayRule implements InternalObject & BasicObject { | ||
id: ID! | ||
standard_id: String! | ||
entity_type: String! | ||
parent_types: [String]! | ||
created_at: DateTime! | ||
updated_at: DateTime! | ||
# DecayRule | ||
name: String! | ||
description: String | ||
order: Int! | ||
active: Boolean! | ||
activated_at: DateTime | ||
built_in: Boolean | ||
# Decay rule settings | ||
decay_lifetime: Int! | ||
decay_pound: Float! | ||
decay_points: [Int!] | ||
decay_revoke_score: Int! | ||
decay_observable_types: [String!] | ||
} | ||
|
||
# Ordering | ||
enum DecayRuleOrdering { | ||
name | ||
order | ||
} | ||
|
||
# Relay connections | ||
type DecayRuleConnection { | ||
pageInfo: PageInfo! | ||
edges: [DecayRuleEdge!]! | ||
} | ||
type DecayRuleEdge { | ||
cursor: String! | ||
node: DecayRule! | ||
} | ||
|
||
# Queries | ||
type Query { | ||
decayRule(id: String!): DecayRule @auth(for: [SETTINGS]) | ||
decayRules( | ||
first: Int | ||
after: ID | ||
orderBy: DecayRuleOrdering | ||
orderMode: OrderingMode | ||
filters: FilterGroup | ||
search: String | ||
): DecayRuleConnection @auth(for: [SETTINGS]) | ||
} | ||
|
||
input DecayRuleAddInput { | ||
name: String! @constraint(minLength: 2) | ||
description: String | ||
order: Int! | ||
active: Boolean! | ||
# Decay rule settings | ||
decay_lifetime: Int! | ||
decay_pound: Float! | ||
decay_points: [Int!] | ||
decay_revoke_score: Int! | ||
decay_observable_types: [String!] | ||
} | ||
|
||
type Mutation { | ||
decayRuleAdd(input: DecayRuleAddInput!): DecayRule @auth(for: [SETTINGS]) | ||
decayRuleDelete(id: ID!): ID @auth(for: [SETTINGS]) | ||
decayRuleFieldPatch(id: ID!, input: [EditInput!]!): DecayRule @auth(for: [SETTINGS]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters