69 lines
2.5 KiB
JavaScript
69 lines
2.5 KiB
JavaScript
const ROOM_TYPES = {
|
|
economy: { id: 'Эконом', name: 'Эконом', pricePerGuest: 2500 },
|
|
standard: { id: 'Стандарт', name: 'Стандарт', pricePerGuest: 4000 },
|
|
vip: { id: 'VIP Люкс', name: 'VIP Люкс', pricePerGuest: 8000 }
|
|
};
|
|
|
|
const BOOKING_STATUSES = {
|
|
NEW: 'новая',
|
|
PAID: 'оплачена',
|
|
RESERVED: 'зарезервирована',
|
|
CHECKED_IN: 'заселена',
|
|
CHECKED_OUT: 'выехала',
|
|
CANCELLED: 'отменена'
|
|
};
|
|
|
|
const DEFAULT_ROOMS = [
|
|
{ type: ROOM_TYPES.economy.id, name: 'Эконом 1', description: 'Бюджетный номер', rooms_count: 3, single_beds: 2, double_beds: 0, has_sofa: 0, has_ac: 0, has_wifi: 1, has_shower: 1, max_guests: 2, price_per_guest: ROOM_TYPES.economy.pricePerGuest },
|
|
{ type: ROOM_TYPES.standard.id, name: 'Стандарт 1', description: 'Комфортный номер', rooms_count: 2, single_beds: 0, double_beds: 1, has_sofa: 1, has_ac: 1, has_wifi: 1, has_shower: 1, max_guests: 3, price_per_guest: ROOM_TYPES.standard.pricePerGuest },
|
|
{ type: ROOM_TYPES.vip.id, name: 'VIP Люкс 1', description: 'Премиум номер', rooms_count: 1, single_beds: 0, double_beds: 1, has_sofa: 1, has_ac: 1, has_wifi: 1, has_shower: 1, max_guests: 4, price_per_guest: ROOM_TYPES.vip.pricePerGuest }
|
|
];
|
|
|
|
const ROOM_PRICES = {
|
|
[ROOM_TYPES.economy.id]: ROOM_TYPES.economy.pricePerGuest,
|
|
[ROOM_TYPES.standard.id]: ROOM_TYPES.standard.pricePerGuest,
|
|
[ROOM_TYPES.vip.id]: ROOM_TYPES.vip.pricePerGuest
|
|
};
|
|
|
|
const STATUS_LIST = [
|
|
BOOKING_STATUSES.NEW,
|
|
BOOKING_STATUSES.PAID,
|
|
BOOKING_STATUSES.RESERVED,
|
|
BOOKING_STATUSES.CHECKED_IN,
|
|
BOOKING_STATUSES.CHECKED_OUT,
|
|
BOOKING_STATUSES.CANCELLED
|
|
];
|
|
|
|
const ROOM_TYPE_LIST = [
|
|
ROOM_TYPES.economy.id,
|
|
ROOM_TYPES.standard.id,
|
|
ROOM_TYPES.vip.id
|
|
];
|
|
|
|
function getRoomPrice(roomType) {
|
|
return ROOM_PRICES[roomType] || 0;
|
|
}
|
|
|
|
function calculateNights(checkin, checkout) {
|
|
const ci = new Date(checkin);
|
|
const co = new Date(checkout);
|
|
return Math.ceil((co - ci) / (1000 * 60 * 60 * 24));
|
|
}
|
|
|
|
function calculateBasePrice(roomType, checkin, checkout) {
|
|
const pricePerNight = getRoomPrice(roomType);
|
|
const nights = calculateNights(checkin, checkout);
|
|
return pricePerNight * nights;
|
|
}
|
|
|
|
module.exports = {
|
|
ROOM_TYPES,
|
|
BOOKING_STATUSES,
|
|
DEFAULT_ROOMS,
|
|
ROOM_PRICES,
|
|
STATUS_LIST,
|
|
ROOM_TYPE_LIST,
|
|
getRoomPrice,
|
|
calculateNights,
|
|
calculateBasePrice
|
|
}; |