add notes
This commit is contained in:
@@ -1,20 +1,21 @@
|
|||||||
import { relations } from 'drizzle-orm';
|
import { relations } from 'drizzle-orm';
|
||||||
import { integer, pgSchema, serial, timestamp, varchar } from 'drizzle-orm/pg-core';
|
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', {
|
export const tasks = personalWebsiteSchema.table('tasks', {
|
||||||
id: serial('id').primaryKey(),
|
id: serial('id').primaryKey(),
|
||||||
name: varchar('name', { length: 256 }),
|
name: varchar('name', { length: 256 }),
|
||||||
currentPoints: integer('current_points').default(0),
|
currentPoints: integer('current_points').default(0),
|
||||||
totalPoints: integer('total_points').default(1),
|
totalPoints: integer('total_points').default(1),
|
||||||
|
notes: varchar('notes', { length: 8192 }),
|
||||||
createdAt: timestamp('created_at').defaultNow(),
|
createdAt: timestamp('created_at').defaultNow(),
|
||||||
updatedAt: timestamp('updated_at').defaultNow()
|
updatedAt: timestamp('updated_at').defaultNow()
|
||||||
});
|
});
|
||||||
|
|
||||||
export const tasksRelations = relations(tasks, ({ many }) => ({
|
export const tasksRelations = relations(tasks, ({ many }) => ({
|
||||||
tasksToTopics: many(tasksToTopics)
|
tasksToTopics: many(tasksToTopics)
|
||||||
}))
|
}));
|
||||||
|
|
||||||
export const topics = personalWebsiteSchema.table('topics', {
|
export const topics = personalWebsiteSchema.table('topics', {
|
||||||
id: serial('id').primaryKey(),
|
id: serial('id').primaryKey(),
|
||||||
@@ -35,7 +36,7 @@ export const tasksToTopics = personalWebsiteSchema.table('tasks_to_topics', {
|
|||||||
topicId: integer('topic_id')
|
topicId: integer('topic_id')
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => topics.id)
|
.references(() => topics.id)
|
||||||
})
|
});
|
||||||
|
|
||||||
export const taskToTopicsRelations = relations(tasksToTopics, ({ one }) => ({
|
export const taskToTopicsRelations = relations(tasksToTopics, ({ one }) => ({
|
||||||
task: one(tasks, {
|
task: one(tasks, {
|
||||||
@@ -70,4 +71,3 @@ export const publications = personalWebsiteSchema.table('publications', {
|
|||||||
createdAt: timestamp('created_at').defaultNow(),
|
createdAt: timestamp('created_at').defaultNow(),
|
||||||
updatedAt: timestamp('updated_at').defaultNow()
|
updatedAt: timestamp('updated_at').defaultNow()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ export const actions = {
|
|||||||
return { status: 401 };
|
return { status: 401 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const data = await request.formData();
|
const data = await request.formData();
|
||||||
|
|
||||||
const topic = await db
|
const topic = await db
|
||||||
@@ -98,13 +96,33 @@ export const actions = {
|
|||||||
|
|
||||||
const data = await request.formData();
|
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
|
await db
|
||||||
.update(tasks)
|
.update(tasks)
|
||||||
.set({
|
.set({
|
||||||
currentPoints: Number(data.get('currentPoints')),
|
currentPoints,
|
||||||
totalPoints: Number(data.get('totalPoints')),
|
totalPoints: Number(data.get('totalPoints')),
|
||||||
updatedAt: new Date()
|
updatedAt: new Date()
|
||||||
})
|
})
|
||||||
.where(eq(tasks.id, Number(params.id)));
|
.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)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -152,3 +152,23 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
||||||
|
|||||||
Reference in New Issue
Block a user