Skip to content

Commit

Permalink
Implement Legacy Record type, with ability to lookup records from old…
Browse files Browse the repository at this point in the history
… cubepb
  • Loading branch information
big213 committed Oct 26, 2021
1 parent 15970a8 commit 7869f1b
Show file tree
Hide file tree
Showing 18 changed files with 705 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as Knex from "knex";

export async function up(knex: Knex): Promise<void> {
return knex.schema.createTable("legacyRecord", function (table) {
table.increments();
table.string("wca_event_id").nullable();
table.integer("record_type").notNullable();
table.integer("number_of_solves").notNullable();
table.integer("result").notNullable();
table.string("other_event_name").nullable();
table.string("main_cube").nullable();
table.integer("event_type").notNullable();
table.dateTime("date").nullable();
table.string("email").notNullable();
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 knex.schema.dropTable("legacyRecord");
}
16 changes: 16 additions & 0 deletions backend/functions/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ export async function up(knex: Knex): Promise<void[]> {
table.dateTime("updated_at").nullable();
table.integer("created_by").notNullable();
}),
knex.schema.createTable("legacyRecord", function (table) {
table.increments();
table.string("wca_event_id").nullable();
table.integer("record_type").notNullable();
table.integer("number_of_solves").notNullable();
table.integer("result").notNullable();
table.string("other_event_name").nullable();
table.string("main_cube").nullable();
table.integer("event_type").notNullable();
table.dateTime("date").nullable();
table.string("email").notNullable();
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();
Expand All @@ -98,6 +113,7 @@ export async function down(knex: Knex): Promise<void[]> {
knex.schema.dropTable("product"),
knex.schema.dropTable("personalBestClass"),
knex.schema.dropTable("personalBest"),
knex.schema.dropTable("legacyRecord"),
knex.schema.dropTable("apiKey"),
]);
}
102 changes: 102 additions & 0 deletions backend/functions/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ export type FilterByField<T> = {
| "happenedOn"
| "isCurrent";
personalBestGroupByKey: undefined;
legacyRecordSortByKey: "id";
legacyRecordGroupByKey: undefined;
apiKeySortByKey: "id" | "createdAt";
apiKeyGroupByKey: undefined;
userUserFollowLinkSortByKey: "createdAt";
Expand Down Expand Up @@ -356,6 +358,49 @@ export type FilterByField<T> = {
fields: InputTypes["updatePersonalBestFields"];
};
flagPersonalBest: { item: InputTypes["personalBest"] };
legacyRecord: { id?: Scalars["id"] };
"legacyRecordFilterByField/id": FilterByField<Scalars["id"]>;
"legacyRecordFilterByField/email": FilterByField<Scalars["string"]>;
legacyRecordFilterByObject: {
id?: InputTypes["legacyRecordFilterByField/id"];
email?: InputTypes["legacyRecordFilterByField/email"];
};
legacyRecordPaginator: {
first?: Scalars["number"];
last?: Scalars["number"];
after?: Scalars["string"];
before?: Scalars["string"];
sortBy?: Scalars["legacyRecordSortByKey"][];
sortDesc?: Scalars["boolean"][];
filterBy?: InputTypes["legacyRecordFilterByObject"][];
groupBy?: Scalars["legacyRecordGroupByKey"][];
};
createLegacyRecord: {
wcaEventId?: Scalars["string"] | null;
recordType: Scalars["number"];
numberOfSolves: Scalars["number"];
result: Scalars["number"];
otherEventName?: Scalars["string"] | null;
mainCube?: Scalars["string"] | null;
eventType: Scalars["number"];
date?: Scalars["unixTimestamp"] | null;
email: Scalars["string"];
};
updateLegacyRecordFields: {
wcaEventId?: Scalars["string"] | null;
recordType?: Scalars["number"];
numberOfSolves?: Scalars["number"];
result?: Scalars["number"];
otherEventName?: Scalars["string"] | null;
mainCube?: Scalars["string"] | null;
eventType?: Scalars["number"];
date?: Scalars["unixTimestamp"] | null;
email?: Scalars["string"];
};
updateLegacyRecord: {
item: InputTypes["legacyRecord"];
fields: InputTypes["updateLegacyRecordFields"];
};
apiKey: { id?: Scalars["id"] };
"apiKeyFilterByField/id": FilterByField<Scalars["id"]>;
"apiKeyFilterByField/user.id": FilterByField<Scalars["id"]>;
Expand Down Expand Up @@ -439,6 +484,14 @@ export type FilterByField<T> = {
Typename: "personalBestPaginator";
Type: GetType<PersonalBestPaginator>;
};
legacyRecordEdge: {
Typename: "legacyRecordEdge";
Type: GetType<LegacyRecordEdge>;
};
legacyRecordPaginator: {
Typename: "legacyRecordPaginator";
Type: GetType<LegacyRecordPaginator>;
};
apiKeyEdge: { Typename: "apiKeyEdge"; Type: GetType<ApiKeyEdge> };
apiKeyPaginator: {
Typename: "apiKeyPaginator";
Expand Down Expand Up @@ -473,6 +526,7 @@ export type FilterByField<T> = {
Type: GetType<PersonalBestClass>;
};
personalBest: { Typename: "personalBest"; Type: GetType<PersonalBest> };
legacyRecord: { Typename: "legacyRecord"; Type: GetType<LegacyRecord> };
apiKey: { Typename: "apiKey"; Type: GetType<ApiKey> };
};
/**PaginatorInfo Type*/ export type PaginatorInfo = {
Expand Down Expand Up @@ -530,6 +584,15 @@ export type PersonalBestEdge = Edge<PersonalBest>;
paginatorInfo: { Type: PaginatorInfo; Args: undefined };
edges: { Type: PersonalBestEdge[]; Args: undefined };
};
export type LegacyRecordEdge = Edge<LegacyRecord>;
/**Paginator*/ export type LegacyRecordPaginator = {
/**The typename of the record*/ __typename: {
Type: Scalars["string"];
Args: [Scalars["number"]];
};
paginatorInfo: { Type: PaginatorInfo; Args: undefined };
edges: { Type: LegacyRecordEdge[]; Args: undefined };
};
export type ApiKeyEdge = Edge<ApiKey>;
/**Paginator*/ export type ApiKeyPaginator = {
/**The typename of the record*/ __typename: {
Expand Down Expand Up @@ -724,6 +787,31 @@ export type UserUserFollowLinkEdge = Edge<UserUserFollowLink>;
};
createdBy: { Type: User; Args: undefined };
};
/**Legacy Record*/ export type LegacyRecord = {
/**The unique ID of the field*/ id: { Type: Scalars["id"]; Args: undefined };
/**The typename of the record*/ __typename: {
Type: Scalars["string"];
Args: [Scalars["number"]];
};
wcaEventId: { Type: Scalars["string"] | null; Args: undefined };
recordType: { Type: Scalars["number"]; Args: undefined };
numberOfSolves: { Type: Scalars["number"]; Args: undefined };
result: { Type: Scalars["number"]; Args: undefined };
otherEventName: { Type: Scalars["string"] | null; Args: undefined };
mainCube: { Type: Scalars["string"] | null; Args: undefined };
eventType: { Type: Scalars["number"]; Args: undefined };
date: { Type: Scalars["unixTimestamp"] | null; Args: undefined };
email: { Type: Scalars["string"]; Args: undefined };
/**When the record was created*/ createdAt: {
Type: Scalars["unixTimestamp"];
Args: undefined;
};
/**When the record was last updated*/ updatedAt: {
Type: Scalars["unixTimestamp"] | null;
Args: undefined;
};
createdBy: { Type: User; Args: undefined };
};
/**API Key Type*/ export type ApiKey = {
/**The unique ID of the field*/ id: { Type: Scalars["id"]; Args: undefined };
/**The typename of the record*/ __typename: {
Expand Down Expand Up @@ -811,6 +899,20 @@ export type UserUserFollowLinkEdge = Edge<UserUserFollowLink>;
Type: PersonalBest;
Args: InputTypes["flagPersonalBest"];
};
getLegacyRecord: { Type: LegacyRecord; Args: InputTypes["legacyRecord"] };
getLegacyRecordPaginator: {
Type: LegacyRecordPaginator;
Args: InputTypes["legacyRecordPaginator"];
};
deleteLegacyRecord: { Type: LegacyRecord; Args: InputTypes["legacyRecord"] };
createLegacyRecord: {
Type: LegacyRecord;
Args: InputTypes["createLegacyRecord"];
};
updateLegacyRecord: {
Type: LegacyRecord;
Args: InputTypes["updateLegacyRecord"];
};
getApiKey: { Type: ApiKey; Args: InputTypes["apiKey"] };
getApiKeyPaginator: {
Type: ApiKeyPaginator;
Expand Down
4 changes: 4 additions & 0 deletions backend/functions/src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import event from "./models/event/typeDef";
import product from "./models/product/typeDef";
import personalBestClass from "./models/personalBestClass/typeDef";
import personalBest from "./models/personalBest/typeDef";
import legacyRecord from "./models/legacyRecord/typeDef";
import apiKey from "./models/apiKey/typeDef";

// add the typeDefs for the services with typeDefs
Expand All @@ -17,6 +18,7 @@ allServices.Event.setTypeDef(event);
allServices.Product.setTypeDef(product);
allServices.PersonalBestClass.setTypeDef(personalBestClass);
allServices.PersonalBest.setTypeDef(personalBest);
allServices.LegacyRecord.setTypeDef(legacyRecord);
allServices.ApiKey.setTypeDef(apiKey);

import User from "./models/user/rootResolver";
Expand All @@ -25,6 +27,7 @@ import Event from "./models/event/rootResolver";
import Product from "./models/product/rootResolver";
import PersonalBestClass from "./models/personalBestClass/rootResolver";
import PersonalBest from "./models/personalBest/rootResolver";
import LegacyRecord from "./models/legacyRecord/rootResolver";
import ApiKey from "./models/apiKey/rootResolver";
import Github from "./models/github/rootResolver";
import UserUserFollowLink from "./links/userUserFollowLink/rootResolver";
Expand All @@ -35,6 +38,7 @@ allServices.Event.setRootResolvers(Event);
allServices.Product.setRootResolvers(Product);
allServices.PersonalBestClass.setRootResolvers(PersonalBestClass);
allServices.PersonalBest.setRootResolvers(PersonalBest);
allServices.LegacyRecord.setRootResolvers(LegacyRecord);
allServices.ApiKey.setRootResolvers(ApiKey);
allServices.Github.setRootResolvers(Github);

Expand Down
12 changes: 12 additions & 0 deletions backend/functions/src/schema/models/legacyRecord/rootResolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { LegacyRecord } from "../../services";
import { generateBaseRootResolvers } from "../../core/helpers/rootResolver";

export default {
...generateBaseRootResolvers(LegacyRecord, [
"get",
"getMultiple",
"delete",
"create",
"update",
]),
};
45 changes: 45 additions & 0 deletions backend/functions/src/schema/models/legacyRecord/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { PaginatedService } from "../../core/services";
import { AccessControlMap, ServiceFunctionInputs } from "../../../types";

export class LegacyRecordService extends PaginatedService {
defaultTypename = "legacyRecord";

filterFieldsMap = {
id: {},
email: {},
};

uniqueKeyMap = {
primary: ["id"],
};

sortFieldsMap = {
id: {},
};

searchFieldsMap = {};

groupByFieldsMap = {};

accessControl: AccessControlMap = {
/*
Allow if:
- Email is not a requested field
*/
get: async ({ query }) => {
if (query.email) return false;

return true;
},

/*
Allow if:
- Email is not a requested field
*/
getMultiple: ({ query }) => {
if (query.email) return false;

return true;
},
};
}
57 changes: 57 additions & 0 deletions backend/functions/src/schema/models/legacyRecord/typeDef.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { LegacyRecord, User } from "../../services";
import { GiraffeqlObjectType, ObjectTypeDefinition } from "giraffeql";
import {
generateIdField,
generateCreatedAtField,
generateUpdatedAtField,
generateTypenameField,
generateIntegerField,
generateUnixTimestampField,
generateCreatedByField,
generateStringField,
} from "../../core/helpers/typeDef";

export default new GiraffeqlObjectType(<ObjectTypeDefinition>{
name: LegacyRecord.typename,
description: "Legacy Record",
fields: {
...generateIdField(),
...generateTypenameField(LegacyRecord),
wcaEventId: generateStringField({
allowNull: true,
sqlOptions: { field: "wca_event_id" },
}),
recordType: generateIntegerField({
allowNull: false,
sqlOptions: { field: "record_type" },
}),
numberOfSolves: generateIntegerField({
allowNull: false,
sqlOptions: { field: "number_of_solves" },
}),
result: generateIntegerField({
allowNull: false,
}),
otherEventName: generateStringField({
allowNull: true,
sqlOptions: { field: "other_event_name" },
}),
mainCube: generateStringField({
allowNull: true,
sqlOptions: { field: "main_cube" },
}),
eventType: generateIntegerField({
allowNull: false,
sqlOptions: { field: "event_type" },
}),
date: generateUnixTimestampField({
allowNull: true,
}),
email: generateStringField({
allowNull: false,
}),
...generateCreatedAtField(),
...generateUpdatedAtField(),
...generateCreatedByField(User),
},
});
2 changes: 2 additions & 0 deletions backend/functions/src/schema/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { EventService } from "./models/event/service";
import { ProductService } from "./models/product/service";
import { PersonalBestClassService } from "./models/personalBestClass/service";
import { PersonalBestService } from "./models/personalBest/service";
import { LegacyRecordService } from "./models/legacyRecord/service";
import { GithubService } from "./models/github/service";
import { ApiKeyService } from "./models/apiKey/service";

Expand All @@ -18,6 +19,7 @@ export const Product = new ProductService();
export const Auth = new AuthService();
export const PersonalBestClass = new PersonalBestClassService();
export const PersonalBest = new PersonalBestService();
export const LegacyRecord = new LegacyRecordService();
export const ApiKey = new ApiKeyService();
export const Github = new GithubService();

Expand Down
2 changes: 1 addition & 1 deletion backend/functions/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export type ServiceFunctionInputs = {
req: Request;
fieldPath: string[];
args: any;
query?: unknown;
query?: any;
data?: any;
isAdmin?: boolean;
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/menu/recordActionMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</v-list-item-title>
</v-list-item>
<v-list-item
v-if="recordInfo.shareOptions && !hideView"
v-if="recordInfo.viewOptions && !hideView"
key="view"
@click="openEditDialog('view')"
>
Expand Down
Loading

0 comments on commit 7869f1b

Please sign in to comment.