feat: auth middleware, brain data layer, Valkey queue (P1-002/003/004) (#71)
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #71.
This commit is contained in:
50
packages/brain/src/tasks.ts
Normal file
50
packages/brain/src/tasks.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { eq, type Db, tasks } from '@mosaic/db';
|
||||
|
||||
export type Task = typeof tasks.$inferSelect;
|
||||
export type NewTask = typeof tasks.$inferInsert;
|
||||
|
||||
export function createTasksRepo(db: Db) {
|
||||
return {
|
||||
async findAll(): Promise<Task[]> {
|
||||
return db.select().from(tasks);
|
||||
},
|
||||
|
||||
async findById(id: string): Promise<Task | undefined> {
|
||||
const rows = await db.select().from(tasks).where(eq(tasks.id, id));
|
||||
return rows[0];
|
||||
},
|
||||
|
||||
async findByProject(projectId: string): Promise<Task[]> {
|
||||
return db.select().from(tasks).where(eq(tasks.projectId, projectId));
|
||||
},
|
||||
|
||||
async findByMission(missionId: string): Promise<Task[]> {
|
||||
return db.select().from(tasks).where(eq(tasks.missionId, missionId));
|
||||
},
|
||||
|
||||
async findByStatus(status: Task['status']): Promise<Task[]> {
|
||||
return db.select().from(tasks).where(eq(tasks.status, status));
|
||||
},
|
||||
|
||||
async create(data: NewTask): Promise<Task> {
|
||||
const rows = await db.insert(tasks).values(data).returning();
|
||||
return rows[0]!;
|
||||
},
|
||||
|
||||
async update(id: string, data: Partial<NewTask>): Promise<Task | undefined> {
|
||||
const rows = await db
|
||||
.update(tasks)
|
||||
.set({ ...data, updatedAt: new Date() })
|
||||
.where(eq(tasks.id, id))
|
||||
.returning();
|
||||
return rows[0];
|
||||
},
|
||||
|
||||
async remove(id: string): Promise<boolean> {
|
||||
const rows = await db.delete(tasks).where(eq(tasks.id, id)).returning();
|
||||
return rows.length > 0;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export type TasksRepo = ReturnType<typeof createTasksRepo>;
|
||||
Reference in New Issue
Block a user