stopping point

This commit is contained in:
2025-09-10 10:11:46 -05:00
parent 603a23983c
commit bf12031773
6 changed files with 539 additions and 211 deletions

View File

@@ -14,6 +14,7 @@ type RWCtx = MutationCtx | QueryCtx;
type StatusRow = {
user: {
id: Id<'users'>;
email: string | null;
name: string | null;
imageUrl: string | null;
};
@@ -155,6 +156,8 @@ export const getCurrentForUser = query({
const getName = (u: Doc<'users'>): string | null =>
'name' in u && typeof u.name === 'string' ? u.name : null;
const getEmail = (u: Doc<'users'>): string | null =>
'email' in u && typeof u.email === 'string' ? u.email : null;
const getImageId = (u: Doc<'users'>): Id<'_storage'> | null => {
if (!('image' in u)) return null;
@@ -205,6 +208,7 @@ export const getCurrentForAll = query({
: null;
updatedByUser = {
id: updater._id,
email: getEmail(updater),
name: getName(updater),
imageUrl: updaterImageUrl,
};
@@ -222,6 +226,7 @@ export const getCurrentForAll = query({
return {
user: {
id: u._id,
email: getEmail(u),
name: getName(u),
imageUrl: userImageUrl,
},
@@ -269,6 +274,7 @@ export const listHistory = query({
const display: StatusRow['user'] = {
id: user._id,
email: getEmail(user),
name: getName(user),
imageUrl: imgUrl,
};
@@ -276,13 +282,13 @@ export const listHistory = query({
return display;
};
const page: StatusRow[] = [];
const statuses: StatusRow[] = [];
for (const s of result.page) {
const owner = await getDisplay(s.userId);
const updatedBy =
s.updatedBy !== s.userId ? await getDisplay(s.updatedBy) : null;
page.push({
statuses.push({
user: owner,
status: {
id: s._id,
@@ -292,6 +298,9 @@ export const listHistory = query({
},
});
}
const page = statuses.sort(
(a, b) => (b.status?.updatedAt ?? 0) - (a.status?.updatedAt ?? 0),
);
return {
page,