Skip to content

Commit

Permalink
Add deleteDraftProject GQL mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
rmunn committed May 13, 2024
1 parent 2869a47 commit 7489e09
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions backend/LexBoxApi/GraphQL/ProjectMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,26 @@ await dbContext.ProjectUsers.Where(pu => pu.ProjectId == input.ProjectId && pu.U
return dbContext.Projects.Where(p => p.Id == input.ProjectId);
}

[Error<NotFoundException>]
[Error<DbError>]
[UseMutationConvention]
[UseFirstOrDefault]
[UseProjection]
public async Task<IQueryable<DraftProject>> DeleteDraftProject(
Guid draftProjectId,
IPermissionService permissionService,
LexBoxDbContext dbContext)
{
permissionService.AssertCanManageProject(draftProjectId);

// Draft projects are deleted immediately, not soft-deleted
var deletedDraftCount = await dbContext.DraftProjects.Where(dp => dp.Id == draftProjectId).ExecuteDeleteAsync();
if (deletedDraftCount == 0)
{
throw NotFoundException.ForType<DraftProject>();
}
return dbContext.DraftProjects.Where(p => p.Id == draftProjectId);
}

[Error<NotFoundException>]
[Error<DbError>]
Expand Down
12 changes: 12 additions & 0 deletions frontend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ type DbError implements Error {
code: DbErrorCode!
}

type DeleteDraftProjectPayload {
draftProject: DraftProject
errors: [DeleteDraftProjectError!]
}

type DeleteUserByAdminOrSelfPayload {
user: User
errors: [DeleteUserByAdminOrSelfError!]
Expand Down Expand Up @@ -176,6 +181,7 @@ type Mutation {
setProjectConfidentiality(input: SetProjectConfidentialityInput!): SetProjectConfidentialityPayload!
leaveProject(input: LeaveProjectInput!): LeaveProjectPayload!
removeProjectMember(input: RemoveProjectMemberInput!): RemoveProjectMemberPayload!
deleteDraftProject(input: DeleteDraftProjectInput!): DeleteDraftProjectPayload!
softDeleteProject(input: SoftDeleteProjectInput!): SoftDeleteProjectPayload!
changeUserAccountBySelf(input: ChangeUserAccountBySelfInput!): ChangeUserAccountBySelfPayload!
changeUserAccountByAdmin(input: ChangeUserAccountByAdminInput!): ChangeUserAccountByAdminPayload! @authorize(policy: "AdminRequiredPolicy")
Expand Down Expand Up @@ -360,6 +366,8 @@ union CreateOrganizationError = DbError

union CreateProjectError = DbError | AlreadyExistsError | ProjectCreatorsMustHaveEmail

union DeleteDraftProjectError = NotFoundError | DbError

union DeleteUserByAdminOrSelfError = NotFoundError | DbError

union LeaveProjectError = NotFoundError | LastMemberCantLeaveError
Expand Down Expand Up @@ -450,6 +458,10 @@ input DateTimeOperationFilterInput {
nlte: DateTime
}

input DeleteDraftProjectInput {
draftProjectId: UUID!
}

input DeleteUserByAdminOrSelfInput {
userId: UUID!
}
Expand Down

0 comments on commit 7489e09

Please sign in to comment.