feat: add admin tables for comments and recordings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { GraphQLError } from "graphql";
|
||||
import { builder } from "../builder";
|
||||
import { CommentType } from "../types/index";
|
||||
import { CommentType, AdminCommentListType } from "../types/index";
|
||||
import { comments, users } from "../../db/schema/index";
|
||||
import { eq, and, desc } from "drizzle-orm";
|
||||
import { eq, and, desc, ilike, or, count } from "drizzle-orm";
|
||||
import { awardPoints, checkAchievements } from "../../lib/gamification";
|
||||
import { requireOwnerOrAdmin } from "../../lib/acl";
|
||||
import { requireOwnerOrAdmin, requireAdmin } from "../../lib/acl";
|
||||
|
||||
builder.queryField("commentsForVideo", (t) =>
|
||||
t.field({
|
||||
@@ -96,3 +96,52 @@ builder.mutationField("deleteComment", (t) =>
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
builder.queryField("adminListComments", (t) =>
|
||||
t.field({
|
||||
type: AdminCommentListType,
|
||||
args: {
|
||||
search: t.arg.string(),
|
||||
limit: t.arg.int(),
|
||||
offset: t.arg.int(),
|
||||
},
|
||||
resolve: async (_root, args, ctx) => {
|
||||
requireAdmin(ctx);
|
||||
const limit = args.limit ?? 50;
|
||||
const offset = args.offset ?? 0;
|
||||
|
||||
const conditions = args.search ? [ilike(comments.comment, `%${args.search}%`)] : [];
|
||||
const where = conditions.length > 0 ? and(...conditions) : undefined;
|
||||
|
||||
const [commentList, totalRows] = await Promise.all([
|
||||
ctx.db
|
||||
.select()
|
||||
.from(comments)
|
||||
.where(where)
|
||||
.orderBy(desc(comments.date_created))
|
||||
.limit(limit)
|
||||
.offset(offset),
|
||||
ctx.db.select({ total: count() }).from(comments).where(where),
|
||||
]);
|
||||
|
||||
const items = await Promise.all(
|
||||
commentList.map(async (c: any) => {
|
||||
const user = await ctx.db
|
||||
.select({
|
||||
id: users.id,
|
||||
first_name: users.first_name,
|
||||
last_name: users.last_name,
|
||||
artist_name: users.artist_name,
|
||||
avatar: users.avatar,
|
||||
})
|
||||
.from(users)
|
||||
.where(eq(users.id, c.user_id))
|
||||
.limit(1);
|
||||
return { ...c, user: user[0] || null };
|
||||
}),
|
||||
);
|
||||
|
||||
return { items, total: totalRows[0]?.total ?? 0 };
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user