Skip to content

Commit

Permalink
feat: hide rejected songs
Browse files Browse the repository at this point in the history
Signed-off-by: ZTL-UwU <[email protected]>
  • Loading branch information
ZTL-UwU committed Oct 23, 2024
1 parent 3e10e0e commit 465c3ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion server/trpc/controllers/song.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LibsqlError } from '@libsql/client';
import { and, count, desc, eq, gt, inArray, or } from 'drizzle-orm';
import { and, count, desc, eq, gt, inArray, ne, or } from 'drizzle-orm';
import { type TNewSong, db } from '../../db/db';
import { songs } from '~/server/db/schema';
import type { TStatus } from '~/types';
Expand Down Expand Up @@ -91,6 +91,20 @@ export class SongController {
}
}

async getListSafe() {
try {
const res = await db.select().from(songs).where(
and(
ne(songs.status, 'rejected'),
gt(songs.createdAt, new Date(Date.now() - 4 * 24 * 60 * 60 * 1000)),
),
).orderBy(desc(songs.createdAt));
return { success: true, res, message: '获取成功' };
} catch {
return { success: false, message: '服务器内部错误' };
}
}

async count(getAll: boolean) {
try {
let res = 0;
Expand Down
2 changes: 1 addition & 1 deletion server/trpc/routers/song.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const songRouter = router({

listSafe: publicProcedure
.query(async ({ ctx }) => {
const res = await ctx.songController.getList();
const res = await ctx.songController.getListSafe();
if (!res.success || !res.res)
throw new TRPCError({ code: 'BAD_REQUEST', message: res.message });
else
Expand Down

0 comments on commit 465c3ce

Please sign in to comment.