All checks were successful
Publish Docker Image / Publish Docker Image (push) Successful in 39s
58 lines
1.4 KiB
TypeScript
Executable File
58 lines
1.4 KiB
TypeScript
Executable File
import type {
|
|
QueryResolvers,
|
|
MutationResolvers,
|
|
ProjectRelationResolvers,
|
|
} from 'types/graphql'
|
|
|
|
import { db } from 'src/lib/db'
|
|
|
|
export const projects: QueryResolvers['projects'] = () => db.project.findMany()
|
|
|
|
export const project: QueryResolvers['project'] = ({ id }) =>
|
|
db.project.findUnique({
|
|
where: { id },
|
|
})
|
|
|
|
export const createProject: MutationResolvers['createProject'] = ({ input }) =>
|
|
db.project.create({
|
|
data: {
|
|
title: input.title,
|
|
description: input.description,
|
|
date: input.date,
|
|
links: input.links,
|
|
images: input.images,
|
|
tags: {
|
|
connect: input.tags.map((tagId) => ({ id: tagId })),
|
|
},
|
|
},
|
|
})
|
|
|
|
export const updateProject: MutationResolvers['updateProject'] = async ({
|
|
id,
|
|
input,
|
|
}) =>
|
|
db.project.update({
|
|
data: {
|
|
title: input.title,
|
|
description: input.description,
|
|
date: input.date,
|
|
links: input.links,
|
|
images: input.images,
|
|
tags: {
|
|
disconnect: input.removeTags?.map((tagId) => ({ id: tagId })),
|
|
connect: input.tags?.map((tagId) => ({ id: tagId })),
|
|
},
|
|
},
|
|
where: { id },
|
|
})
|
|
|
|
export const deleteProject: MutationResolvers['deleteProject'] = ({ id }) =>
|
|
db.project.delete({
|
|
where: { id },
|
|
})
|
|
|
|
export const Project: ProjectRelationResolvers = {
|
|
tags: (_obj, { root }) =>
|
|
db.project.findUnique({ where: { id: root?.id } }).tags(),
|
|
}
|