Skip to content

Commit

Permalink
Add frontend and backend directories and boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
big213 committed Feb 26, 2021
1 parent c420afb commit b3f62cb
Show file tree
Hide file tree
Showing 159 changed files with 30,615 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
frontend/types/*.ts
5 changes: 5 additions & 0 deletions backend/.firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "cubepb-65c9e"
}
}
70 changes: 70 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
firebase-debug.*.log*

# Firebase cache
.firebase/

# Firebase config

# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# dotenv environment variables file
.deploy_info
env.json
22 changes: 22 additions & 0 deletions backend/env.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"mysql": {
"password": "PASSWORD",
"host": "HOST",
"user": "USER",
"database": "DATABASE",
"port": "PORT"
"socketpath": "SOCKETPATH"
},
"pusher": {
"key": "PUSHER_KEY",
"cluster": "CLUSTER",
"app_id": "APP_ID",
"secret": "SECRET"
},
"wca": {
"base_url": "https://staging.worldcubeassociation.org/",
"client_secret": "example-secret",
"client_id": "example-application-id",
"redirect_uri": "http://localhost:3000/wca-redirect"
}
}
16 changes: 16 additions & 0 deletions backend/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
},
"emulators": {
"functions": {
"port": 5001
},
"ui": {
"enabled": true
}
}
}
13 changes: 13 additions & 0 deletions backend/functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
parser: "@typescript-eslint/parser",
extends: [
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended",
],
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
},
rules: {},
};
9 changes: 9 additions & 0 deletions backend/functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Compiled JavaScript files
lib/**/*.js
lib/**/*.js.map

# TypeScript v1 declaration files
typings/

# Node.js dependency directory
node_modules/
73 changes: 73 additions & 0 deletions backend/functions/db/migrations/20210224123833_migration_name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import * as Knex from "knex";

export async function up(knex: Knex): Promise<void[]> {
return Promise.all([
knex.schema.createTable("user", function (table) {
table.increments();
table.string("provider").notNullable();
table.string("provider_id").notNullable();
table.string("wca_id").nullable();
table.string("email").notNullable().unique();
table.string("name").notNullable();
table.string("avatar").nullable();
table.string("country").nullable();
table.boolean("is_public").notNullable().defaultTo(true);
table.integer("role").notNullable().defaultTo(1);
table.json("permissions").nullable();
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
table.unique(["provider", "provider_id"]);
}),
knex.schema.createTable("event", function (table) {
table.increments();
table.string("name").notNullable();
table.string("code").notNullable().unique();
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
}),
knex.schema.createTable("product", function (table) {
table.increments();
table.string("name").notNullable();
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
}),
knex.schema.createTable("personalBestClass", function (table) {
table.increments();
table.string("name").notNullable();
table.text("description").nullable();
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
}),
knex.schema.createTable("personalBest", function (table) {
table.increments();
table.integer("pb_class").notNullable();
table.integer("event").notNullable();
table.integer("set_size").notNullable();
table.integer("score").notNullable();
table.integer("attempts_succeeded").notNullable().defaultTo(1);
table.integer("attempts_total").notNullable().defaultTo(1);
table.integer("product").nullable();
table.date("happened_on").notNullable();
table.integer("time_elapsed").notNullable();
table.boolean("show_ms").notNullable().defaultTo(false);
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
table.unique(["pb_class", "event", "set_size"]);
}),
]);
}

export async function down(knex: Knex): Promise<void[]> {
return Promise.all([
knex.schema.dropTable("user"),
knex.schema.dropTable("event"),
knex.schema.dropTable("product"),
knex.schema.dropTable("personalBestClass"),
knex.schema.dropTable("personalBest"),
]);
}
24 changes: 24 additions & 0 deletions backend/functions/db/seeds/initialize_users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as Knex from "knex";

export async function seed(knex: Knex): Promise<void> {
// Deletes ALL existing entries
await knex("user").del();

// Inserts seed entries
await knex("user").insert([
{
provider: "wca",
provider_id: "277",
wca_id: "2008VIRO01",
email: "[email protected]",
name: "Philippe Virouleau",
avatar:
"https://staging.worldcubeassociation.org/uploads/user/avatar/2008VIRO01/1473886131.jpg",
country: "FR",
is_public: true,
role: "3",
permissions: null,
created_by: 0,
},
]);
}
40 changes: 40 additions & 0 deletions backend/functions/knexfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
export const env = require("../env.json");

export const production = {
client: "pg",
connection: {
host: env.pg.host,
user: env.pg.user,
password: env.pg.password,
database: env.pg.database,
...(env.pg.port && { port: env.pg.port }),
},
pool: { min: 0, max: 1 },
migrations: {
tableName: "knex_migrations",
directory: "./db/migrations",
},
seeds: {
directory: "./db/seeds",
},
};

export const development = {
client: "pg",
connection: {
host: env.pg_dev.host,
user: env.pg_dev.user,
password: env.pg_dev.password,
database: env.pg_dev.database,
...(env.pg_dev.port && { port: env.pg_dev.port }),
},
pool: { min: 0, max: 1 },
migrations: {
tableName: "knex_migrations",
directory: "./db/migrations",
},
seeds: {
directory: "./db/seeds",
},
};
73 changes: 73 additions & 0 deletions backend/functions/migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import * as Knex from "knex";

export async function up(knex: Knex): Promise<void[]> {
return Promise.all([
knex.schema.createTable("user", function (table) {
table.increments();
table.string("provider").notNullable();
table.string("provider_id").notNullable();
table.string("wca_id").nullable();
table.string("email").notNullable().unique();
table.string("name").notNullable();
table.string("avatar").nullable();
table.string("country").nullable();
table.boolean("is_public").notNullable().defaultTo(true);
table.integer("role").notNullable().defaultTo(1);
table.json("permissions").nullable();
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
table.unique(["provider", "provider_id"]);
}),
knex.schema.createTable("event", function (table) {
table.increments();
table.string("name").notNullable();
table.string("code").notNullable().unique();
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
}),
knex.schema.createTable("product", function (table) {
table.increments();
table.string("name").notNullable();
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
}),
knex.schema.createTable("personalBestClass", function (table) {
table.increments();
table.string("name").notNullable();
table.text("description").nullable();
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
}),
knex.schema.createTable("personalBest", function (table) {
table.increments();
table.integer("pb_class").notNullable();
table.integer("event").notNullable();
table.integer("set_size").notNullable();
table.integer("score").notNullable();
table.integer("attempts_succeeded").notNullable().defaultTo(1);
table.integer("attempts_total").notNullable().defaultTo(1);
table.integer("product").nullable();
table.date("happened_on").notNullable();
table.integer("time_elapsed").notNullable();
table.boolean("show_ms").notNullable().defaultTo(false);
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
table.unique(["pb_class", "event", "set_size"]);
}),
]);
}

export async function down(knex: Knex): Promise<void[]> {
return Promise.all([
knex.schema.dropTable("user"),
knex.schema.dropTable("event"),
knex.schema.dropTable("product"),
knex.schema.dropTable("personalBestClass"),
knex.schema.dropTable("personalBest"),
]);
}
Loading

0 comments on commit b3f62cb

Please sign in to comment.