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
6 changes: 6 additions & 0 deletions super_team_picker/db/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const config = require("../knexfile.js");
const knex = require("knex");

const connection = knex(config["development"]);

module.exports = connection;
23 changes: 23 additions & 0 deletions super_team_picker/db/migrations/20220224014855_CreateCohorts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/

exports.up = function(knex) {
return knex.schema.createTable('cohorts', table => {
table.increments('id');
table.text('members');
table.string('name');
table.string('logoUrl');
table.timestamp('createdAt').defaultTo(knex.fn.now());
})
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function(knex) {
return knex.schema.dropTable('cohorts');

};
18 changes: 18 additions & 0 deletions super_team_picker/db/seeds/CreateCohorts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const faker = require('faker')
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.seed = async function(knex) {
// Deletes ALL existing entries
await knex('cohorts').del()
const cohorts = Array.from({length:10}).map(() => {
return {
'name': faker.name.jobTitle(),
'members': faker.lorem.words(faker.datatype.number({ min: 15, max: 25 })).split(" ").join(", "),
'logoUrl': faker.image.abstract(50, 50, true)
}

})
await knex('cohorts').insert(cohorts);
};
36 changes: 36 additions & 0 deletions super_team_picker/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const express = require("express");
const app = express();
const methodOverride = require("method-override");
const logger = require("morgan");
const cohortsRouter = require("./routes/cohorts");
const path = require("path");

app.use(logger("dev"));

app.use(express.static(path.join(__dirname, "public")));
app.use(express.urlencoded({ extended: true }));

app.use(
methodOverride((req, res) => {
if (req.body && req.body._method) {
const method = req.body._method;
return method;
}
})
);

app.set("view engine", "ejs");
app.set("views", "views");

app.get("/", (request, response) => {
response.redirect("/cohorts");
});

app.use("/cohorts", cohortsRouter);

const PORT = 3000;
const DOMAIN = "localhost";

app.listen(PORT, DOMAIN, () => {
console.log(`Server is listening on http://${DOMAIN}:${PORT}`);
});
24 changes: 24 additions & 0 deletions super_team_picker/knexfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Update with your config settings.

/**
* @type { Object.<string, import("knex").Knex.Config> }
*/
module.exports = {

development: {
client: 'postgresql',
connection: {
database: 'super_team_picker',
username: 'abe',
password: 'BmP$S5%M'
},

migrations: {
tableName: "migrations",
directory: 'db/migrations'
},
seeds: {
directory: "db/seeds"
}
}
};
Loading