about page; added user profileform and me page

This commit is contained in:
2025-03-15 17:16:35 +01:00
parent 1ccbcddae3
commit cff9dad54c
17 changed files with 321 additions and 35 deletions
+11
View File
@@ -1,7 +1,18 @@
"use server";
import { userProfileSchema } from "@/lib/validation/zod/user";
import { api } from "@/trpc/server";
import { revalidatePath } from "next/cache";
import { z } from "zod";
export async function updateUserProfile(
profile: z.infer<typeof userProfileSchema>,
) {
const [result] = await api.users.updateProfile({ profile });
if (!result?.id) return { success: false };
revalidatePath("/me");
return { success: true };
}
export async function setUserPermissions(userId: string, permission: number) {
const result = await api.users.setPermission({ userId, permission });
+2 -2
View File
@@ -160,7 +160,7 @@ export const articleRouter = createTRPCRouter({
.optional(),
)
.query(async ({ ctx, input }) => {
return await ctx.db.query.articles.findMany({
return (await ctx.db.query.articles.findMany({
where: input?.categoryId
? eq(articles.categoryId, input.categoryId)
: undefined,
@@ -170,7 +170,7 @@ export const articleRouter = createTRPCRouter({
slug: true,
createdAt: true,
},
});
})) as Array<Article>;
}),
getCount: publicProcedure
+11 -1
View File
@@ -1,11 +1,21 @@
import { hasPermission, Role } from "@/lib/validation/permissions";
import { createTRPCRouter, protectedProcedure } from "../trpc";
import { z } from "zod";
import { permission } from "process";
import { users } from "@/server/db/schema";
import { desc, eq } from "drizzle-orm";
import { userProfileSchema } from "@/lib/validation/zod/user";
export const usersRouter = createTRPCRouter({
updateProfile: protectedProcedure
.input(z.object({ profile: userProfileSchema }))
.mutation(async ({ ctx, input }) => {
return await ctx.db
.update(users)
.set(input.profile)
.where(eq(users.id, ctx.session.user.id))
.returning();
}),
getAll: protectedProcedure.query(async ({ ctx }) => {
const isAdmin = hasPermission(ctx.session.user.role, Role.ADMIN);
if (!isAdmin) throw new Error("You are not allowed to get all users");