Contact Page
This commit is contained in:
19
api/src/graphql/portraits.sdl.ts
Normal file
19
api/src/graphql/portraits.sdl.ts
Normal 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
|
||||
}
|
||||
`
|
@ -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 {
|
||||
|
@ -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 (
|
||||
|
37
api/src/services/portraits/portraits.ts
Normal file
37
api/src/services/portraits/portraits.ts
Normal 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 },
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user