Actualización CRUD módulo configuración de vehículos
This commit is contained in:
@ -10,55 +10,113 @@ export class VehicleConfigController {
|
||||
req:Request,
|
||||
res:Response
|
||||
){
|
||||
const vehicleConfigs = await vehicleConfigService.getAll();
|
||||
try{
|
||||
const vehicleConfigs = await vehicleConfigService.getAll();
|
||||
|
||||
res.json(vehicleConfigs);
|
||||
res.json(vehicleConfigs);
|
||||
}catch(error){
|
||||
res.status(500).json({
|
||||
message:"Error al obtener configuración de vehículo",
|
||||
error
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async getById(
|
||||
req:Request,
|
||||
res:Response
|
||||
){
|
||||
const vehicleConfig = await vehicleConfigService.getById(
|
||||
req.params.id as string
|
||||
);
|
||||
try{
|
||||
const vehicleConfig = await vehicleConfigService.getById(
|
||||
req.params.id as string
|
||||
);
|
||||
if(!vehicleConfig){
|
||||
return res.status(404).json({
|
||||
message:"Configuración de vehículo no encontrada"
|
||||
});
|
||||
}
|
||||
|
||||
res.json(vehicleConfig);
|
||||
res.json(vehicleConfig);
|
||||
}catch(error){
|
||||
res.status(500).json({
|
||||
message:"Error al obtener configuración de vehículo",
|
||||
error
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async create (
|
||||
req:Request,
|
||||
res:Response
|
||||
){
|
||||
const vehicleConfig = await vehicleConfigService.create(
|
||||
req.body
|
||||
);
|
||||
try{
|
||||
const vehicleConfig = await vehicleConfigService.create(
|
||||
req.body
|
||||
);
|
||||
|
||||
res.status(201).json(vehicleConfig);
|
||||
res.status(201).json(vehicleConfig);
|
||||
|
||||
}catch(error){
|
||||
res.status(500).json({
|
||||
message:"Error al crear configuración de vehículo",
|
||||
error
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async update(
|
||||
req:Request,
|
||||
res:Response
|
||||
){
|
||||
const vehicleConfig = await vehicleConfigService.update(
|
||||
req.params.id as string,
|
||||
req.body
|
||||
);
|
||||
|
||||
res.json(vehicleConfig);
|
||||
try{
|
||||
const vehicleConfig = await vehicleConfigService.update(
|
||||
req.params.id as string,
|
||||
req.body
|
||||
);
|
||||
|
||||
if(!vehicleConfig){
|
||||
return res.status(404).json({
|
||||
message:"Configuración de vehículo no encontrada"
|
||||
})
|
||||
}
|
||||
|
||||
res.status(200).json(vehicleConfig);
|
||||
|
||||
}catch(error){
|
||||
res.status(500).json({
|
||||
message:"Error al actualizar configuración de vehículo",
|
||||
error
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async delete (
|
||||
req:Request,
|
||||
res:Response
|
||||
){
|
||||
const vehicleConfig = await vehicleConfigService.delete(
|
||||
req.params.id as string
|
||||
);
|
||||
try{
|
||||
const vehicleConfig = await vehicleConfigService.delete(
|
||||
req.params.id as string
|
||||
);
|
||||
if(!vehicleConfig){
|
||||
return res.status(404).json({
|
||||
message:"Configuración de vehículo no encontrada"
|
||||
});
|
||||
}
|
||||
|
||||
res.json({
|
||||
messaje:"Configuración de vehículo eliminada"
|
||||
});
|
||||
res.json({
|
||||
message:"Configuración de vehículo eliminada"
|
||||
});
|
||||
|
||||
}catch(error){
|
||||
res.status(500).json({
|
||||
message:"Error al eliminar configuración de vehículo",
|
||||
error
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,7 @@ import mongoose from "mongoose";
|
||||
|
||||
const vehicleConfigSchema = new mongoose.Schema ({
|
||||
|
||||
vehicleid:{
|
||||
vehicleId:{
|
||||
type:Number,
|
||||
required:true,
|
||||
unique:true
|
||||
@ -14,7 +14,7 @@ const vehicleConfigSchema = new mongoose.Schema ({
|
||||
required:true,
|
||||
},
|
||||
|
||||
tankcapacity:{
|
||||
tankCapacity:{
|
||||
type:Number,
|
||||
required:true
|
||||
},
|
||||
|
||||
@ -8,12 +8,12 @@ const controller = new VehicleConfigController();
|
||||
|
||||
vehicleConfigRouter.get("/", authMiddleware, controller.getAll);
|
||||
|
||||
vehicleConfigRouter.get("/id", authMiddleware, controller.getById);
|
||||
vehicleConfigRouter.get("/:id", authMiddleware, controller.getById);
|
||||
|
||||
vehicleConfigRouter.post("/", authMiddleware, controller.create);
|
||||
|
||||
vehicleConfigRouter.put("/id", authMiddleware, controller.update);
|
||||
vehicleConfigRouter.put("/:id", authMiddleware, controller.update);
|
||||
|
||||
vehicleConfigRouter.delete("/id", authMiddleware.apply, controller.delete);
|
||||
vehicleConfigRouter.delete("/:id", authMiddleware, controller.delete);
|
||||
|
||||
export default vehicleConfigRouter;
|
||||
@ -1,4 +1,5 @@
|
||||
import vehiclesConfigModel from "./vehiclesConfig.model";
|
||||
import { IVehicleConfig } from "./vehiclesConfig.interface";
|
||||
|
||||
export class VehicleConfigService {
|
||||
|
||||
@ -19,7 +20,7 @@ export class VehicleConfigService {
|
||||
}
|
||||
|
||||
async create(
|
||||
data:any
|
||||
data:IVehicleConfig
|
||||
){
|
||||
return await vehiclesConfigModel.create(
|
||||
data);
|
||||
@ -27,7 +28,7 @@ export class VehicleConfigService {
|
||||
|
||||
async update(
|
||||
id:string,
|
||||
data:any
|
||||
data:Partial<IVehicleConfig>
|
||||
){
|
||||
return await vehiclesConfigModel.findByIdAndUpdate(
|
||||
id,
|
||||
|
||||
Reference in New Issue
Block a user