start on statuses table list thing
This commit is contained in:
@@ -11,22 +11,16 @@ import type { MutationCtx, QueryCtx } from './_generated/server';
|
||||
type RWCtx = MutationCtx | QueryCtx;
|
||||
|
||||
// CHANGED: typed helpers
|
||||
const ensureUser = async (
|
||||
ctx: RWCtx,
|
||||
userId: Id<'users'>,
|
||||
) => {
|
||||
const ensureUser = async (ctx: RWCtx, userId: Id<'users'>) => {
|
||||
const user = await ctx.db.get(userId);
|
||||
if (!user) throw new ConvexError('User not found.');
|
||||
return user;
|
||||
};
|
||||
|
||||
const latestStatusForOwner = async (
|
||||
ctx: RWCtx,
|
||||
ownerId: Id<'users'>,
|
||||
) => {
|
||||
const latestStatusForOwner = async (ctx: RWCtx, ownerId: Id<'users'>) => {
|
||||
const [latest] = await ctx.db
|
||||
.query('statuses')
|
||||
.withIndex('by_user_updatedAt', q => q.eq('userId', ownerId))
|
||||
.withIndex('by_user_updatedAt', (q) => q.eq('userId', ownerId))
|
||||
.order('desc')
|
||||
.take(1);
|
||||
return latest as Doc<'statuses'> | null;
|
||||
@@ -180,7 +174,7 @@ export const listHistoryByUser = query({
|
||||
|
||||
return await ctx.db
|
||||
.query('statuses')
|
||||
.withIndex('by_user_updatedAt', q => q.eq('userId', userId))
|
||||
.withIndex('by_user_updatedAt', (q) => q.eq('userId', userId))
|
||||
.order('desc')
|
||||
.paginate(paginationOpts);
|
||||
},
|
||||
|
Reference in New Issue
Block a user