Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict';

var request = require('request');

module.exports = function (grunt) {
// show elapsed time at the end
require('time-grunt')(grunt);
// load all grunt tasks
require('load-grunt-tasks')(grunt);

var reloadPort = 35729, files;

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
develop: {
server: {
file: 'app.js'
}
},
watch: {
options: {
nospawn: true,
livereload: reloadPort
},
js: {
files: [
'app.js',
'app/**/*.js',
'config/*.js'
],
tasks: ['develop', 'delayed-livereload']
},
css: {
files: [
'public/css/*.css'
],
options: {
livereload: reloadPort
}
},
views: {
files: [
'app/views/*.ejs',
'app/views/**/*.ejs'
],
options: { livereload: reloadPort }
}
}
});

grunt.config.requires('watch.js.files');
files = grunt.config('watch.js.files');
files = grunt.file.expand(files);

grunt.registerTask('delayed-livereload', 'Live reload after the node server has restarted.', function () {
var done = this.async();
setTimeout(function () {
request.get('http://localhost:' + reloadPort + '/changed?files=' + files.join(','), function(err, res) {
var reloaded = !err && res.statusCode === 200;
if (reloaded)
grunt.log.ok('Delayed live reload successful.');
else
grunt.log.error('Unable to make a delayed live reload.');
done(reloaded);
});
}, 500);
});

grunt.registerTask('default', [
'develop',
'watch'
]);
};
182 changes: 3 additions & 179 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,180 +1,4 @@
# GSTV BE Coding Exercise
Due to really limited time because of my current job requirements to be on call 24/7. I was only able to make a quick pass at this as I was dealing with a production server deployment for our scoring system. I was able to get the drop down display logic and day of week functionality partially going. You can see that I worked in an MVC pattern with different kinds of environment based configurations for deployments. I also completed the mongoose model structure of the time slot data. And began to leverage it for data save and search. Normally I would do all of this in angular and have useage of more verbs like PUT, DELETE, with JSON responses. But I wanted to get something up and running fast so I just did it old fashion POST style for the DOM creation. There was not enough time to finish the validation and complete the entire workflow but it was heading in the right direction. The drop down hour display logic was a fun challenge and that is in there. There are bugs in the View/Edit Page logic (It's really just incomplete). But at least it gives you an idea of some of my capabilities. I wish I had more time to work on this but I am completely slammed right now. My sincerest apologies and I hope that my attempt at it proves how eager I am to possibly work with you guys.

1. [Exercise Overview](#exercise-overview)
1. [System Requirements](#system-requirements)
1. [Version Control](#version-control)
1. [JavaScript](#javascript)

## Exercise Overview
The site - an individual gas station - is the most atomic piece of the GSTV business model - it is at the core of everything we do. Our hardware is installed at the site, advertisers purchase impressions at a site level and schedules are generated on a per-site basis. Thus, keeping accurate information about a site is essential to maintaining business operations.

We are asking you to build out the ability to create, edit and view hours for a given site. We are focusing on the way you approach the services, and structure the Mongo documents - there is no expectation of a polished UI. **We want you to focus on the server-side aspects of implementing these requirements.**

This data is used to help us know when to turn on and off hardware, how many times a video asset is expected to play and at its most basic level, whether the site is open when we try to call them.

A site may have multiple open and close times for a single day. For example they may be open in the morning, but close mid-afternoon and reopen for the after work rush hour. In many cases stations will be open past midnight, but business owners do not necessarily think of this as the next day.

[Taco Bell](http://s3-media2.fl.yelpcdn.com/bphoto/bzl1SoxoBR-ggedVDlECAA/ls.jpg) is a perfect example of business hours vs. chronological hours - they may be open until 4am on Sunday, but you still think of it as Saturday night.

#### Creating and Editing Hours
Edit & Create Site hours have the same business rules. The main difference is that on edit the dropdowns and values are prepopulated, while in add they are blank.

- Format
- For each day of the week
- Day Label
- Full name
- Each day may have one or many time slots
- For each Time Slot
- Open Time
- Dropdown
- Values are in 30 minute increments
- Values are in AM/PM format
- Values
- Start at Midnight and end 11:30 PM
- Close Time
- Dropdown
- Values are in 30 minute increments
- Values are in AM/PM format
- Values
- Start at 12:30 AM and end at 6:00 AM (next day)
- All values past 11:30 PM (values between Midnight and 6:00 AM) should have the text (next day) at the end
- Remove Button
- Open 24 Hours Button
- Add Button
- Close Button
- Submit Button
- Functionality
- Remove Button
- Removes the selected time slot
- If Open 24 Hours
- Removes Open 24 Hours message
- Displays one empty time slot
- Add Button
- Adds an additional time slot to the selected day
- Open 24 Hours Button
- Removes all the time slots if any exist
- Hides Open 24 Hours Button
- Message
- Open 24 Hours
- Close Button
- User is returned to the spot where they opened the wizard and the view not reflect any changes
- Submit Button
- FE Validates values
- Null Validation
- If a start time is entered a close time is required
- If a close time is entered a start time is required
- Submit fails
- Message
- Unable to Create/Update: {itemName} is required.
- Overlap/Duplicate Validation
- If a timeslot for a given day overlaps any other time slots on the same day
- Submit fails
- Message
- Unable to Create/Update: there is at least one overlapping timeslot
- Time Slot Format Validation
- If the start time falls after the end time
- Message
- Unable to Create/Update: The start time must be before the end time
- If the end time falls before the start time
- Message
- Unable to Create/Update: The start time must be before the end time
- If the start time falls on the end time
- Message
- Unable to Create/Update: The start time may not be the same date as the end time
- If FE validation passes
- Submit changes to the BE
- BE validates values
- Null Validation
- If any required items are null
- Submit fails
- Message
- Unable to Create/Update: {itemName} is required.
- Unchanged Data Validation
- If any required items are null
- Submit fails
- Message
- Unable to Update: {itemName} {itemValue} has not been changed.
- Duplicate Validation
- If any required items are null
- Submit fails
- Message
- Unable to Create/Update: {itemName} {itemValue} already exists.
- Malformed Data Validation
- If any required items are null
- Submit fails
- Message
- Unable to Create/Update: {itemName} {itemValue} does not match the expected format.
- Time Slot Format Validation
- If the start time falls after the end time
- Message
- Unable to Create/Update: The start time must be before the end time
- If the end time falls before the start time
- Message
- Unable to Create/Update: The start time must be before the end time
- If the start time falls on the end time
- Message
- Unable to Create/Update: The start time may not be the same date as the end time
- If BE validation passes
- Update Data
- User is returned to the spot where they opened the wizard and the view will reflect changes from the wizard.

#### Viewing Hours
- Format
- Normal State
- For current date/time
- Open or Closed
- Rules
- If current date and time is within a defined open period, then Open
- If current date and time is not within a defined open period, then Closed
- For each day
- Day Label
- Full name
- If not Open 24 hours
- For each time slot
- Open Time
- Close Time
- If Open 24 hours
- Message
- Open 24 hours
- If Hours are Null
- Message
- Closed
- Edit Site Hours Button
- Empty State
- Message
- There are no site hours for {Site ID}.
- Create Site Hours Button
- Functionality
- Edit Site Hours Button
- Links to Creating/Editing Hours
- Create Site Hours Button
- Links to Creating/Editing Hours

#### Extra Credit
##### Future Date/Time Open or Closed
Our field operations team often goes to sites for maintenance or upgrades. While creating their schedules it would be helpful to know if a site will be open on a given date and time in the future.

##### Timezones
GSTV has sites across the US. People from the Detroit main office may be calling sites in California. For that reason it is important to know the open times based upon a given timezone.

##### Daylight Savings Time
GSTV has sites in Arizona. Arizona does not participate in daylight savings time. For that reason it is important to know the open times based upon a site’s participation in daylight savings.

## System Requirements
* Node.js `^4.0.0`
* MongoDB `^3.0.0`

## Version Control
### GitFlow and GithubFlow
We use [GitFlow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow/) on a daily basis - this allows us to build quality control into our development, QA and deployment process.

We are asking that you use a modified [Github Flow](https://guides.github.com/introduction/flow/) - sometimes referred to as a [feature branch workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow) - methodology instead of GitFlow. Conceptually, GitFlow and Github flow are similar.

Please fork our repository and use a feature branch workflow while developing your functionality. When you are ready to submit your work make a [pull request against our repository](https://help.github.com/articles/using-pull-requests/).

## JavaScript
### Standards
We have a work in progress [style guide](https://github.com/davezuko/gstv-javascript-standards) that you can refer to. We don't expect you to strictly adhere to these standards, but they may help provide insight into how our JavaScript is generally structured.

### Unit Testing
Please feel free to create unit tests - we use [Mocha](https://github.com/mochajs/mocha).
All the best,
Robert Rudas
25 changes: 25 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


var express = require('express'),
config = require('./config/config'),
glob = require('glob'),
mongoose = require('mongoose');

mongoose.connect(config.db);
var db = mongoose.connection;
db.on('error', function () {
throw new Error('unable to connect to database at ' + config.db);
});

var models = glob.sync(config.root + '/app/models/*.js');
models.forEach(function (model) {
require(model);
});
var app = express();

require('./config/express')(app, config);

app.listen(config.port, function () {
console.log('Express server listening on port ' + config.port);
});

Loading