|
| 1 | +import { BaseEntity } from '@app/common/base/base-entity' |
| 2 | +import { EntityRef } from '@app/common/decorators/entity-ref.decorator' |
| 3 | +import { OwnedEntity } from '@app/common/decorators/owned-entity.decorator' |
| 4 | +import { jsonProp } from '@app/common/decorators/props/json-prop.decorator' |
| 5 | +import { Reference } from '@app/common/typings/mongodb' |
| 6 | +import { FilterableField } from '@nestjs-query/query-graphql' |
| 7 | +import { Field, ID, InputType, ObjectType } from '@nestjs/graphql' |
| 8 | +import { prop, Ref } from '@typegoose/typegoose' |
| 9 | +import { GraphQLJSONObject } from 'graphql-type-json' |
| 10 | +import { JSONSchema7 } from 'json-schema' |
| 11 | +import { IntegrationAccount } from '../../integration-accounts/entities/integration-account' |
| 12 | +import { User } from '../../users/entities/user' |
| 13 | + |
| 14 | +@ObjectType() |
| 15 | +@OwnedEntity() |
| 16 | +@EntityRef('owner', () => User) |
| 17 | +@EntityRef('integrationAccount', () => IntegrationAccount) |
| 18 | +export class AccountCredential extends BaseEntity { |
| 19 | + @FilterableField(() => ID) |
| 20 | + @prop({ ref: User, required: true, index: true }) |
| 21 | + readonly owner!: Reference<User> |
| 22 | + |
| 23 | + @FilterableField(() => ID) |
| 24 | + @prop({ ref: IntegrationAccount, required: true, index: true }) |
| 25 | + readonly integrationAccount!: Reference<IntegrationAccount> |
| 26 | + |
| 27 | + @Field() |
| 28 | + @prop({ required: true }) |
| 29 | + name: string |
| 30 | + |
| 31 | + // Placeholder for credential pairs input |
| 32 | + credentials: Record<string, string> |
| 33 | + |
| 34 | + @prop() |
| 35 | + encryptedCredentials: string |
| 36 | + |
| 37 | + @Field(() => GraphQLJSONObject, { nullable: true }) |
| 38 | + @jsonProp() |
| 39 | + fields: Record<string, string> |
| 40 | + |
| 41 | + /** |
| 42 | + * Stores references for operations with dynamic schemas. |
| 43 | + */ |
| 44 | + @Field(() => GraphQLJSONObject, { nullable: true }) |
| 45 | + @jsonProp() |
| 46 | + schemaRefs?: Record<string, JSONSchema7> |
| 47 | +} |
| 48 | + |
| 49 | +@InputType() |
| 50 | +export class CreateAccountCredentialInput { |
| 51 | + @Field(() => ID) |
| 52 | + integrationAccount: Ref<IntegrationAccount> |
| 53 | + |
| 54 | + @Field() |
| 55 | + name: string |
| 56 | + |
| 57 | + @Field(() => GraphQLJSONObject, { nullable: true }) |
| 58 | + credentials: Record<string, string> |
| 59 | + |
| 60 | + @Field(() => GraphQLJSONObject, { nullable: true }) |
| 61 | + fields: Record<string, string> |
| 62 | +} |
| 63 | + |
| 64 | +@InputType() |
| 65 | +export class UpdateAccountCredentialInput { |
| 66 | + @Field({ nullable: true }) |
| 67 | + name: string |
| 68 | + |
| 69 | + @Field(() => GraphQLJSONObject, { nullable: true }) |
| 70 | + credentials: Record<string, string> |
| 71 | + |
| 72 | + @Field(() => GraphQLJSONObject, { nullable: true }) |
| 73 | + fields: Record<string, string> |
| 74 | +} |
0 commit comments