Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/SMS-COSMO/Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
KishinZW committed Mar 9, 2025
2 parents 6e352a1 + eff9ffe commit a73911d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const contents = sqliteTable('contents', {
state: text('state', { enum: ['created', 'approved', 'rejected', 'inuse', 'outdated'] }).notNull().default('created'),
categoryId: integer('category_id').references(() => pools.id, setNull),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
reviewNotes: text('reviewNotes'),
});

export const contentsRelations = relations(contents, ({ one, many }) => ({
Expand Down
9 changes: 9 additions & 0 deletions server/trpc/controllers/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { db } from '../../db/db';
import { contents } from '../../db/schema';
import { UserController } from './user';

type ContentState = 'created' | 'approved' | 'rejected' | 'inuse' | 'outdated';

export class ContentController {
private userController: UserController;
constructor() {
Expand Down Expand Up @@ -66,4 +68,11 @@ export class ContentController {
});
return res;
}

async updateAuditStatus(id: number, state: ContentState, reviewNotes?: string) {
await db.update(contents)
.set({ state, reviewNotes: reviewNotes ?? null })
.where(eq(contents.id, id));
return '内容审核状态修改成功';
}
}
9 changes: 9 additions & 0 deletions server/trpc/routers/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const S3FileIdZod = z.string();
const lifespanZod = z.number()
.max(15_552_000, { message: '内容有效期不能超过180天' });
const categoryIdZod = z.number();
const stateEnumZod = z.enum(['created', 'approved', 'rejected', 'inuse', 'outdated'], { errorMap: () => ({ message: '审核状态错误' }) });
const reviewNotesZod = z.string().optional();

export const contentRouter = router({
create: protectedProcedure
Expand Down Expand Up @@ -59,4 +61,11 @@ export const contentRouter = router({
.query(async ({ ctx, input }) => {
return await ctx.contentController.getInfo(input.id);
}),

reviewNotes: protectedProcedure
.use(requireRoles(['admin']))
.input(z.object({ id: idZod, state: stateEnumZod, reviewNotes: reviewNotesZod }))
.mutation(async ({ ctx, input }) => {
return await ctx.contentController.updateAuditStatus(input.id, input.state, input.reviewNotes);
}),
});

0 comments on commit a73911d

Please sign in to comment.