Contact Page

This commit is contained in:
Ahmed Al-Taiar
2024-08-21 01:24:24 -04:00
parent c7d87e36f2
commit 593567a197
25 changed files with 848 additions and 42 deletions

View File

@ -0,0 +1,7 @@
-- CreateTable
CREATE TABLE "Portrait" (
"id" SERIAL NOT NULL,
"fileId" TEXT NOT NULL,
CONSTRAINT "Portrait_pkey" PRIMARY KEY ("id")
);

View File

@ -43,3 +43,8 @@ model Social {
type Handle
username String
}
model Portrait {
id Int @id @default(autoincrement())
fileId String
}

View File

@ -0,0 +1,19 @@
export const schema = gql`
type Portrait {
id: Int!
fileId: String!
}
type Query {
portrait: Portrait @skipAuth
}
input CreatePortraitInput {
fileId: String!
}
type Mutation {
createPortrait(input: CreatePortraitInput!): Portrait! @requireAuth
deletePortrait: Portrait! @requireAuth
}
`

View File

@ -20,8 +20,8 @@ export const schema = gql`
}
type Query {
socials: [Social!]! @requireAuth
social(id: Int!): Social @requireAuth
socials: [Social!]! @skipAuth
social(id: Int!): Social @skipAuth
}
input CreateSocialInput {

View File

@ -39,7 +39,10 @@ export const handleTusUpload = (
res.raw.statusCode = 405
res.raw.end('Method not allowed')
}
} else tusHandler.handle(req.raw, res.raw)
} else {
setCorsHeaders(res)
tusHandler.handle(req.raw, res.raw)
}
}
const handleAuthenticatedRequest = async (

View File

@ -0,0 +1,37 @@
import type { QueryResolvers, MutationResolvers } from 'types/graphql'
import { ValidationError } from '@redwoodjs/graphql-server'
import { db } from 'src/lib/db'
export const portrait: QueryResolvers['portrait'] = async () => {
const portrait = await db.portrait.findFirst()
if (portrait) return portrait
else
return {
id: -1,
fileId: '/no_portrait.webp',
}
}
export const createPortrait: MutationResolvers['createPortrait'] = async ({
input,
}) => {
if (await db.portrait.findFirst())
throw new ValidationError('Portrait already exists')
else
return db.portrait.create({
data: input,
})
}
export const deletePortrait: MutationResolvers['deletePortrait'] = async () => {
const portrait = await db.portrait.findFirst()
if (!portrait) throw new ValidationError('Portrait does not exist')
else
return db.portrait.delete({
where: { id: portrait.id },
})
}