dashboard fix

This commit is contained in:
root
2026-05-19 21:25:38 -04:00
parent 7ac0098c7f
commit d4f7de5762
27 changed files with 705 additions and 336 deletions
+10 -9
View File
@@ -6,6 +6,7 @@ import { uploadImage } from '../lib/storage'
import { requireCompanyAuth } from '../middleware/requireCompanyAuth'
import { requireTenant } from '../middleware/requireTenant'
import { requireSubscription } from '../middleware/requireSubscription'
import { requireRole } from '../middleware/requireRole'
const router = Router()
const upload = multer({ storage: multer.memoryStorage(), limits: { fileSize: 10 * 1024 * 1024 } })
@@ -48,7 +49,7 @@ router.get('/', async (req, res, next) => {
} catch (err) { next(err) }
})
router.post('/', async (req, res, next) => {
router.post('/', requireRole('MANAGER'), async (req, res, next) => {
try {
const body = vehicleSchema.parse(req.body)
const vehicle = await prisma.vehicle.create({ data: { ...body, companyId: req.companyId } })
@@ -63,7 +64,7 @@ router.get('/:id', async (req, res, next) => {
} catch (err) { next(err) }
})
router.patch('/:id', async (req, res, next) => {
router.patch('/:id', requireRole('MANAGER'), async (req, res, next) => {
try {
const body = vehicleSchema.partial().parse(req.body)
if (body.status === 'MAINTENANCE' || body.status === 'OUT_OF_SERVICE') {
@@ -78,14 +79,14 @@ router.patch('/:id', async (req, res, next) => {
} catch (err) { next(err) }
})
router.delete('/:id', async (req, res, next) => {
router.delete('/:id', requireRole('MANAGER'), async (req, res, next) => {
try {
await prisma.vehicle.updateMany({ where: { id: req.params.id, companyId: req.companyId }, data: { status: 'OUT_OF_SERVICE', isPublished: false } })
res.json({ data: { success: true } })
} catch (err) { next(err) }
})
router.post('/:id/photos', upload.array('photos', 10), async (req, res, next) => {
router.post('/:id/photos', requireRole('MANAGER'), upload.array('photos', 10), async (req, res, next) => {
try {
const vehicle = await prisma.vehicle.findFirstOrThrow({ where: { id: req.params.id, companyId: req.companyId } })
const files = req.files as Express.Multer.File[]
@@ -95,7 +96,7 @@ router.post('/:id/photos', upload.array('photos', 10), async (req, res, next) =>
} catch (err) { next(err) }
})
router.delete('/:id/photos/:idx', async (req, res, next) => {
router.delete('/:id/photos/:idx', requireRole('MANAGER'), async (req, res, next) => {
try {
const vehicle = await prisma.vehicle.findFirstOrThrow({ where: { id: req.params.id, companyId: req.companyId } })
const idx = parseInt(req.params.idx)
@@ -105,7 +106,7 @@ router.delete('/:id/photos/:idx', async (req, res, next) => {
} catch (err) { next(err) }
})
router.patch('/:id/publish', async (req, res, next) => {
router.patch('/:id/publish', requireRole('MANAGER'), async (req, res, next) => {
try {
const { isPublished } = z.object({ isPublished: z.boolean() }).parse(req.body)
await prisma.vehicle.updateMany({ where: { id: req.params.id, companyId: req.companyId }, data: { isPublished } })
@@ -214,7 +215,7 @@ router.get('/:id/calendar', async (req, res, next) => {
} catch (err) { next(err) }
})
router.post('/:id/calendar/blocks', async (req, res, next) => {
router.post('/:id/calendar/blocks', requireRole('MANAGER'), async (req, res, next) => {
try {
const body = z.object({
startDate: z.string().datetime({ offset: true }).or(z.string().regex(/^\d{4}-\d{2}-\d{2}$/)),
@@ -242,7 +243,7 @@ router.post('/:id/calendar/blocks', async (req, res, next) => {
} catch (err) { next(err) }
})
router.delete('/:id/calendar/blocks/:blockId', async (req, res, next) => {
router.delete('/:id/calendar/blocks/:blockId', requireRole('MANAGER'), async (req, res, next) => {
try {
await prisma.vehicle.findFirstOrThrow({ where: { id: req.params.id, companyId: req.companyId } })
await prisma.vehicleCalendarBlock.deleteMany({
@@ -259,7 +260,7 @@ router.get('/:id/maintenance', async (req, res, next) => {
} catch (err) { next(err) }
})
router.post('/:id/maintenance', async (req, res, next) => {
router.post('/:id/maintenance', requireRole('MANAGER'), async (req, res, next) => {
try {
const body = z.object({
type: z.string().min(1),