Assemble QMS app + SQLite refactor + Unraid single-container deploy
Build and Push Docker Image / build (push) Successful in 1m12s

Reconstruct the full app from init-source overlays (base + fix-1..6 +
update-1..3, last-wins) at the repo root, complete the missing pieces so it
builds and runs, and stage the Unraid deployment.

App completion:
- types/index.ts: former Prisma enums as string-literal unions + AppUser
- pages/_app.tsx + styles/globals.css (mount AppProvider/ToastProvider)
- API routes: auth/login, auth/me, users, submissions (+REVIEW_READY notify),
  forms (list/create), notifications
- scripts/create-admin.js: idempotent first-admin bootstrap
- 14 unbuilt nav targets stubbed via ComingSoon placeholder

SQLite refactor (single-container, no external DB):
- schema provider -> sqlite; enums -> String; Json -> String;
  FormField.options String[] -> JSON-encoded String
- lib/forms.ts (de)serialises options at the DB boundary
- drop mode:"insensitive" (unsupported on SQLite)
- enum imports repointed from @prisma/client to @/types

Deploy:
- multi-stage Dockerfile (next build -> prod runner), docker-entrypoint.sh
  (prisma db push -> create-admin -> next start), .dockerignore
- docker-compose.yml: br0 10.2.0.x, /mnt/user/appdata/qms -> /data volume
- README rewritten for the Unraid/Gitea Actions flow; .env scrubbed of the
  live Supabase credential; vercel.json removed

Verified: next build clean (41 routes); live SQLite round-trip of
login/session, form options array, and submission -> REVIEW_READY.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
jason
2026-06-15 16:57:15 -05:00
parent 631890c5bd
commit ad499f6782
70 changed files with 8045 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import { prisma } from '@/lib/prisma'
import { requireAuth, logAction } from '@/lib/auth'
import { notifySolutionConfirmed } from '@/lib/email'
import { NCRSeverity, NCRStatus } from '@/types'
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const user = await requireAuth(req, res, ['ADMIN', 'QC'])
if (!user) return
const { id } = req.query as { id: string }
const ncr = await prisma.nCR.findUnique({
where: { id },
include: { raisedBy: { select: { id: true, name: true, email: true } }, capa: { select: { ref: true } } },
})
if (!ncr) return res.status(404).json({ error: 'NCR not found' })
if (req.method === 'GET') {
return res.json({ data: ncr })
}
if (req.method === 'PATCH') {
const before = { ...ncr }
const { severity, status, resolution, category, confirmNotify } = req.body as {
severity?: NCRSeverity
status?: NCRStatus
resolution?: string
category?: string
confirmNotify?: boolean
}
const updateData: any = {}
if (severity !== undefined) updateData.severity = severity
if (status !== undefined) updateData.status = status
if (resolution !== undefined && category !== undefined) {
// Resolving — requires both resolution notes and a category, files to library
updateData.resolution = resolution
updateData.category = category
updateData.status = 'RESOLVED'
updateData.resolvedAt = new Date()
}
if (confirmNotify) {
updateData.notified = true
updateData.notifiedAt = new Date()
}
const updated = await prisma.nCR.update({
where: { id },
data: updateData,
include: { raisedBy: { select: { id: true, name: true, email: true } }, capa: { select: { ref: true } } },
})
// File to resolutions library
if (resolution !== undefined && category !== undefined) {
await prisma.resolution.create({
data: {
title: ncr.description.length > 80 ? ncr.description.slice(0, 80) + '…' : ncr.description,
category, resolution, linkedRef: ncr.ref,
}
})
}
// Confirm-and-notify: emails/notifies whoever raised the NCR
if (confirmNotify && ncr.raisedBy) {
await notifySolutionConfirmed(ncr.ref, ncr.description, ncr.raisedBy.email, ncr.raisedBy.id)
}
await logAction(user.id, 'UPDATE', 'NCR', id, before, updated)
return res.json({ data: updated })
}
res.status(405).end()
}
+48
View File
@@ -0,0 +1,48 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import { prisma } from '@/lib/prisma'
import { requireAuth, logAction, generateRef } from '@/lib/auth'
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const user = await requireAuth(req, res, ['ADMIN', 'QC'])
if (!user) return
if (req.method !== 'POST') return res.status(405).end()
const { id } = req.query as { id: string }
const { title, priority, ownerId, dueDate } = req.body
if (!title || !ownerId || !dueDate) {
return res.status(400).json({ error: 'title, ownerId, dueDate required' })
}
const ncr = await prisma.nCR.findUnique({ where: { id } })
if (!ncr) return res.status(404).json({ error: 'NCR not found' })
const count = await prisma.cAPA.count()
const ref = generateRef('CAPA', count)
const capa = await prisma.cAPA.create({
data: {
ref, title,
description: `Escalated from ${ncr.ref}: ${ncr.description}`,
priority: priority || 'MEDIUM',
ownerId, raisedById: user.id,
dueDate: new Date(dueDate),
},
include: { owner: { select: { id: true, name: true, email: true } } },
})
await prisma.cAPAEvent.create({
data: { capaId: capa.id, event: 'CAPA raised', note: `Escalated from ${ncr.ref} by ${user.name}` }
})
const updatedNcr = await prisma.nCR.update({
where: { id },
data: { status: 'ESCALATED', capaId: capa.id },
include: { raisedBy: { select: { name: true } }, capa: { select: { ref: true } } },
})
await logAction(user.id, 'UPDATE', 'NCR', id, { status: ncr.status }, { status: 'ESCALATED', capaRef: capa.ref })
await logAction(user.id, 'CREATE', 'CAPA', capa.id, null, { ref: capa.ref, fromNcr: ncr.ref })
return res.status(201).json({ data: { ncr: updatedNcr, capa } })
}
+41
View File
@@ -0,0 +1,41 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import { prisma } from '@/lib/prisma'
import { requireAuth, logAction, generateRef } from '@/lib/auth'
import { NCRStatus } from '@/types'
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const user = await requireAuth(req, res)
if (!user) return
if (req.method === 'GET') {
const { status } = req.query
const where: any = {}
if (status) where.status = status as NCRStatus
const ncrs = await prisma.nCR.findMany({
where,
include: { raisedBy: { select: { name: true } }, capa: { select: { ref: true } } },
orderBy: { createdAt: 'desc' },
})
return res.json({ data: ncrs })
}
if (req.method === 'POST') {
// Any authenticated user can report an issue (production intake)
const { description, source } = req.body
if (!description) return res.status(400).json({ error: 'description required' })
const count = await prisma.nCR.count()
const ref = generateRef('NCR', count)
const ncr = await prisma.nCR.create({
data: { ref, description, source, raisedById: user.id },
include: { raisedBy: { select: { name: true } } },
})
await logAction(user.id, 'CREATE', 'NCR', ncr.id, null, { ref, description })
return res.status(201).json({ data: ncr })
}
res.status(405).end()
}