not even sure

This commit is contained in:
2025-09-20 09:49:54 -05:00
parent a8bbfebd00
commit d4d690eb15
10 changed files with 101 additions and 40 deletions

View File

@@ -58,29 +58,33 @@ export const create = mutation({
updatedBy: v.optional(v.id('users')),
},
handler: async (ctx, args) => {
const authUserId = await getAuthUserId(ctx);
const authUserId: Id<'users'> | null = await getAuthUserId(ctx);
if (!args.userId && !authUserId) {
throw new ConvexError('Not authenticated.');
}
const userId = args.userId ?? authUserId!;
const updatedBy = args.updatedBy ?? authUserId!;
await ensureUser(ctx, userId);
await ensureUser(ctx, updatedBy);
const message = args.message.trim();
if (message.length === 0) {
throw new ConvexError('Message cannot be empty.');
}
const statusId = await ctx.db.insert('statuses', {
message,
userId,
updatedBy,
updatedAt: Date.now(),
});
const userId = args.userId ?? authUserId!;
const updatedBy = args.updatedBy ?? authUserId;
await ensureUser(ctx, userId);
let statusId: Id<'statuses'>;
if (updatedBy) {
ensureUser(ctx, updatedBy);
statusId = await ctx.db.insert('statuses', {
message,
userId,
updatedBy,
updatedAt: Date.now(),
});
} else {
statusId = await ctx.db.insert('statuses', {
message,
userId,
updatedAt: Date.now(),
});
}
await ctx.db.patch(userId, { currentStatusId: statusId });
return { statusId };
},
@@ -125,7 +129,6 @@ export const bulkCreate = mutation({
},
});
// Update all users - simplified
export const updateAllStatuses = mutation({
args: { message: v.string() },
handler: async (ctx, args) => {
@@ -152,22 +155,19 @@ export const updateAllStatuses = mutation({
},
});
// Lunch status with automatic return - this should be an action
export const createLunchStatus = mutation({
args: {},
handler: async (ctx) => {
const authUserId = await getAuthUserId(ctx);
if (!authUserId) throw new ConvexError('Not authenticated.');
// Create lunch status
await ctx.runMutation(api.statuses.create, {
message: 'At lunch',
userId: authUserId
userId: authUserId,
});
const oneHour = 60 * 60 * 1000;
console.log('Scheduling return to desk after 1 hour');
await ctx.scheduler.runAfter(oneHour, api.statuses.create, {
message: 'At desk',
userId: authUserId
userId: authUserId,
});
return { success: true };
},
@@ -257,7 +257,10 @@ export const listHistory = query({
userId: v.optional(v.id('users')),
paginationOpts: paginationOptsValidator,
},
handler: async (ctx, { userId, paginationOpts }): Promise<Paginated<StatusRow>> => {
handler: async (
ctx,
{ userId, paginationOpts },
): Promise<Paginated<StatusRow>> => {
const result = userId
? await ctx.db
.query('statuses')