Skip to content

Commit

Permalink
Resolve #20: Add support for sub-events
Browse files Browse the repository at this point in the history
  • Loading branch information
big213 committed May 22, 2021
1 parent 5c56f44 commit dce1a42
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as Knex from "knex";

export async function up(knex: Knex): Promise<void> {
return knex.schema.alterTable("event", function (t) {
t.boolean("is_sub_event").notNullable().defaultTo(false);
});
}

export async function down(knex: Knex): Promise<void> {
return knex.schema.alterTable("event", function (t) {
t.dropColumn("is_sub_event");
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as Knex from "knex";

export async function up(knex: Knex): Promise<void> {
return knex.schema.alterTable("event", function (t) {
t.boolean("is_wca_event").notNullable().defaultTo(false);
});
}

export async function down(knex: Knex): Promise<void> {
return knex.schema.alterTable("event", function (t) {
t.dropColumn("is_wca_event");
});
}
102 changes: 92 additions & 10 deletions backend/functions/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,101 @@ import * as Knex from "knex";

export async function up(knex: Knex): Promise<void[]> {
return Promise.all([
knex.schema.createTable("userUserFollowLink", function (table) { table.increments();table.integer("user").notNullable();table.integer("target").notNullable();table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());table.dateTime("updated_at").nullable();table.integer("created_by").notNullable();table.unique(["user","target"]); }),
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.boolean("is_featured").notNullable().defaultTo(false);table.integer("role").notNullable().defaultTo(2);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.text("description").nullable();table.string("code").notNullable().unique();table.string("cubing_icon").nullable();table.string("score_method").notNullable();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.integer("set_size").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").nullable();table.integer("attempts_total").nullable();table.integer("product").nullable();table.dateTime("happened_on").notNullable().defaultTo(knex.fn.now());table.integer("time_elapsed").nullable();table.decimal("moves_count").nullable();table.boolean("is_current").notNullable();table.text("public_comments").nullable();table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());table.dateTime("updated_at").nullable();table.integer("created_by").notNullable(); }),
knex.schema.createTable("apiKey", function (table) { table.increments();table.string("name").notNullable();table.string("code").notNullable().unique();table.integer("user").notNullable();table.json("permissions").nullable();table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());table.dateTime("updated_at").nullable();table.integer("created_by").notNullable(); }),

])
knex.schema.createTable("userUserFollowLink", function (table) {
table.increments();
table.integer("user").notNullable();
table.integer("target").notNullable();
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
table.unique(["user", "target"]);
}),
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.boolean("is_featured").notNullable().defaultTo(false);
table.integer("role").notNullable().defaultTo(2);
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.text("description").nullable();
table.string("code").notNullable().unique();
table.string("cubing_icon").nullable();
table.string("score_method").notNullable();
table.boolean("is_sub_event").notNullable().defaultTo(false);
table.boolean("is_wca_event").notNullable().defaultTo(false);
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.integer("set_size").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").nullable();
table.integer("attempts_total").nullable();
table.integer("product").nullable();
table.dateTime("happened_on").notNullable().defaultTo(knex.fn.now());
table.integer("time_elapsed").nullable();
table.decimal("moves_count").nullable();
table.boolean("is_current").notNullable();
table.text("public_comments").nullable();
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
}),
knex.schema.createTable("apiKey", function (table) {
table.increments();
table.string("name").notNullable();
table.string("code").notNullable().unique();
table.integer("user").notNullable();
table.json("permissions").nullable();
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
}),
]);
}

export async function down(knex: Knex): Promise<void[]> {
return Promise.all([
knex.schema.dropTable("userUserFollowLink"),knex.schema.dropTable("user"),knex.schema.dropTable("event"),knex.schema.dropTable("product"),knex.schema.dropTable("personalBestClass"),knex.schema.dropTable("personalBest"),knex.schema.dropTable("apiKey")
knex.schema.dropTable("userUserFollowLink"),
knex.schema.dropTable("user"),
knex.schema.dropTable("event"),
knex.schema.dropTable("product"),
knex.schema.dropTable("personalBestClass"),
knex.schema.dropTable("personalBest"),
knex.schema.dropTable("apiKey"),
]);
}
6 changes: 6 additions & 0 deletions backend/functions/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,17 @@ export type FilterByField<T> = {
code: Scalars["string"];
cubingIcon?: Scalars["string"] | null;
scoreMethod: Scalars["scoreMethod"];
isSubEvent?: Scalars["boolean"];
isWcaEvent?: Scalars["boolean"];
};
updateEventFields: {
name?: Scalars["string"];
description?: Scalars["string"] | null;
code?: Scalars["string"];
cubingIcon?: Scalars["string"] | null;
scoreMethod?: Scalars["scoreMethod"];
isSubEvent?: Scalars["boolean"];
isWcaEvent?: Scalars["boolean"];
};
updateEvent: {
item: InputTypes["event"];
Expand Down Expand Up @@ -629,6 +633,8 @@ export type UserUserFollowLinkEdge = Edge<UserUserFollowLink>;
code: { Type: Scalars["string"]; Args: undefined };
cubingIcon: { Type: Scalars["string"] | null; Args: undefined };
scoreMethod: { Type: Scalars["scoreMethod"]; Args: undefined };
isSubEvent: { Type: Scalars["boolean"]; Args: undefined };
isWcaEvent: { Type: Scalars["boolean"]; Args: undefined };
/**When the record was created*/ createdAt: {
Type: Scalars["unixTimestamp"];
Args: undefined;
Expand Down
15 changes: 15 additions & 0 deletions backend/functions/src/schema/models/event/typeDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
generateTypenameField,
generateEnumField,
generateTextField,
generateBooleanField,
} from "../../core/helpers/typeDef";
import * as Scalars from "../../scalars";

Expand Down Expand Up @@ -37,6 +38,20 @@ export default new GiraffeqlObjectType(<ObjectTypeDefinition>{
allowNull: false,
sqlOptions: { field: "score_method" },
}),
isSubEvent: generateBooleanField({
allowNull: false,
defaultValue: false,
sqlOptions: {
field: "is_sub_event",
},
}),
isWcaEvent: generateBooleanField({
allowNull: false,
defaultValue: false,
sqlOptions: {
field: "is_wca_event",
},
}),
...generateCreatedAtField(),
...generateUpdatedAtField(),
...generateCreatedByField(User),
Expand Down
24 changes: 22 additions & 2 deletions frontend/components/table/common/eventColumn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
<template v-slot:activator="{ on }">
<v-chip pill small v-on="on">
<v-avatar left>
<span class="cubing-icon" :class="currentValue.cubingIcon"></span>
<span
v-if="currentValue.cubingIcon"
class="cubing-icon"
:class="currentValue.cubingIcon"
></span>
<v-icon v-else>mdi-square-medium</v-icon>
</v-avatar>
{{ currentValue.name }}
</v-chip>
Expand All @@ -21,7 +26,12 @@
<v-list>
<v-list-item>
<v-list-item-avatar>
<span class="cubing-icon" :class="currentValue.cubingIcon"></span>
<span
v-if="currentValue.cubingIcon"
class="cubing-icon"
:class="currentValue.cubingIcon"
></span>
<v-icon v-else>mdi-square-medium</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<template>
Expand All @@ -35,6 +45,14 @@
>Score Method:
{{ currentEvent.scoreMethod }}</v-list-item-subtitle
>
<v-list-item-subtitle>
<v-chip v-if="currentEvent.isSubEvent" small
>Sub-Event</v-chip
>
<v-chip v-if="currentEvent.isWcaEvent" small
>WCA Event</v-chip
>
</v-list-item-subtitle>
</template>
</template>
</v-list-item-content>
Expand Down Expand Up @@ -93,6 +111,8 @@ export default {
getEvent: {
description: true,
scoreMethod: true,
isSubEvent: true,
isWcaEvent: true,
__args: {
id: this.currentValue.id,
},
Expand Down
42 changes: 39 additions & 3 deletions frontend/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ export const Event = <RecordInfo<'event'>>{
getOptions: getScoreMethods,
inputType: 'select',
},
isSubEvent: {
text: 'Sub Event',
inputType: 'switch',
parseQueryValue: (val) => val === 'true',
},
isWcaEvent: {
text: 'WCA Event',
inputType: 'switch',
parseQueryValue: (val) => val === 'true',
},
createdAt: {
text: 'Created At',
component: TimeagoColumn,
Expand All @@ -57,6 +67,16 @@ export const Event = <RecordInfo<'event'>>{
field: 'name+code',
sortable: true,
},
{
field: 'isSubEvent',
sortable: false,
width: '150px',
},
{
field: 'isWcaEvent',
sortable: false,
width: '150px',
},
{
field: 'scoreMethod',
sortable: false,
Expand Down Expand Up @@ -86,13 +106,29 @@ export const Event = <RecordInfo<'event'>>{
downloadOptions: {},
},
addOptions: {
fields: ['name', 'description', 'code', 'cubingIcon', 'scoreMethod'],
fields: [
'name',
'description',
'code',
'cubingIcon',
'scoreMethod',
'isSubEvent',
'isWcaEvent',
],
},
editOptions: {
fields: ['name', 'description', 'code', 'cubingIcon'],
fields: ['name', 'description', 'code', 'cubingIcon', 'isWcaEvent'],
},
viewOptions: {
fields: ['name', 'description', 'code', 'cubingIcon', 'scoreMethod'],
fields: [
'name',
'description',
'code',
'cubingIcon',
'scoreMethod',
'isSubEvent',
'isWcaEvent',
],
},
deleteOptions: {},
shareOptions: undefined,
Expand Down
6 changes: 3 additions & 3 deletions frontend/models/personalBest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const PersonalBest = <RecordInfo<'personalBest'>>{
'event.cubingIcon': {
text: 'Event Icon',
},
'event.name+event.cubingIcon': {
'event.id+event.name+event.cubingIcon': {
text: 'Event',
compoundOptions: {
pathPrefix: 'event',
Expand Down Expand Up @@ -293,7 +293,7 @@ export const PersonalBest = <RecordInfo<'personalBest'>>{
],
headers: [
{
field: 'event.name+event.cubingIcon',
field: 'event.id+event.name+event.cubingIcon',
width: '200px',
},
{
Expand Down Expand Up @@ -355,7 +355,7 @@ export const PersonalBest = <RecordInfo<'personalBest'>>{
},
viewOptions: {
fields: [
'event.name+event.cubingIcon',
'event.id+event.name+event.cubingIcon',
'pbClass.name+setSize',
'score+timeElapsed+movesCount+attemptsSucceeded+attemptsTotal+event.scoreMethod',
'ranking',
Expand Down
6 changes: 6 additions & 0 deletions frontend/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,17 @@ export type FilterByField<T> = {
code: Scalars['string']
cubingIcon?: Scalars['string'] | null
scoreMethod: Scalars['scoreMethod']
isSubEvent?: Scalars['boolean']
isWcaEvent?: Scalars['boolean']
}
updateEventFields: {
name?: Scalars['string']
description?: Scalars['string'] | null
code?: Scalars['string']
cubingIcon?: Scalars['string'] | null
scoreMethod?: Scalars['scoreMethod']
isSubEvent?: Scalars['boolean']
isWcaEvent?: Scalars['boolean']
}
updateEvent: {
item: InputTypes['event']
Expand Down Expand Up @@ -624,6 +628,8 @@ export type UserUserFollowLinkEdge = Edge<UserUserFollowLink>
code: { Type: Scalars['string']; Args: undefined }
cubingIcon: { Type: Scalars['string'] | null; Args: undefined }
scoreMethod: { Type: Scalars['scoreMethod']; Args: undefined }
isSubEvent: { Type: Scalars['boolean']; Args: undefined }
isWcaEvent: { Type: Scalars['boolean']; Args: undefined }
/**When the record was created*/ createdAt: {
Type: Scalars['unixTimestamp']
Args: undefined
Expand Down

0 comments on commit dce1a42

Please sign in to comment.