From dc8bf19b95b82818dbd5c415c9ae81273e6466ea Mon Sep 17 00:00:00 2001 From: Jiri Spac Date: Sun, 1 Sep 2024 01:41:52 +0200 Subject: [PATCH] define new model WebInputMutation --- backend/gqlSchemas/authier.graphql | 18 ++++++++++++++++-- backend/models/WebInput.ts | 19 +++++++++++++++++++ backend/models/generated/WebInputGQL.ts | 15 +-------------- backend/prisma/generated/types.ts | 4 ++-- backend/schemas/RootResolver.ts | 3 ++- 5 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 backend/models/WebInput.ts diff --git a/backend/gqlSchemas/authier.graphql b/backend/gqlSchemas/authier.graphql index 0afba41a..c631b707 100755 --- a/backend/gqlSchemas/authier.graphql +++ b/backend/gqlSchemas/authier.graphql @@ -191,7 +191,6 @@ type WebInputGQL { addedByUserId: String addedByUser: UserGQL UsageEvents: [SecretUsageEventGQL!]! - delete: Int! } enum WebInputType { @@ -401,7 +400,7 @@ type Mutation { """ logout(removeDevice: Boolean): Int @deprecated(reason: "prefer device methods") - webInput(id: Int!): WebInputGQL + webInput(id: Int!): WebInputMutation addWebInputs(webInputs: [WebInputElement!]!): [WebInputGQL!]! } @@ -691,6 +690,21 @@ input AddNewDeviceInput { devicePlatform: String! } +type WebInputMutation { + id: Int! + layoutType: String + createdAt: DateTime! + host: String! + url: String! + kind: WebInputType! + domPath: String! + domOrdinal: Int! + addedByUserId: String + addedByUser: UserGQL + UsageEvents: [SecretUsageEventGQL!]! + delete: Int! +} + input WebInputElement { domPath: String! diff --git a/backend/models/WebInput.ts b/backend/models/WebInput.ts new file mode 100644 index 00000000..6cca4e97 --- /dev/null +++ b/backend/models/WebInput.ts @@ -0,0 +1,19 @@ +import { Field, ObjectType, Int, GraphQLISODateTime, Ctx } from 'type-graphql' +import { WebInputGQL } from './generated/WebInputGQL' +import debug from 'debug' +import { IContextAuthenticated } from '../schemas/RootResolver' + +const log = debug('au:WebInput') + +@ObjectType() +export class WebInputMutation extends WebInputGQL { + @Field(() => Int) + async delete(@Ctx() ctx: IContextAuthenticated) { + log('delete of WebInput id: ', this.id) + // TODO rate limit this to like 1 per hour + + return ctx.prisma.webInput.delete({ + where: { id: this.id } + }) + } +} diff --git a/backend/models/generated/WebInputGQL.ts b/backend/models/generated/WebInputGQL.ts index 5d29993d..5d3157e9 100644 --- a/backend/models/generated/WebInputGQL.ts +++ b/backend/models/generated/WebInputGQL.ts @@ -1,11 +1,8 @@ -import { Field, ObjectType, Int, GraphQLISODateTime, Ctx } from 'type-graphql' +import { Field, ObjectType, Int, GraphQLISODateTime } from 'type-graphql' import { WebInputTypeGQL } from '../types/WebInputType' import { UserGQL } from './UserGQL' import { SecretUsageEventGQL } from './SecretUsageEventGQL' -import type { IContextAuthenticated } from 'schemas/RootResolver' -import debug from 'debug' -const log = debug('au:WebInput') @ObjectType() export class WebInputGQLScalars { @Field(() => Int) @@ -45,14 +42,4 @@ export class WebInputGQL extends WebInputGQLScalars { UsageEvents: SecretUsageEventGQL[] // skip overwrite 👇 - - @Field(() => Int) - async delete(@Ctx() ctx: IContextAuthenticated) { - log('delete of WebInput id: ', this.id) - // TODO rate limit this to like 1 per hour - - return ctx.prisma.webInput.delete({ - where: { id: this.id } - }) - } } diff --git a/backend/prisma/generated/types.ts b/backend/prisma/generated/types.ts index 89fa1700..c1905c48 100644 --- a/backend/prisma/generated/types.ts +++ b/backend/prisma/generated/types.ts @@ -91,7 +91,7 @@ export type EmailVerification = { kind: EmailVerificationType } export type EncryptedSecret = { - id: string + id: Generated encrypted: string version: number kind: EncryptedSecretType @@ -136,7 +136,7 @@ export type Token = { userId: string } export type User = { - id: string + id: Generated email: string | null tokenVersion: Generated username: string | null diff --git a/backend/schemas/RootResolver.ts b/backend/schemas/RootResolver.ts index 9538f211..0400487e 100755 --- a/backend/schemas/RootResolver.ts +++ b/backend/schemas/RootResolver.ts @@ -45,6 +45,7 @@ import { import { plainToClass } from 'class-transformer' import { firebaseAdmin } from '../lib/firebaseAdmin' +import { WebInputMutation } from '../models/WebInput' const log = debug('au:RootResolver') @@ -469,7 +470,7 @@ export class RootResolver { } @UseMiddleware(throwIfNotAuthenticated) - @Mutation(() => WebInputGQL, { + @Mutation(() => WebInputMutation, { nullable: true }) @Query(() => WebInputGQL, {