-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Legacy Record type, with ability to lookup records from old…
… cubepb
- Loading branch information
Showing
18 changed files
with
705 additions
and
5 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
backend/functions/db/migrations/20211026145209_add_legacy_record_type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
backend/functions/src/schema/models/legacyRecord/rootResolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
backend/functions/src/schema/models/legacyRecord/service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
57
backend/functions/src/schema/models/legacyRecord/typeDef.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.