Adding support for data of entry
This commit is contained in:
@@ -8,7 +8,6 @@ router.get('/', async (req, res) => {
|
||||
const computers = new Computers();
|
||||
await computers.getAll();
|
||||
try {
|
||||
|
||||
res.status(200).json(computers);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Internal Server Error' });
|
||||
@@ -34,10 +33,11 @@ router.get('/:id', async (req, res) => {
|
||||
router.post('/', async (req, res) => {
|
||||
try {
|
||||
const { brand, model, state, status } = req.body;
|
||||
if (!brand || !model || !state || !status) {
|
||||
if ((!brand || brand == "") || (!model || model == "" ) || (!state || state == "" ) || (!status || status == "" )) {
|
||||
res.status(400).json({ error: 'Bad Request' });
|
||||
}
|
||||
const computer = new Computer(null, brand, model, state, status);
|
||||
const dateOfEntry = req.body.dateOfEntry || null;
|
||||
const computer = new Computer(null, brand, model, state, dateOfEntry, status);
|
||||
await computer.create();
|
||||
res.status(201).json({ message: 'Computer created successfully' });
|
||||
} catch (error) {
|
||||
@@ -53,10 +53,11 @@ router.put('/:id', async (req, res) => {
|
||||
if (computer.brand === null) {
|
||||
res.status(404).json({ error: 'Computer not found' });
|
||||
}
|
||||
const { brand, model, state, status } = req.body;
|
||||
const { brand, model, state, dateOfEntry, status } = req.body;
|
||||
computer.brand = brand;
|
||||
computer.model = model;
|
||||
computer.state = state;
|
||||
computer.dateOfEntry = dateOfEntry;
|
||||
computer.status = status;
|
||||
await computer.update();
|
||||
res.status(200).json({ message: 'Computer updated successfully' });
|
||||
|
||||
Reference in New Issue
Block a user