added backend implementation
This commit is contained in:
114
backend/controller/customers.js
Normal file
114
backend/controller/customers.js
Normal file
@ -0,0 +1,114 @@
|
||||
//import functions from customers model
|
||||
import {
|
||||
getCustomers,
|
||||
getSelectedCustomers,
|
||||
getCustomerByProductionOrderId,
|
||||
getCustomerByMaintenanceVisitId,
|
||||
insertCustomer,
|
||||
getCustomerByCustomerId,
|
||||
getCustomerByName,
|
||||
updateCustomerById,
|
||||
deleteCustomerById,
|
||||
} from "../models/customerModel.js";
|
||||
|
||||
//get all customers
|
||||
export const showCustomers = (req, res) => {
|
||||
getCustomers((err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//create new customer
|
||||
export const createCustomer = (req, res) => {
|
||||
const data = req.body;
|
||||
insertCustomer(data, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//get all selected customers
|
||||
export const showSelectedCustomers = (req, res) => {
|
||||
getSelectedCustomers(req.params.id, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//get single customer by production order id
|
||||
export const showCustomerByProductionOrderId = (req, res) => {
|
||||
getCustomerByProductionOrderId(req.params.id, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//get single customer by maintenance visit id
|
||||
export const showCustomerByMaintenanceVisitId = (req, res) => {
|
||||
getCustomerByMaintenanceVisitId(req.params.id, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//get single customer by customer id
|
||||
export const showCustomerByCustomerId = (req, res) => {
|
||||
getCustomerByCustomerId(req.params.id, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//get single customer by name
|
||||
export const showCustomerByName = (req, res) => {
|
||||
getCustomerByName(req.params.id, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Update customer
|
||||
export const updateCustomer = (req, res) => {
|
||||
const data = req.body;
|
||||
updateCustomerById(data, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Delete customer
|
||||
export const deleteCustomer = (req, res) => {
|
||||
const id = req.params.id;
|
||||
deleteCustomerById(id, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user