feat(vessel): Schiffsflotte im Profil und Logbuch-Auswahl

Benutzerweiter Vessel-Pool (E2E, Sync, Migration von Legacy-Yachts) mit
LogbookVesselSelection und LogbookVesselPicker. Profil mit Accordion
(Flotte & Crew); Demo und Onboarding-Tour inkl. profile_vessel_pool.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-01 21:25:08 +02:00
parent 182ea497d8
commit ec11dd8d2b
39 changed files with 2107 additions and 113 deletions
+89
View File
@@ -593,6 +593,95 @@ router.post('/person-pool/push', requireUser, async (req: any, res) => {
}
})
router.get('/vessel-pool', requireUser, async (req: any, res) => {
try {
const { hasVesselPoolPrismaModels, isMissingPrismaTable, VESSEL_POOL_MIGRATION_HINT } =
await import('../utils/crewPoolSchema.js')
if (!hasVesselPoolPrismaModels()) {
console.warn('Vessel pool Prisma models missing — run prisma generate')
return res.status(503).json({ error: VESSEL_POOL_MIGRATION_HINT, vessels: [] })
}
const vessels = await prisma.vesselPayload.findMany({
where: { userId: req.userId }
})
return res.json({ vessels })
} catch (error: unknown) {
const { isMissingPrismaTable, VESSEL_POOL_MIGRATION_HINT } = await import('../utils/crewPoolSchema.js')
if (isMissingPrismaTable(error)) {
return res.status(503).json({ error: VESSEL_POOL_MIGRATION_HINT, vessels: [] })
}
return sendInternalError(res, error, 'auth/vessel-pool-get')
}
})
router.post('/vessel-pool/push', requireUser, async (req: any, res) => {
try {
const { hasVesselPoolPrismaModels, isMissingPrismaTable, VESSEL_POOL_MIGRATION_HINT } =
await import('../utils/crewPoolSchema.js')
if (!hasVesselPoolPrismaModels()) {
return res.status(503).json({ error: VESSEL_POOL_MIGRATION_HINT })
}
const { items } = req.body
if (!items || !Array.isArray(items)) {
return res.status(400).json({ error: 'items array is required' })
}
const results: Array<{ payloadId: string; status: string; error?: string; reason?: string }> = []
for (const item of items) {
const { action, payloadId, data, updatedAt } = item
const itemUpdatedAt = new Date(updatedAt)
try {
if (action === 'delete') {
await prisma.vesselPayload.deleteMany({
where: { userId: req.userId, payloadId }
})
results.push({ payloadId, status: 'success' })
continue
}
const parsed = JSON.parse(data)
const encryptedData = parsed.encryptedData || parsed.ciphertext
const { iv, tag } = parsed
const existing = await prisma.vesselPayload.findUnique({
where: { userId_payloadId: { userId: req.userId, payloadId } }
})
if (existing && new Date(existing.updatedAt) > itemUpdatedAt) {
results.push({ payloadId, status: 'conflict', reason: 'Server version is newer' })
continue
}
await prisma.vesselPayload.upsert({
where: { userId_payloadId: { userId: req.userId, payloadId } },
create: {
userId: req.userId,
payloadId,
encryptedData,
iv,
tag,
updatedAt: itemUpdatedAt
},
update: { encryptedData, iv, tag, updatedAt: itemUpdatedAt }
})
results.push({ payloadId, status: 'success' })
} catch (err: any) {
results.push({ payloadId, status: 'error', error: err.message || 'Operation failed' })
}
}
return res.json({ results })
} catch (error: unknown) {
const { isMissingPrismaTable, VESSEL_POOL_MIGRATION_HINT } = await import('../utils/crewPoolSchema.js')
if (isMissingPrismaTable(error)) {
return res.status(503).json({ error: VESSEL_POOL_MIGRATION_HINT })
}
return sendInternalError(res, error, 'auth/vessel-pool-push')
}
})
router.get('/profile', requireUser, async (req: any, res) => {
try {
const user = await prisma.user.findUnique({
+8
View File
@@ -80,6 +80,13 @@ router.get('/share-pull', async (req: any, res) => {
const logbookCrewSelection = await prisma.logbookCrewSelectionPayload.findUnique({
where: { logbookId }
})
let logbookVesselSelection = null
const { hasVesselPoolPrismaModels } = await import('../utils/crewPoolSchema.js')
if (hasVesselPoolPrismaModels()) {
logbookVesselSelection = await prisma.logbookVesselSelectionPayload.findUnique({
where: { logbookId }
})
}
const entries = await prisma.entryPayload.findMany({ where: { logbookId } })
const photos = await prisma.photoPayload.findMany({ where: { logbookId } })
const gpsTracks = await prisma.gpsTrackPayload.findMany({ where: { logbookId } })
@@ -90,6 +97,7 @@ router.get('/share-pull', async (req: any, res) => {
deviation,
crews,
logbookCrewSelection,
logbookVesselSelection,
entries,
photos,
gpsTracks
+33 -1
View File
@@ -147,6 +147,8 @@ router.post('/push', async (req: any, res) => {
await prisma.gpsTrackPayload.deleteMany({ where: { logbookId, entryId: payloadId } })
} else if (type === 'logbookCrew') {
await prisma.logbookCrewSelectionPayload.deleteMany({ where: { logbookId } })
} else if (type === 'logbookVessel') {
await prisma.logbookVesselSelectionPayload.deleteMany({ where: { logbookId } })
} else {
results.push({ payloadId, status: 'error', error: `Unsupported delete type: ${type}` })
continue
@@ -270,6 +272,29 @@ router.post('/push', async (req: any, res) => {
update: { encryptedData, iv, tag, updatedAt: itemUpdatedAt }
})
}
} else if (type === 'logbookVessel') {
const { hasVesselPoolPrismaModels, VESSEL_POOL_MIGRATION_HINT } =
await import('../utils/crewPoolSchema.js')
if (!hasVesselPoolPrismaModels()) {
results.push({
payloadId,
status: 'error',
error: VESSEL_POOL_MIGRATION_HINT
})
continue
}
{
const existing = await prisma.logbookVesselSelectionPayload.findUnique({ where: { logbookId } })
if (existing && new Date(existing.updatedAt) > itemUpdatedAt) {
results.push({ payloadId, status: 'conflict', reason: 'Server version is newer' })
continue
}
await prisma.logbookVesselSelectionPayload.upsert({
where: { logbookId },
create: { logbookId, encryptedData, iv, tag, updatedAt: itemUpdatedAt },
update: { encryptedData, iv, tag, updatedAt: itemUpdatedAt }
})
}
}
recordCollaboratorChange(
@@ -336,18 +361,25 @@ router.get('/pull', async (req: any, res) => {
const photos = await prisma.photoPayload.findMany({ where: { logbookId } })
const gpsTracks = await prisma.gpsTrackPayload.findMany({ where: { logbookId } })
let logbookCrewSelection = null
const { hasCrewPoolPrismaModels } = await import('../utils/crewPoolSchema.js')
let logbookVesselSelection = null
const { hasCrewPoolPrismaModels, hasVesselPoolPrismaModels } = await import('../utils/crewPoolSchema.js')
if (hasCrewPoolPrismaModels()) {
logbookCrewSelection = await prisma.logbookCrewSelectionPayload.findUnique({
where: { logbookId }
})
}
if (hasVesselPoolPrismaModels()) {
logbookVesselSelection = await prisma.logbookVesselSelectionPayload.findUnique({
where: { logbookId }
})
}
return res.json({
yacht,
deviation,
crews,
logbookCrewSelection,
logbookVesselSelection,
entries,
photos,
gpsTracks
+14
View File
@@ -12,9 +12,23 @@ export function hasCrewPoolPrismaModels(): boolean {
)
}
export function hasVesselPoolPrismaModels(): boolean {
const client = prisma as unknown as {
vesselPayload?: { findMany: unknown }
logbookVesselSelectionPayload?: { findUnique: unknown }
}
return (
typeof client.vesselPayload?.findMany === 'function' &&
typeof client.logbookVesselSelectionPayload?.findUnique === 'function'
)
}
export const CREW_POOL_MIGRATION_HINT =
'Crew-Pool-Datenbank fehlt. Im Ordner server ausführen: npx prisma generate && npx prisma db push — danach Server neu starten.'
export const VESSEL_POOL_MIGRATION_HINT =
'Schiffs-Pool-Datenbank fehlt. Im Ordner server ausführen: npx prisma generate && npx prisma db push — danach Server neu starten.'
export function isMissingPrismaTable(error: unknown): boolean {
return (
typeof error === 'object' &&