Skip to content

Commit

Permalink
Merge pull request #228 from aXenDeveloper/forum/edit
Browse files Browse the repository at this point in the history
feat: Add edit dialog for forum in AdminCP
  • Loading branch information
aXenDeveloper authored Feb 26, 2024
2 parents 6c89a16 + a6b8a01 commit d1754bc
Show file tree
Hide file tree
Showing 45 changed files with 1,286 additions and 818 deletions.
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

0 comments on commit d1754bc

Please sign in to comment.