-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2935305
commit f7ad02c
Showing
6 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
backend/src/plugins/core/admin/members/edit/dto/edit.args.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ArgsType, Field, Int } from "@nestjs/graphql"; | ||
|
||
@ArgsType() | ||
export class EditAdminMembersArgs { | ||
@Field(() => Int) | ||
id: number; | ||
|
||
@Field(() => String) | ||
name: string; | ||
|
||
@Field(() => String) | ||
email: string; | ||
|
||
@Field(() => Boolean) | ||
newsletter: boolean; | ||
|
||
@Field(() => String) | ||
first_name: string; | ||
|
||
@Field(() => String) | ||
last_name: string; | ||
|
||
@Field(() => Date) | ||
birthday: Date; | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/plugins/core/admin/members/edit/edit.resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Args, Mutation, Resolver } from "@nestjs/graphql"; | ||
import { UseGuards } from "@nestjs/common"; | ||
|
||
import { EditAdminMembersService } from "./edit.service"; | ||
import { EditAdminMembersArgs } from "./dto/edit.args"; | ||
|
||
import { AdminAuthGuards } from "@/utils/guards/admin-auth.guard"; | ||
|
||
@Resolver() | ||
export class EditAdminMembersResolver { | ||
constructor(private readonly service: EditAdminMembersService) {} | ||
|
||
@Mutation(() => String) | ||
@UseGuards(AdminAuthGuards) | ||
async admin__core_members__edit( | ||
@Args() args: EditAdminMembersArgs | ||
): Promise<string> { | ||
return this.service.edit(args); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
backend/src/plugins/core/admin/members/edit/edit.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { eq } from "drizzle-orm"; | ||
|
||
import { EditAdminMembersArgs } from "./dto/edit.args"; | ||
|
||
import { core_users } from "@/plugins/core/admin/database/schema/users"; | ||
import { DatabaseService } from "@/database/database.service"; | ||
import { NotFoundError } from "@/utils/errors/not-found-error"; | ||
import { AccessDeniedError } from "@/utils/errors/access-denied-error"; | ||
|
||
@Injectable() | ||
export class EditAdminMembersService { | ||
constructor(private readonly databaseService: DatabaseService) {} | ||
|
||
async edit({ | ||
id, | ||
name, | ||
email, | ||
newsletter, | ||
first_name, | ||
last_name, | ||
birthday | ||
}: EditAdminMembersArgs): Promise<string> { | ||
const user = await this.databaseService.db.query.core_users.findFirst({ | ||
where: eq(core_users.id, id) | ||
}); | ||
|
||
if (!user) throw new NotFoundError("User"); | ||
|
||
const admin = | ||
await this.databaseService.db.query.core_admin_permissions.findFirst({ | ||
where: (table, { or, eq }) => | ||
or(eq(table.user_id, user.id), eq(table.group_id, user.group_id)) | ||
}); | ||
|
||
if (!admin) throw new AccessDeniedError(); | ||
|
||
await this.databaseService.db | ||
.update(core_users) | ||
.set({ | ||
name: name, | ||
email: email, | ||
newsletter: newsletter, | ||
first_name: first_name, | ||
last_name: last_name, | ||
birthday: birthday | ||
}) | ||
.where(eq(core_users.id, id)); | ||
|
||
return "Success!"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters