rhythia-api 205.0.0 → 208.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,12 @@ const adminOperations = {
19
19
  removeAllScores: z.object({ userId: z.number() }),
20
20
  invalidateRankedScores: z.object({ userId: z.number() }),
21
21
  unbanUser: z.object({ userId: z.number() }),
22
+ getScoresPaginated: z.object({
23
+ page: z.number().min(1).default(1),
24
+ limit: z.number().min(1).max(100).default(50),
25
+ userId: z.number().optional(),
26
+ includeAdditionalData: z.boolean().default(true),
27
+ }),
22
28
  } as const;
23
29
 
24
30
  // Create a discriminated union type for operation parameters
@@ -67,6 +73,10 @@ const OperationParam = z.discriminatedUnion("operation", [
67
73
  operation: z.literal("changeBadges"),
68
74
  params: adminOperations.changeBadges,
69
75
  }),
76
+ z.object({
77
+ operation: z.literal("getScoresPaginated"),
78
+ params: adminOperations.getScoresPaginated,
79
+ }),
70
80
  ]);
71
81
 
72
82
  export const Schema = {
@@ -209,6 +219,64 @@ export async function handler(
209
219
  }
210
220
 
211
221
  break;
222
+
223
+ case "getScoresPaginated":
224
+ const offset = (params.page - 1) * params.limit;
225
+ let query = supabase
226
+ .from("scores")
227
+ .select(
228
+ `
229
+ id,
230
+ awarded_sp,
231
+ userId,
232
+ additional_data,
233
+ profiles (
234
+ username
235
+ )
236
+ `
237
+ )
238
+ .eq("passed", true)
239
+ .order("created_at", { ascending: false })
240
+ .range(offset, offset + params.limit - 1);
241
+
242
+ if (params.userId) {
243
+ query = query.eq("userId", params.userId);
244
+ }
245
+
246
+ const { data: scoresData, error: scoresError, count } = await query;
247
+
248
+ if (scoresError) {
249
+ result = { error: scoresError, data: null };
250
+ } else {
251
+ const transformedScores = scoresData?.map((score) => {
252
+ const transformed: any = {
253
+ id: score.id,
254
+ awarded_sp: score.awarded_sp,
255
+ userId: score.userId,
256
+ username: score.profiles?.username || null,
257
+ };
258
+
259
+ if (params.includeAdditionalData) {
260
+ transformed.additional_data = score.additional_data;
261
+ }
262
+
263
+ return transformed;
264
+ });
265
+
266
+ result = {
267
+ data: {
268
+ scores: transformedScores,
269
+ pagination: {
270
+ page: params.page,
271
+ limit: params.limit,
272
+ total: count || 0,
273
+ totalPages: Math.ceil((count || 0) / params.limit),
274
+ },
275
+ },
276
+ error: null,
277
+ };
278
+ }
279
+ break;
212
280
  }
213
281
 
214
282
  // Log the admin action
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "205.0.0",
3
+ "version": "208.0.0",
4
4
  "main": "index.ts",
5
5
  "author": "online-contributors-cunev",
6
6
  "scripts": {