beeeeg update
Some checks failed
Test and deploy staging / staging (push) Has been cancelled

This commit is contained in:
2026-09-23 04:15:10 +00:00
parent 487eff5bb2
commit d0c7b6548b
135 changed files with 9531 additions and 1777 deletions

View File

@@ -1,8 +1,11 @@
import { isAdmin, requireAdmin } from '$lib/server/authorization';
import type { Actions, PageServerLoad } from './$types';
import { db } from '$lib/server/db';
import { tasks, tasksToTopics, topics } from '$lib/server/db/schema';
import { eq, and } from 'drizzle-orm';
export const load = async ({ cookies, params }) => {
export const load: PageServerLoad = async (event) => {
const { params } = event;
return {
task: await db.query.tasks.findFirst({
with: {
@@ -17,28 +20,24 @@ export const load = async ({ cookies, params }) => {
}
}),
topics: await db.query.topics.findMany(),
editable: cookies.get('token')
editable: isAdmin(event)
};
};
export const actions = {
createTopic: async ({ cookies, request, params }) => {
if (!cookies.get('token')) {
return { status: 401 };
}
export const actions: Actions = {
createTopic: async (event) => {
requireAdmin(event);
const { request, params } = event;
const data = await request.formData();
const topic = await db
.insert(topics)
.values({ name: data.get('name') })
.values({ name: String(data.get('name') ?? '').trim() })
.returning();
const existing = await db.query.tasksToTopics.findFirst({
where: and(
eq(tasksToTopics.taskId, Number(params.id)),
eq(tasksToTopics.topicId, topic[0].id)
)
where: { taskId: Number(params.id), topicId: topic[0].id }
});
if (!existing) {
@@ -48,21 +47,18 @@ export const actions = {
.returning();
}
},
addTopic: async ({ cookies, request, params }) => {
if (!cookies.get('token')) {
return { status: 401 };
}
addTopic: async (event) => {
requireAdmin(event);
const { request, params } = event;
const data = await request.formData();
const topicId = Number(data.get('topic-id'));
const existing = await db.query.tasksToTopics.findFirst({
where: and(eq(tasksToTopics.taskId, Number(params.id)), eq(tasksToTopics.topicId, topicId))
where: { taskId: Number(params.id), topicId }
});
console.log(existing);
if (!existing) {
await db
.insert(tasksToTopics)
@@ -70,17 +66,16 @@ export const actions = {
.returning();
}
},
removeTopic: async ({ cookies, request, params }) => {
if (!cookies.get('token')) {
return { status: 401 };
}
removeTopic: async (event) => {
requireAdmin(event);
const { request, params } = event;
const data = await request.formData();
const topicId = Number(data.get('topic-id'));
const existing = await db.query.tasksToTopics.findFirst({
where: and(eq(tasksToTopics.taskId, Number(params.id)), eq(tasksToTopics.topicId, topicId))
where: { taskId: Number(params.id), topicId }
});
if (existing) {
@@ -91,10 +86,9 @@ export const actions = {
);
}
},
updateProgress: async ({ cookies, request, params }) => {
if (!cookies.get('token')) {
return { status: 401 };
}
updateProgress: async (event) => {
requireAdmin(event);
const { request, params } = event;
const data = await request.formData();
@@ -112,10 +106,9 @@ export const actions = {
})
.where(eq(tasks.id, Number(params.id)));
},
updateNotes: async ({ cookies, request, params }) => {
if (!cookies.get('token')) {
return { status: 401 };
}
updateNotes: async (event) => {
requireAdmin(event);
const { request, params } = event;
const data = await request.formData();

View File

@@ -1,20 +1,21 @@
import { requireAdmin } from '$lib/server/authorization';
import type { Actions } from './$types';
import { db } from '$lib/server/db';
import { tasks } from '$lib/server/db/schema';
import { redirect } from '@sveltejs/kit';
export const actions = {
default: async ({ cookies, request }) => {
if (!cookies.get('token')) {
return { status: 401 };
}
export const actions: Actions = {
default: async (event) => {
requireAdmin(event);
const { request } = event;
const data = await request.formData();
const task = await db
.insert(tasks)
.values({ name: data.get('name') })
.values({ name: String(data.get('name') ?? '').trim() })
.returning();
redirect(303, '/progress/' + task[0].id);
redirect(303, '/projects/progress/' + task[0].id);
}
};