Files
stack/packages/brain/src/missions.ts
Jarvis 774b76447d
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
ci/woodpecker/push/ci Pipeline failed
fix: rename all packages from @mosaic/* to @mosaicstack/*
- Updated all package.json name fields and dependency references
- Updated all TypeScript/JavaScript imports
- Updated .woodpecker/publish.yml filters and registry paths
- Updated tools/install.sh scope default
- Updated .npmrc registry paths (worktree + host)
- Enhanced update-checker.ts with checkForAllUpdates() multi-package support
- Updated CLI update command to show table of all packages
- Added KNOWN_PACKAGES, formatAllPackagesTable, getInstallAllCommand
- Marked checkForUpdate() with @deprecated JSDoc

Closes #391
2026-04-04 21:43:23 -05:00

62 lines
1.9 KiB
TypeScript

import { eq, and, type Db, missions } from '@mosaicstack/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 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]!;
},
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>;