add notes

This commit is contained in:
2025-03-23 02:09:41 +01:00
parent cccf2137a4
commit 16186baf7f
3 changed files with 45 additions and 7 deletions

View File

@@ -1,20 +1,21 @@
import { relations } from 'drizzle-orm';
import { integer, pgSchema, serial, timestamp, varchar } from 'drizzle-orm/pg-core';
export const personalWebsiteSchema = pgSchema('personal_website')
export const personalWebsiteSchema = pgSchema('personal_website');
export const tasks = personalWebsiteSchema.table('tasks', {
id: serial('id').primaryKey(),
name: varchar('name', { length: 256 }),
currentPoints: integer('current_points').default(0),
totalPoints: integer('total_points').default(1),
notes: varchar('notes', { length: 8192 }),
createdAt: timestamp('created_at').defaultNow(),
updatedAt: timestamp('updated_at').defaultNow()
});
export const tasksRelations = relations(tasks, ({ many }) => ({
tasksToTopics: many(tasksToTopics)
}))
}));
export const topics = personalWebsiteSchema.table('topics', {
id: serial('id').primaryKey(),
@@ -35,7 +36,7 @@ export const tasksToTopics = personalWebsiteSchema.table('tasks_to_topics', {
topicId: integer('topic_id')
.notNull()
.references(() => topics.id)
})
});
export const taskToTopicsRelations = relations(tasksToTopics, ({ one }) => ({
task: one(tasks, {
@@ -70,4 +71,3 @@ export const publications = personalWebsiteSchema.table('publications', {
createdAt: timestamp('created_at').defaultNow(),
updatedAt: timestamp('updated_at').defaultNow()
});

View File

@@ -25,8 +25,6 @@ export const actions = {
return { status: 401 };
}
const data = await request.formData();
const topic = await db
@@ -98,13 +96,33 @@ export const actions = {
const data = await request.formData();
const currentPoints =
Number(data.get('currentPoints')) <= Number(data.get('totalPoints'))
? Number(data.get('currentPoints'))
: Number(data.get('totalPoints'));
await db
.update(tasks)
.set({
currentPoints: Number(data.get('currentPoints')),
currentPoints,
totalPoints: Number(data.get('totalPoints')),
updatedAt: new Date()
})
.where(eq(tasks.id, Number(params.id)));
},
updateNotes: async ({ cookies, request, params }) => {
if (!cookies.get('token')) {
return { status: 401 };
}
const data = await request.formData();
await db
.update(tasks)
.set({
notes: data.get('notes') as string,
updatedAt: new Date()
})
.where(eq(tasks.id, Number(params.id)));
}
};

View File

@@ -152,3 +152,23 @@
</form>
</div>
</div>
<div class="my-8">
<h2 class="text-xl font-semibold text-center mb-4">Notes</h2>
<form method="POST" action="?/updateNotes" class="max-w-xl mx-auto">
<textarea
name="notes"
class="w-full p-3 border rounded min-h-[150px] resize-y"
placeholder="Add notes about this task..."
readonly={!data.editable}
onchange={(e) => data.editable && e.target.form?.submit()}>{data.task?.notes || ''}</textarea
>
{#if data.editable}
<div class="flex justify-end mt-2">
<Button type="submit" size="sm">Save Notes</Button>
</div>
{/if}
</form>
</div>