feat(coord): DB migration — project-scoped missions, multi-tenant RBAC (#149)
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #149.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { eq, type Db, missions } from '@mosaic/db';
|
||||
import { eq, and, type Db, missions } from '@mosaic/db';
|
||||
|
||||
export type Mission = typeof missions.$inferSelect;
|
||||
export type NewMission = typeof missions.$inferInsert;
|
||||
@@ -9,15 +9,34 @@ export function createMissionsRepo(db: Db) {
|
||||
return db.select().from(missions);
|
||||
},
|
||||
|
||||
async findAllByUser(userId: string): Promise<Mission[]> {
|
||||
return db.select().from(missions).where(eq(missions.userId, userId));
|
||||
},
|
||||
|
||||
async findById(id: string): Promise<Mission | undefined> {
|
||||
const rows = await db.select().from(missions).where(eq(missions.id, id));
|
||||
return rows[0];
|
||||
},
|
||||
|
||||
async findByIdAndUser(id: string, userId: string): Promise<Mission | undefined> {
|
||||
const rows = await db
|
||||
.select()
|
||||
.from(missions)
|
||||
.where(and(eq(missions.id, id), eq(missions.userId, userId)));
|
||||
return rows[0];
|
||||
},
|
||||
|
||||
async findByProject(projectId: string): Promise<Mission[]> {
|
||||
return db.select().from(missions).where(eq(missions.projectId, projectId));
|
||||
},
|
||||
|
||||
async findByProjectAndUser(projectId: string, userId: string): Promise<Mission[]> {
|
||||
return db
|
||||
.select()
|
||||
.from(missions)
|
||||
.where(and(eq(missions.projectId, projectId), eq(missions.userId, userId)));
|
||||
},
|
||||
|
||||
async create(data: NewMission): Promise<Mission> {
|
||||
const rows = await db.insert(missions).values(data).returning();
|
||||
return rows[0]!;
|
||||
|
||||
Reference in New Issue
Block a user