-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Create Accommodation): Travel admin can create accommodation
- create accommodation controller - create accommodation route - create accommodation models - implement cloudinary and multer for accommodation images - validate controller inputs - write unit and integration test [Maintains #167727749]
- Loading branch information
Showing
18 changed files
with
592 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { config, uploader } from 'cloudinary'; | ||
import './env'; | ||
|
||
const cloudinaryConfig = (req, res, next) => { | ||
config({ | ||
cloud_name: process.env.CLOUDINARY_CLOUD_NAME, | ||
api_key: process.env.CLOUDINARY_API_KEY, | ||
api_secret: process.env.CLOUDINARY_API_SECRET, | ||
}); | ||
next(); | ||
}; | ||
|
||
export { cloudinaryConfig, uploader }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import models from '../models'; | ||
import response from '../utils/response'; | ||
import messages from '../utils/messages'; | ||
import DbServices from '../services/dbServices'; | ||
|
||
const { Accommodation } = models; | ||
const { create } = DbServices; | ||
const { serverError } = messages; | ||
|
||
/** | ||
* travel admin can add accommodation controller | ||
* @param {Object} req - server request | ||
* @param {Object} res - server response | ||
* @returns {Object} - custom response | ||
*/ | ||
const createAccommodation = async (req, res) => { | ||
let images; | ||
try { | ||
const { body } = req; | ||
const { | ||
country, city, address, accommodation, accommodationType, roomType, numOfRooms, | ||
description, facilities | ||
} = body; | ||
|
||
if (req.files) { | ||
images = await req.files.map((image) => ({ url: image.secure_url })); | ||
} | ||
|
||
const createdAccommodation = { | ||
country, | ||
city, | ||
address, | ||
accommodation, | ||
accommodationType, | ||
roomType, | ||
numOfRooms, | ||
description, | ||
facilities, | ||
images, | ||
}; | ||
const accomm = await create(Accommodation, createdAccommodation); | ||
|
||
return response(res, 201, 'success', accomm); | ||
} catch (error) { | ||
return response(res, 500, 'error', { | ||
message: serverError, | ||
}); | ||
} | ||
}; | ||
|
||
export default createAccommodation; |
86 changes: 86 additions & 0 deletions
86
src/database/migrations/20190831223315-create-accommodation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Accommodation', { | ||
id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: Sequelize.UUID | ||
}, | ||
country: { | ||
type: Sequelize.ENUM('Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola', 'Antigua and Barbuda', 'Argentina', | ||
'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', | ||
'Belarus', 'Belgium', 'Belize', 'Benin', 'Bhutan', 'Bolivia', 'Bosnia and Herzegovina', 'Botswana', 'Brazil', | ||
'Brunei', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cabo Verde', 'Cambodia', 'Cameroon', 'Canada', | ||
'Central African Republic (CAR)', 'Chad', 'Chile', 'China', 'Colombia', 'Comoros', 'Congo', 'Democratic Republic of the Congo', 'Republic of the Costa Rica', | ||
'Cote d"Ivoire', 'Croatia', 'Cuba', 'Cyprus', 'Czechia', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', | ||
'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Eswatini', 'Ethiopia', | ||
'Fiji', 'Finland', 'France', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Greece', 'Grenada', 'Guatemala', | ||
'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Honduras', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', | ||
'Iraq', 'Ireland', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Kosovo', | ||
'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libya', 'Liechtenstein', | ||
'Lithuania', 'Luxembourg', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', | ||
'Mauritania', 'Mauritius', 'Mexico', 'Micronesia', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Morocco', | ||
'Mozambique', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'New Zealand', 'Nicaragua', | ||
'Niger', 'Nigeria', 'North Korea', 'North Macedonia', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Palestine', | ||
'Panama', 'Papua New Guinea', 'Paraguay,', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Qatar', | ||
'Romania', 'Russia', 'Rwanda', 'Saint Kitts and Nevis', | ||
'Saint Lucia', 'Saint Vincent and the Grenadines', 'Samoa', 'San Marino', 'Sao Tome and Principe', | ||
'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', | ||
'Solomon Islands', 'Somalia', 'South Africa', 'South Korea', 'South Sudan', 'Spain', 'Sri Lanka', | ||
'Sudan', 'Suriname', 'Sweden', 'Switzerland', 'Syria', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', | ||
'Timor-Leste', 'Togo', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Tuvalu', | ||
'Uganda', 'Ukraine', 'United Arab Emirates (UAE)', 'United Kingdom (UK)', 'United States of America (USA)', 'Uruguay', | ||
'Uzbekistan', 'Vanuatu', 'Vatican City', 'Venezuela', 'Vietnam', 'Yemen', 'Zambia', 'Zimbabwe'), | ||
allowNull: false, | ||
}, | ||
city: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
address: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
accommodation: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
accommodationType: { | ||
type: Sequelize.ARRAY(Sequelize.STRING), | ||
allowNull: false, | ||
}, | ||
roomType: { | ||
type: Sequelize.ARRAY(Sequelize.STRING), | ||
allowNull: false, | ||
}, | ||
numOfRooms: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
}, | ||
description: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
facilities: { | ||
type: Sequelize.ARRAY(Sequelize.STRING), | ||
allowNull: false, | ||
}, | ||
images: { | ||
type: Sequelize.ARRAY(Sequelize.BLOB), | ||
allowNull: true, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('Accommodation'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.bulkInsert('Accommodation', [ | ||
{ | ||
id: '122a0d86-8b78-4bb8-b28f-8e5f7811c452', | ||
country: 'Nigeria', | ||
city: 'Lagos', | ||
accommodation: 'Eko Hotel', | ||
address: '1415 Adetokunbo Ademola Street, Victoria Island, Lagos', | ||
accommodationType: ['Hotel'], | ||
roomType: ['Single', 'Double', 'Executive'], | ||
numOfRooms: 50, | ||
description: 'Eko Hotel is the main building on our property and it houses most of the attractive features which Eko Hotels & Suites has become known for. These include 447 ...', | ||
facilities: ['Free-WIFI', 'Parking', '24/7 Electricity', 'Pool', 'Free breakfast', 'Airport transportation'], | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}, | ||
{ | ||
id: 'fb94de4d-47ff-4079-89e8-b0186c0a3be6', | ||
country: 'Nigeria', | ||
city: 'Lagos', | ||
accommodation: 'Lagos Continental Hotel', | ||
address: 'Plot 52, Kofo Abayomi Street, Victoria Island, Lagos, Nigeria.', | ||
accommodationType: ['Hotel'], | ||
roomType: ['Single', 'Double', 'Executive'], | ||
numOfRooms: 50, | ||
description: 'The Lagos Continental Hotel, is a 5-Star Hotel located at Plot 52A, Kofo Abayomi Street, Victoria Island, within the heart of the central business district of Lagos Nigeria.', | ||
facilities: ['Free-WIFI', 'Parking', '24/7 Electricity'], | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}, { | ||
id: '0ce36391-2c08-4703-bddb-a4ea8cccbbc1', | ||
country: 'Turkey', | ||
city: 'Istanbul', | ||
accommodation: 'Apple Tree Hotel', | ||
address: 'Sultanahmet Mah Akbiyik Cad No:79, Fatih, 34122 Istanbul, Turkey', | ||
accommodationType: ['Hotel'], | ||
roomType: ['Single', 'Double', 'Executive'], | ||
numOfRooms: 50, | ||
description: 'Located in Sultanahmet area, Apple Tree Hotel is just 300 m from Blue Mosque.The hotel offers free WiFi throughout the property. Every room at this hotel is air conditioned and is equipped with a flat-screen TV.', | ||
facilities: ['Free-WIFI', 'Parking', '24/7 Electricity'], | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
} | ||
], {}) | ||
}, | ||
|
||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.bulkDelete('Accommodation', null, {}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import multer from 'multer'; | ||
import storage from '../utils/cloudinaryStorage'; | ||
|
||
const multerUploads = multer({ storage }).array('images', 10); | ||
|
||
export default multerUploads; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
module.exports = (sequelize, DataTypes) => { | ||
const Accommodation = sequelize.define('Accommodation', { | ||
id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: DataTypes.UUID, | ||
defaultValue: DataTypes.UUIDV4, | ||
}, | ||
country: { | ||
type: DataTypes.ENUM, | ||
allowNull: false, | ||
values: ['Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola', 'Antigua and Barbuda', 'Argentina', | ||
'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', | ||
'Belarus', 'Belgium', 'Belize', 'Benin', 'Bhutan', 'Bolivia', 'Bosnia and Herzegovina', 'Botswana', 'Brazil', | ||
'Brunei', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cabo Verde', 'Cambodia', 'Cameroon', 'Canada', | ||
'Central African Republic (CAR)', 'Chad', 'Chile', 'China', 'Colombia', 'Comoros', 'Congo', 'Democratic Republic of the Congo', 'Republic of the Costa Rica', | ||
'Cote d"Ivoire', 'Croatia', 'Cuba', 'Cyprus', 'Czechia', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', | ||
'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Eswatini', 'Ethiopia', | ||
'Fiji', 'Finland', 'France', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Greece', 'Grenada', 'Guatemala', | ||
'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Honduras', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', | ||
'Iraq', 'Ireland', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Kosovo', | ||
'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libya', 'Liechtenstein', | ||
'Lithuania', 'Luxembourg', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', | ||
'Mauritania', 'Mauritius', 'Mexico', 'Micronesia', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Morocco', | ||
'Mozambique', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'New Zealand', 'Nicaragua', | ||
'Niger', 'Nigeria', 'North Korea', 'North Macedonia', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Palestine', | ||
'Panama', 'Papua New Guinea', 'Paraguay,', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Qatar', | ||
'Romania', 'Russia', 'Rwanda', 'Saint Kitts and Nevis', | ||
'Saint Lucia', 'Saint Vincent and the Grenadines', 'Samoa', 'San Marino', 'Sao Tome and Principe', | ||
'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', | ||
'Solomon Islands', 'Somalia', 'South Africa', 'South Korea', 'South Sudan', 'Spain', 'Sri Lanka', | ||
'Sudan', 'Suriname', 'Sweden', 'Switzerland', 'Syria', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', | ||
'Timor-Leste', 'Togo', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Tuvalu', | ||
'Uganda', 'Ukraine', 'United Arab Emirates (UAE)', 'United Kingdom (UK)', 'United States of America (USA)', 'Uruguay', | ||
'Uzbekistan', 'Vanuatu', 'Vatican City', 'Venezuela', 'Vietnam', 'Yemen', 'Zambia', 'Zimbabwe'], | ||
}, | ||
city: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
address: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
accommodation: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
accommodationType: { | ||
type: DataTypes.ARRAY(DataTypes.STRING), | ||
allowNull: false, | ||
}, | ||
roomType: { | ||
type: DataTypes.ARRAY(DataTypes.STRING), | ||
allowNull: false, | ||
}, | ||
numOfRooms: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
}, | ||
description: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
facilities: { | ||
type: DataTypes.ARRAY(DataTypes.STRING), | ||
allowNull: false, | ||
}, | ||
images: { | ||
type: DataTypes.ARRAY(DataTypes.BLOB), | ||
allowNull: true, | ||
} | ||
}); | ||
|
||
return Accommodation; | ||
}; |
Oops, something went wrong.