Multi-department fault log: NewBook-synced room locations + manual locations with categories, six-state task flow (submitted/in progress/ hold-parts/hold-later/temporary fix/fixed), photos per stage, priorities with unusable flag and per-task NewBook out-of-order push, costs on resolve, comment/audit thread, recurring task templates with note-to-template carryover, asset register, contractor register with document attachments, staff/contractor allocation, occupancy-aware summary filter, searchable history with CSV export, email notifications. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
import Fastify from 'fastify'
|
|
import cookie from '@fastify/cookie'
|
|
import cors from '@fastify/cors'
|
|
import multipart from '@fastify/multipart'
|
|
import staticFiles from '@fastify/static'
|
|
import { fileURLToPath } from 'url'
|
|
import { dirname, join } from 'path'
|
|
import { initDb } from './db.js'
|
|
import { startScheduler } from './lib/scheduler.js'
|
|
import { locationRoutes } from './routes/locations.js'
|
|
import { taskRoutes } from './routes/tasks.js'
|
|
import { photoRoutes } from './routes/photos.js'
|
|
import { historyRoutes } from './routes/history.js'
|
|
import { assetRoutes } from './routes/assets.js'
|
|
import { contractorRoutes } from './routes/contractors.js'
|
|
import { templateRoutes } from './routes/templates.js'
|
|
import { configRoutes } from './routes/config.js'
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
const UPLOADS_DIR = join(__dirname, '..', 'uploads')
|
|
|
|
const app = Fastify({ logger: true, trustProxy: true })
|
|
|
|
await app.register(cookie)
|
|
await app.register(cors, {
|
|
origin: process.env.CORS_ORIGIN || false,
|
|
credentials: true,
|
|
})
|
|
await app.register(multipart, { limits: { fileSize: 10 * 1024 * 1024 } })
|
|
await app.register(staticFiles, {
|
|
root: UPLOADS_DIR,
|
|
prefix: '/api/uploads/',
|
|
decorateReply: false,
|
|
})
|
|
|
|
app.get('/health', async () => ({ status: 'healthy' }))
|
|
|
|
await app.register(locationRoutes)
|
|
await app.register(taskRoutes)
|
|
await app.register(photoRoutes, { uploadsDir: UPLOADS_DIR })
|
|
await app.register(historyRoutes)
|
|
await app.register(assetRoutes)
|
|
await app.register(contractorRoutes, { uploadsDir: UPLOADS_DIR })
|
|
await app.register(templateRoutes)
|
|
await app.register(configRoutes)
|
|
|
|
try {
|
|
await initDb()
|
|
startScheduler(app)
|
|
await app.listen({ port: 3001, host: '0.0.0.0' })
|
|
} catch (err) {
|
|
app.log.error(err)
|
|
process.exit(1)
|
|
}
|