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:
42
packages/brain/src/missions.ts
Normal file
42
packages/brain/src/missions.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { eq, type Db, missions } from '@mosaic/db';
|
||||
|
||||
export type Mission = typeof missions.$inferSelect;
|
||||
export type NewMission = typeof missions.$inferInsert;
|
||||
|
||||
export function createMissionsRepo(db: Db) {
|
||||
return {
|
||||
async findAll(): Promise<Mission[]> {
|
||||
return db.select().from(missions);
|
||||
},
|
||||
|
||||
async findById(id: string): Promise<Mission | undefined> {
|
||||
const rows = await db.select().from(missions).where(eq(missions.id, id));
|
||||
return rows[0];
|
||||
},
|
||||
|
||||
async findByProject(projectId: string): Promise<Mission[]> {
|
||||
return db.select().from(missions).where(eq(missions.projectId, projectId));
|
||||
},
|
||||
|
||||
async create(data: NewMission): Promise<Mission> {
|
||||
const rows = await db.insert(missions).values(data).returning();
|
||||
return rows[0]!;
|
||||
},
|
||||
|
||||
async update(id: string, data: Partial<NewMission>): Promise<Mission | undefined> {
|
||||
const rows = await db
|
||||
.update(missions)
|
||||
.set({ ...data, updatedAt: new Date() })
|
||||
.where(eq(missions.id, id))
|
||||
.returning();
|
||||
return rows[0];
|
||||
},
|
||||
|
||||
async remove(id: string): Promise<boolean> {
|
||||
const rows = await db.delete(missions).where(eq(missions.id, id)).returning();
|
||||
return rows.length > 0;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export type MissionsRepo = ReturnType<typeof createMissionsRepo>;
|
||||
Reference in New Issue
Block a user