Skip to content

Commit

Permalink
define new model WebInputMutation
Browse files Browse the repository at this point in the history
  • Loading branch information
capaj committed Aug 31, 2024
1 parent d2c6f18 commit dc8bf19
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
18 changes: 16 additions & 2 deletions backend/gqlSchemas/authier.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ type WebInputGQL {
addedByUserId: String
addedByUser: UserGQL
UsageEvents: [SecretUsageEventGQL!]!
delete: Int!
}

enum WebInputType {
Expand Down Expand Up @@ -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!]!
}

Expand Down Expand Up @@ -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!

Expand Down
19 changes: 19 additions & 0 deletions backend/models/WebInput.ts
Original file line number Diff line number Diff line change
@@ -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 }
})
}
}
15 changes: 1 addition & 14 deletions backend/models/generated/WebInputGQL.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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 }
})
}
}
4 changes: 2 additions & 2 deletions backend/prisma/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export type EmailVerification = {
kind: EmailVerificationType
}
export type EncryptedSecret = {
id: string
id: Generated<string>
encrypted: string
version: number
kind: EncryptedSecretType
Expand Down Expand Up @@ -136,7 +136,7 @@ export type Token = {
userId: string
}
export type User = {
id: string
id: Generated<string>
email: string | null
tokenVersion: Generated<number>
username: string | null
Expand Down
3 changes: 2 additions & 1 deletion backend/schemas/RootResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -469,7 +470,7 @@ export class RootResolver {
}

@UseMiddleware(throwIfNotAuthenticated)
@Mutation(() => WebInputGQL, {
@Mutation(() => WebInputMutation, {
nullable: true
})
@Query(() => WebInputGQL, {
Expand Down

0 comments on commit dc8bf19

Please sign in to comment.