43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import type { QueryResolvers, MutationResolvers } from 'types/graphql'
|
|
|
|
import { isProduction } from '@redwoodjs/api/logger'
|
|
import { ValidationError } from '@redwoodjs/graphql-server'
|
|
|
|
import { db } from 'src/lib/db'
|
|
|
|
const address = isProduction
|
|
? process.env.ADDRESS_PROD
|
|
: process.env.ADDRESS_DEV
|
|
|
|
export const portrait: QueryResolvers['portrait'] = async () => {
|
|
const portrait = await db.portrait.findFirst()
|
|
|
|
if (portrait) return portrait
|
|
else
|
|
return {
|
|
id: -1,
|
|
fileId: `${address}/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 },
|
|
})
|
|
}
|