Skip to content

Commit

Permalink
Add basic frontend. Polish backend
Browse files Browse the repository at this point in the history
  • Loading branch information
theCrius committed Sep 29, 2017
1 parent f9a3f67 commit 1c82f82
Show file tree
Hide file tree
Showing 29 changed files with 798 additions and 133 deletions.
1 change: 1 addition & 0 deletions .env.sample → .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ db_host=localhost
db_database=hostManager
db_user=root
db_password=toor
seed=15276b3c-3e4c-41c4-a03f-65ea5148e12a

port=4000
17 changes: 7 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/dist
/logs
/npm-debug.log
/node_modules
/public/node_modules
/public/app/bower_components/*
!/public/app/bower_components/app.css
npm-debug.log
logs/*
!.gitkeep
node_modules/
bower_components/
tmp
.DS_Store
.env
knexfile.js
constants.js
.idea
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,21 @@ HostManager

Simple application to manage property details.

I used a simple bootstrap/angularJS as frontend but you can easile replace it with whatever float your boat.
I used a simple bootstrap/angularJS as frontend but you can easily replace it with whatever float your boat.
Be sure that port 4000 is being kept free for this application to work.

Requirements
---------------

You need an up-to-date node, npm, bower and mysql.
You need an up-to-date node, npm, bower, and mysql.

Getting Started
---------------

Begin setting up the configswer

```sh
cp db/knexfile.sample.js db/knexfile.js
cp .env.sample .env
cp public/constants.sample.js public/constants.js
```

Be sure that the values inside those files match your development environment.

```sh
knex migrate:latest --knexfile=db/knexfile.js
npm install
cd public; npm install; cd ..
cd public; npm install; grunt build; cd ..
```

Finally run node to start the application:
Expand Down
23 changes: 15 additions & 8 deletions controllers/apiController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const Promise = require('bluebird');
const async = require('async');
const _ = require('lodash');
const moment = require('moment');

const Bookshelf = require('../db/bookshelf');
const Properties = require('../models/properties');
Expand Down Expand Up @@ -33,17 +34,17 @@ function view(req, res, next) {
//Just create a new property using a transaction
function create(req, res, next) {
const uuid = require('uuid/v5');
let addressPayload = req.body.Addresses[0]; delete req.body.Addresses;
let propertyPayload = req.body;
Bookshelf.transaction((t) => {
req.body.property.uuid = uuid(req.body.property.id+req.body.property.owner, process.env.seed);
return new Properties(req.body.property)
req.body.uuid = uuid(req.body.owner+req.body.incomeGenerated, process.env.seed);
return new Properties(propertyPayload)
.save(null, {transacting: t})
.tap((property) => {
return new Addresses(req.body.address).save({'property_id': property.id}, {transacting: t});
return new Addresses(addressPayload).save({'property_id': property.id}, {transacting: t});
});
}).then((property) => {
Properties.where({id:property.id}).fetch({withRelated: ['Addresses']})
.then((data) => { res.send(data) })
.catch((err) => { next(err) })
res.send(property)
}).catch(function(err) {
next(err);
});
Expand All @@ -52,11 +53,17 @@ function create(req, res, next) {
//Create a new entry for the property with the updated info, using the same uuid
function update(req, res, next) {
const uuid = require('uuid/v5');
let addressPayload = req.body.Addresses[0];
delete addressPayload.created_at;
addressPayload.updated_at = moment().format("YYYY-MM-DD HH:mm:ss");
let propertyPayload = req.body;
delete propertyPayload.Addresses; delete propertyPayload.created_at;
propertyPayload.updated_at = moment().format("YYYY-MM-DD HH:mm:ss");
Bookshelf.transaction((t) => {
return new Properties(req.body.property)
return new Properties(propertyPayload)
.save(null, {transacting: t})
.tap((property) => {
return new Addresses(req.body.address).save({'property_id': property.id}, {transacting: t});
return new Addresses(addressPayload).save({'property_id': property.id}, {transacting: t});
});
}).then((property) => {
Properties.where({id:property.id}).fetch({withRelated: ['Addresses']})
Expand Down
17 changes: 17 additions & 0 deletions db/knexfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
client: 'mysql',
connection: {
host: 'localhost',
database: 'hostManager',
user: 'root',
password: 'toor'
},
pool: {
min: 1,
max: 5
},
migrations: {
tableName: 'knex_migrations',
directory: './migrations'
}
};
20 changes: 0 additions & 20 deletions db/knexfile.sample.js

This file was deleted.

6 changes: 3 additions & 3 deletions db/migrations/20170928114841_create_properties_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ exports.up = function(knex, Promise) {
.then(function () {
const seed = '15276b3c-3e4c-41c4-a03f-65ea5148e12a';
const properties_pool = [
{"id": 1, "uuid": uuid('1carlos', seed), "owner": "carlos", "airbnbId": 3512500, "numberOfBedrooms": 1, "numberOfBathrooms": 1, "incomeGenerated": 2000.34},
{"id": 2, "uuid": uuid('2ankur', seed), "owner": "ankur", "airbnbId": 1334159, "numberOfBedrooms": 3, "numberOfBathrooms": 1, "incomeGenerated": 10000},
{"id": 3, "uuid": uuid('3elaine', seed), "owner": "elaine", "airbnbId": 12220057, "numberOfBedrooms": 2, "numberOfBathrooms": 2, "incomeGenerated": 1200}
{"id": 1, "uuid": uuid('carlos3512500', seed), "owner": "carlos", "airbnbId": 3512500, "numberOfBedrooms": 1, "numberOfBathrooms": 1, "incomeGenerated": 2000.34},
{"id": 2, "uuid": uuid('ankur1334159', seed), "owner": "ankur", "airbnbId": 1334159, "numberOfBedrooms": 3, "numberOfBathrooms": 1, "incomeGenerated": 10000},
{"id": 3, "uuid": uuid('elaine12220057', seed), "owner": "elaine", "airbnbId": 12220057, "numberOfBedrooms": 2, "numberOfBathrooms": 2, "incomeGenerated": 1200}
];
knex.insert(properties_pool).into('properties')
.finally(() => { knex.destroy() });
Expand Down
2 changes: 1 addition & 1 deletion db/schemas/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = {
airbnbId: {type: 'integer', unsigned: true, nullable: false},
numberOfBedrooms: {type: 'integer', unsigned: true, nullable: false},
numberOfBathrooms: {type: 'integer', unsigned: true, nullable: false},
incomeGenerated: {type: 'decimal', precision: 8, scale: 2, unsigned: true, nullable: false},
incomeGenerated: {type: 'double', unsigned: true, nullable: false},
deletedAt: {type: 'dateTime', nullable: true}
};
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ app.use(bodyParser.json());

const apiRouter = require('./routes/router')(app);
app.use('/assets', express.static(path.join(__dirname, '/public/app/bower_components/')));
app.use('/', express.static(path.join(__dirname, '/public/app/')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname + '/public/app/index.html'));
})
Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
"cors": "^2.7.1",
"dotenv": "^4.0.0",
"express": "^4.13.3",
"grunt-angular-boilerplate": "^1.0.0",
"knex": "^0.13.0",
"lodash": "^4.17.4",
"moment": "^2.18.1",
"mysql": "^2.14.1",
"uuid": "^3.1.0",
"widget-knex-schema": "^1.1.0"
Expand Down
Loading

0 comments on commit 1c82f82

Please sign in to comment.