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