Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add edit dialog for forum in AdminCP #228

Merged
merged 17 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
467a829
feat(admin): Add edit button with form for forum
aXenDeveloper Feb 24, 2024
df09b13
refactor(frontend): Improve drag and drop hook
aXenDeveloper Feb 24, 2024
53e90e7
chore: Change buildTree to generic
aXenDeveloper Feb 24, 2024
2313255
fix(frontend): Multiple re-render item when user move item in child a…
aXenDeveloper Feb 24, 2024
639d592
fix(frontend): Drop item to the parent from child in drag and drop
aXenDeveloper Feb 24, 2024
ad0b8ba
fix(frontend): indexToMove for drag and drop
aXenDeveloper Feb 24, 2024
a9fcf04
feat(frontend): Add DragOverlay for forums in AdminCP
aXenDeveloper Feb 24, 2024
99f028e
perf(frontend): Remove react query for forums AdminCP
aXenDeveloper Feb 24, 2024
6e4d4bc
fix(frontend): Drop item to children with invalid index for forums in…
aXenDeveloper Feb 25, 2024
ae497a8
perf(frontend): Add update mutation for forums in AdminCP
aXenDeveloper Feb 25, 2024
1d26325
feat(frontend): Add build tree for display forums after fetched in Ad…
aXenDeveloper Feb 25, 2024
d4bc46a
Merge pull request #229 from aXenDeveloper/refactor/drag_and_drop_table
aXenDeveloper Feb 25, 2024
4ca7d68
perf(forum): Remove _count form show query
aXenDeveloper Feb 26, 2024
59d90a2
feat(forum): Add permissions to query for show forums in AdminCP
aXenDeveloper Feb 26, 2024
d432b47
feat(forum): Connect item data to edit dialog for forums in AdminCP
aXenDeveloper Feb 26, 2024
10e334e
feat(forum): Add edit mutation for forums in AdminCP
aXenDeveloper Feb 26, 2024
a6b8a01
feat(forum): Connect edit forum dialog to API in AdminCP
aXenDeveloper Feb 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion backend/src/admin/forum/forum.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { ChangePositionForumForumsResolver } from "./forums/change_position/chan
import { ChangePositionForumForumsService } from "./forums/change_position/change_position.service";
import { ShowForumForumsAdminResolver } from "./forums/show/show.resolver";
import { ShowForumForumsAdminService } from "./forums/show/show.service";
import { EditForumForumsResolver } from "./forums/edit/edit.resolver";
import { EditForumForumsService } from "./forums/edit/edit.service";

@Module({
providers: [
Expand All @@ -14,7 +16,9 @@ import { ShowForumForumsAdminService } from "./forums/show/show.service";
ChangePositionForumForumsResolver,
ChangePositionForumForumsService,
ShowForumForumsAdminResolver,
ShowForumForumsAdminService
ShowForumForumsAdminService,
EditForumForumsResolver,
EditForumForumsService
]
})
export class AdminForumModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class ChangePositionForumForumsService {
const allChildrenParent =
await this.databaseService.db.query.forum_forums.findMany({
where: (table, { eq }) =>
parent_id === null
? isNull(table.parent_id)
!parent_id
? isNull(table.parent_id ?? null)
: eq(table.parent_id, parent_id),
orderBy: (table, { asc }) => asc(table.position)
});
Expand Down
32 changes: 9 additions & 23 deletions backend/src/admin/forum/forums/create/create.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Injectable } from "@nestjs/common";
import { count, eq } from "drizzle-orm";

import { CreateForumForumsArgs } from "./dto/create.args";
import { CreateForumForumsObj } from "./dto/create.obj";
Expand Down Expand Up @@ -85,10 +84,7 @@ export class CreateForumForumsService {
permissions.groups.map(item => ({
forum_id: data[0].id,
group_id: item.id,
can_create: item.create,
can_read: item.read,
can_reply: item.reply,
can_view: item.view
...item
}))
);
}
Expand All @@ -98,33 +94,23 @@ export class CreateForumForumsService {
with: {
name: true,
description: true,
permissions: true
permissions: true,
parent: {
with: {
name: true,
description: true
}
}
}
});

if (!forum) {
throw new NotFoundError("Forum");
}

const parent = await this.databaseService.db.query.forum_forums.findFirst({
where: (table, { eq }) => eq(table.id, parent_id || null),
with: {
name: true,
description: true,
permissions: true
}
});

const countParentChildren = await this.databaseService.db
.select({ count: count() })
.from(forum_forums)
.where(eq(forum_forums.parent_id, parent_id || null));

return {
...forum,
children: [],
_count: { children: 0 },
parent: { ...parent, _count: { children: countParentChildren[0].count } }
children: []
};
}
}
10 changes: 5 additions & 5 deletions backend/src/admin/forum/forums/create/dto/create.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ class GroupsPermissionsCreateForumForums {
id: number;

@Field(() => Boolean)
view: boolean;
can_view: boolean;

@Field(() => Boolean)
read: boolean;
can_read: boolean;

@Field(() => Boolean)
create: boolean;
can_create: boolean;

@Field(() => Boolean)
reply: boolean;
can_reply: boolean;
}

@InputType()
class PermissionsCreateForumForums {
export class PermissionsCreateForumForums {
@Field(() => Boolean)
can_all_view: boolean;

Expand Down
9 changes: 9 additions & 0 deletions backend/src/admin/forum/forums/edit/dto/edit.args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ArgsType, Field, Int } from "@nestjs/graphql";

import { CreateForumForumsArgs } from "../../create/dto/create.args";

@ArgsType()
export class EditForumForumsArgs extends CreateForumForumsArgs {
@Field(() => Int)
id: number;
}
21 changes: 21 additions & 0 deletions backend/src/admin/forum/forums/edit/edit.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Args, Mutation, Resolver } from "@nestjs/graphql";
import { UseGuards } from "@nestjs/common";

import { EditForumForumsService } from "./edit.service";
import { CreateForumForumsObj } from "../create/dto/create.obj";
import { EditForumForumsArgs } from "./dto/edit.args";

import { AdminAuthGuards } from "@/utils/guards/admin-auth.guards";

@Resolver()
export class EditForumForumsResolver {
constructor(private readonly service: EditForumForumsService) {}

@Mutation(() => CreateForumForumsObj)
@UseGuards(AdminAuthGuards)
async admin__forum_forums__edit(
@Args() args: EditForumForumsArgs
): Promise<CreateForumForumsObj> {
return await this.service.edit(args);
}
}
Loading
Loading