-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparkingController.js
49 lines (47 loc) · 1.33 KB
/
parkingController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { parkCarService, leaveCarService } from '../services/parkingService.js';
export const parkCarController = async (req, res) => {
try {
const { parkingLotId, registrationNumber, color } = req.body;
const parkingInfo = await parkCarService(
parkingLotId,
registrationNumber,
color,
);
res.status(200).json({
isSuccess: true,
response: parkingInfo,
});
} catch (error) {
console.error('Error parking car:', error);
res.status(500).json({
isSuccess: false,
error: {
reason: 'Internal Server Error',
},
});
}
};
export const leaveCarController = async (req, res) => {
try {
const { parkingLotId, registrationNumber } = req.body;
const slotNumber = await leaveCarService(
parkingLotId,
registrationNumber,
);
res.status(200).json({
isSuccess: true,
response: {
slotNumber,
status: 'LEFT',
},
});
} catch (error) {
console.error('Error leaving car:', error);
res.status(500).json({
isSuccess: false,
error: {
reason: 'Internal Server Error',
},
});
}
};