Delete project properly as it's not causing problems with forking logic (#539)
This commit was merged in pull request #539.
This commit is contained in:
@@ -129,7 +129,6 @@ export const updateProject = async ({ id, input }: UpdateProjectArgs) => {
|
|||||||
}
|
}
|
||||||
requireAuth()
|
requireAuth()
|
||||||
const originalProject = await requireProjectOwnership({ projectId: id })
|
const originalProject = await requireProjectOwnership({ projectId: id })
|
||||||
console.log('yooooo', originalProject)
|
|
||||||
if (input.title) {
|
if (input.title) {
|
||||||
input.title = enforceAlphaNumeric(input.title)
|
input.title = enforceAlphaNumeric(input.title)
|
||||||
}
|
}
|
||||||
@@ -257,12 +256,19 @@ export const updateProjectImages = async ({
|
|||||||
export const deleteProject = async ({ id }: Prisma.ProjectWhereUniqueInput) => {
|
export const deleteProject = async ({ id }: Prisma.ProjectWhereUniqueInput) => {
|
||||||
requireAuth()
|
requireAuth()
|
||||||
await requireOwnership({ projectId: id })
|
await requireOwnership({ projectId: id })
|
||||||
return db.project.update({
|
const project = await db.project.findUnique({
|
||||||
data: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
where: { id },
|
where: { id },
|
||||||
})
|
})
|
||||||
|
const childrenDeletePromises = [
|
||||||
|
db.comment.deleteMany({ where: { projectId: project.id } }),
|
||||||
|
db.projectReaction.deleteMany({ where: { projectId: project.id } }),
|
||||||
|
db.socialCard.deleteMany({ where: { projectId: project.id } }),
|
||||||
|
]
|
||||||
|
await Promise.all(childrenDeletePromises)
|
||||||
|
await db.project.delete({
|
||||||
|
where: { id },
|
||||||
|
})
|
||||||
|
return project
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Project = {
|
export const Project = {
|
||||||
@@ -272,7 +278,7 @@ export const Project = {
|
|||||||
childForks: (_obj, { root }) =>
|
childForks: (_obj, { root }) =>
|
||||||
db.project.findMany({ where: { forkedFromId: root.id } }),
|
db.project.findMany({ where: { forkedFromId: root.id } }),
|
||||||
user: (_obj, { root }: ResolverArgs<ReturnType<typeof project>>) =>
|
user: (_obj, { root }: ResolverArgs<ReturnType<typeof project>>) =>
|
||||||
db.project.findUnique({ where: { id: root.id } }).user(),
|
db.user.findUnique({ where: { id: root.userId } }),
|
||||||
socialCard: (_obj, { root }: ResolverArgs<ReturnType<typeof project>>) =>
|
socialCard: (_obj, { root }: ResolverArgs<ReturnType<typeof project>>) =>
|
||||||
db.project.findUnique({ where: { id: root.id } }).socialCard(),
|
db.project.findUnique({ where: { id: root.id } }).socialCard(),
|
||||||
Comment: (_obj, { root }: ResolverArgs<ReturnType<typeof project>>) =>
|
Comment: (_obj, { root }: ResolverArgs<ReturnType<typeof project>>) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user