fix and update language for company workspace
This commit is contained in:
@@ -28,6 +28,7 @@ const vehicleSchema = z.object({
|
||||
mileage: z.number().int().optional(),
|
||||
notes: z.string().optional(),
|
||||
isPublished: z.boolean().default(true),
|
||||
status: z.enum(['AVAILABLE', 'RENTED', 'MAINTENANCE', 'OUT_OF_SERVICE']).optional(),
|
||||
})
|
||||
|
||||
router.get('/', async (req, res, next) => {
|
||||
@@ -65,9 +66,14 @@ router.get('/:id', async (req, res, next) => {
|
||||
router.patch('/:id', async (req, res, next) => {
|
||||
try {
|
||||
const body = vehicleSchema.partial().parse(req.body)
|
||||
const vehicle = await prisma.vehicle.updateMany({ where: { id: req.params.id, companyId: req.companyId }, data: body })
|
||||
if (vehicle.count === 0) return res.status(404).json({ error: 'not_found', message: 'Vehicle not found', statusCode: 404 })
|
||||
const updated = await prisma.vehicle.findUniqueOrThrow({ where: { id: req.params.id } })
|
||||
if (body.status === 'MAINTENANCE' || body.status === 'OUT_OF_SERVICE') {
|
||||
body.isPublished = false
|
||||
} else if (body.status === 'AVAILABLE' || body.status === 'RENTED') {
|
||||
body.isPublished = true
|
||||
}
|
||||
const existing = await prisma.vehicle.findFirst({ where: { id: req.params.id, companyId: req.companyId } })
|
||||
if (!existing) return res.status(404).json({ error: 'not_found', message: 'Vehicle not found', statusCode: 404 })
|
||||
const updated = await prisma.vehicle.update({ where: { id: req.params.id }, data: body })
|
||||
res.json({ data: updated })
|
||||
} catch (err) { next(err) }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user