|
|
|
@ -1,4 +1,4 @@
|
|
|
|
import type { Database } from 'better-sqlite3';
|
|
|
|
import type { Database } from 'bun:sqlite';
|
|
|
|
import { db } from '../db';
|
|
|
|
import { db } from '../db';
|
|
|
|
|
|
|
|
|
|
|
|
type CreateTaskInput = {
|
|
|
|
type CreateTaskInput = {
|
|
|
|
@ -21,15 +21,15 @@ export class TaskService {
|
|
|
|
const insertTask = this.dbInstance.prepare(`
|
|
|
|
const insertTask = this.dbInstance.prepare(`
|
|
|
|
INSERT INTO tasks (description, due_date, group_id, created_by)
|
|
|
|
INSERT INTO tasks (description, due_date, group_id, created_by)
|
|
|
|
VALUES (?, ?, ?, ?)
|
|
|
|
VALUES (?, ?, ?, ?)
|
|
|
|
RETURNING id
|
|
|
|
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|
const taskResult = insertTask.get(
|
|
|
|
const runResult = insertTask.run(
|
|
|
|
task.description,
|
|
|
|
task.description,
|
|
|
|
task.due_date ?? null,
|
|
|
|
task.due_date ?? null,
|
|
|
|
task.group_id ?? null,
|
|
|
|
task.group_id ?? null,
|
|
|
|
task.created_by
|
|
|
|
task.created_by
|
|
|
|
) as { id: number };
|
|
|
|
);
|
|
|
|
|
|
|
|
const taskId = Number((runResult as any).lastInsertRowid);
|
|
|
|
|
|
|
|
|
|
|
|
if (assignments.length > 0) {
|
|
|
|
if (assignments.length > 0) {
|
|
|
|
const insertAssignment = this.dbInstance.prepare(`
|
|
|
|
const insertAssignment = this.dbInstance.prepare(`
|
|
|
|
@ -42,11 +42,11 @@ export class TaskService {
|
|
|
|
for (const a of assignments) {
|
|
|
|
for (const a of assignments) {
|
|
|
|
if (seen.has(a.user_id)) continue;
|
|
|
|
if (seen.has(a.user_id)) continue;
|
|
|
|
seen.add(a.user_id);
|
|
|
|
seen.add(a.user_id);
|
|
|
|
insertAssignment.run(taskResult.id, a.user_id, a.assigned_by);
|
|
|
|
insertAssignment.run(taskId, a.user_id, a.assigned_by);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return taskResult.id;
|
|
|
|
return taskId;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return runTx();
|
|
|
|
return runTx();
|
|
|
|
|