Skip to content

Commit e4ff7a2

Browse files
committed
feat: add project, resource, payment schema
1 parent 73f1663 commit e4ff7a2

17 files changed

+163
-45
lines changed

src/common/QueryRunner.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export interface JoinClause {
3737

3838
export interface WhereClause {
3939
where(whereCriteria: {
40-
key: string,
41-
operator: Operator,
42-
value: Value
40+
key: string;
41+
operator: Operator;
42+
value: Value;
4343
}): JoinAndWhereClause & LimitClause & OffsetClause;
4444
}
4545

@@ -56,16 +56,23 @@ export interface InsertQuery<CreateInput> {
5656
}
5757

5858
export interface UpdateQuery<UpdateInput> {
59-
update(lookupCriteria: {[key: string]: unknown} ,input: UpdateInput): ExecuteSqlQuery;
59+
update(lookupCriteria: { [key: string]: unknown }, input: UpdateInput): ExecuteSqlQuery;
6060
}
6161

6262
export interface DeleteQuery {
6363
delete(): ExecuteSqlQuery;
6464
}
6565

66-
export class QueryRunner<T, CreateInput extends {[key: string]: unknown}, UpdateInput extends {[key: string]: unknown}>
67-
implements
68-
SelectQuery, JoinClause, WhereClause, LimitClause, OffsetClause,
66+
export class QueryRunner<
67+
T,
68+
CreateInput extends { [key: string]: unknown },
69+
UpdateInput extends { [key: string]: unknown }
70+
> implements
71+
SelectQuery,
72+
JoinClause,
73+
WhereClause,
74+
LimitClause,
75+
OffsetClause,
6976
InsertQuery<CreateInput>,
7077
UpdateQuery<UpdateInput>,
7178
DeleteQuery,
@@ -85,7 +92,7 @@ export class QueryRunner<T, CreateInput extends {[key: string]: unknown}, Update
8592
column: columns.map((col) => ({
8693
tableName: this.schema.tableName,
8794
name: col.name,
88-
type: col.type
95+
type: col.type,
8996
})),
9097
where: [],
9198
join: [],
@@ -101,9 +108,9 @@ export class QueryRunner<T, CreateInput extends {[key: string]: unknown}, Update
101108

102109
// TODO: use "convenience" methods from lib-util to build the clause
103110
where(whereCriteria: {
104-
key: string,
105-
operator: Operator,
106-
value: Value
111+
key: string;
112+
operator: Operator;
113+
value: Value;
107114
}): JoinAndWhereClause & LimitClause & OffsetClause {
108115
if (this.#query?.query?.$case != "select") {
109116
throw new Error("Cannot set where clause on a non-select query");
@@ -119,15 +126,15 @@ export class QueryRunner<T, CreateInput extends {[key: string]: unknown}, Update
119126
}
120127

121128
limit(limit: number): OffsetClause & ExecuteSqlQuery {
122-
if (this.#query?.query?.$case != "select") {
129+
if (this.#query?.query?.$case != "select") {
123130
throw new Error("Cannot set limit on a non-select query");
124131
}
125132
this.#query.query.select.limit = limit;
126133
return this;
127134
}
128135

129136
offset(offset: number): ExecuteSqlQuery {
130-
if (this.#query?.query?.$case != "select") {
137+
if (this.#query?.query?.$case != "select") {
131138
throw new Error("Cannot set offset on a non-select query");
132139
}
133140
this.#query.query.select.offset = offset;

src/domain/LegacyChallenge.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import _ from "lodash";
21
import { QueryRunner } from "../common/QueryRunner";
3-
4-
import { relationalClient } from "../grpc/client/relational";
5-
import { ColumnType, Operator, QueryRequest, QueryResponse } from "../grpc/models/rdb/relational";
2+
import { ColumnType, Operator, QueryRequest } from "../grpc/models/rdb/relational";
63
import { CheckChallengeExistsResponse } from "../models/domain-layer/legacy/legacy_challenge";
74
import { Value } from "../models/google/protobuf/struct";
8-
import { Project } from "../schema/Project";
5+
import { Project } from "../schema/project/Project";
96

107
class LegacyChallengeDomain {
118
constructor(private tableName: string = "project") {}

src/domain/LegacyChallengePhase.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import _ from "lodash";
22

3-
import {
4-
PhaseTypeList,
5-
} from "../models/domain-layer/legacy/legacy_challenge_phase";
3+
import { PhaseTypeList } from "../models/domain-layer/legacy/legacy_challenge_phase";
64

75
import { QueryRunner } from "../common/QueryRunner";
86
import { Value } from "../grpc/models/rdb/relational";
97

10-
import { ProjectPhaseSchema } from "../schema/ProjectPhase";
11-
import { PhaseType } from "../schema/PhaseType";
8+
import { ProjectPhaseSchema } from "../schema/project/ProjectPhase";
9+
import { PhaseType } from "../schema/project/PhaseType";
1210
import {
1311
CreatePhaseInput,
1412
CreateResult,
@@ -22,14 +20,16 @@ class LegacyChallengePhaseDomain {
2220
modifyUser: 22838965, // tcwebservice | TODO: Get using grpc interceptor
2321
};
2422

25-
const phaseId = (await new QueryRunner(ProjectPhaseSchema).insert(createInput).exec()) as number;
23+
const phaseId = (await new QueryRunner(ProjectPhaseSchema)
24+
.insert(createInput)
25+
.exec()) as number;
2626

2727
return {
2828
kind: {
2929
$case: "integerId",
30-
integerId: phaseId
31-
}
32-
}
30+
integerId: phaseId,
31+
},
32+
};
3333
}
3434

3535
public async getPhaseTypes(): Promise<PhaseTypeList> {

src/schema/PhaseType.ts renamed to src/schema/project/PhaseType.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Schema } from "../common/QueryRunner";
2-
import { ColumnType } from "../../dist/grpc/models/rdb/relational";
3-
import { AuditColumns } from "./common/AuditColumns";
1+
import { Schema } from "../../common/QueryRunner";
2+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational";
3+
import { AuditColumns } from "../common/AuditColumns";
44

55
export const PhaseType: Schema = {
66
dbSchema: "tcs_catalog",

src/schema/Project.ts renamed to src/schema/project/Project.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Schema } from "../common/QueryRunner";
2-
import { ColumnType } from "../grpc/models/rdb/relational";
3-
import { AuditColumns } from "./common/AuditColumns";
1+
import { Schema } from "../../common/QueryRunner";
2+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational";
3+
import { AuditColumns } from "../common/AuditColumns";
44

55
export const Project: Schema = {
66
dbSchema: "tcs_catalog",

src/schema/ProjectPhase.ts renamed to src/schema/project/ProjectPhase.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Schema } from "../common/QueryRunner";
2-
import { ColumnType } from "../grpc/models/rdb/relational";
3-
import { AuditColumns } from "./common/AuditColumns";
1+
import { Schema } from "../../common/QueryRunner";
2+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational";
3+
import { AuditColumns } from "../common/AuditColumns";
44

55
export const ProjectPhaseSchema: Schema = {
66
dbSchema: "tcs_catalog",

src/schema/ProjectStatus.ts renamed to src/schema/project/ProjectStatus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Schema } from "../common/QueryRunner.js";
2-
import { ColumnType } from "../grpc/models/rdb/relational.js";
3-
import { AuditColumns } from "./common/AuditColumns";
1+
import { Schema } from "../../common/QueryRunner.js";
2+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational.js";
3+
import { AuditColumns } from "../common/AuditColumns";
44

55
export const ProjectStatus: Schema = {
66
dbSchema: "tcs_catalog",

src/schema/Prize.ts renamed to src/schema/project_payment/Prize.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Schema } from "../common/QueryRunner";
2-
import { ColumnType } from "../grpc/models/rdb/relational";
3-
import { AuditColumns } from "./common/AuditColumns";
1+
import { Schema } from "../../common/QueryRunner";
2+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational";
3+
import { AuditColumns } from "../common/AuditColumns";
44

55
export const Prize: Schema = {
66
dbSchema: "tcs_catalog",
@@ -10,7 +10,7 @@ export const Prize: Schema = {
1010
prizeId: { name: "prize_id", type: ColumnType.COLUMN_TYPE_INT },
1111
project_id: { name: "project_id", type: ColumnType.COLUMN_TYPE_INT },
1212
prizeTypeId: { name: "prize_type_id", type: ColumnType.COLUMN_TYPE_INT },
13-
prizeAmount: { name: "prize_amount", type: ColumnType.COLUMN_TYPE_INT },
13+
prizeAmount: { name: "prize_amount", type: ColumnType.COLUMN_TYPE_FLOAT },
1414
numberOfSubmissions: { name: "number_of_submissions", type: ColumnType.COLUMN_TYPE_INT },
1515
...AuditColumns,
1616
},

src/schema/PrizeType.ts renamed to src/schema/project_payment/PrizeType.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Schema } from "../common/QueryRunner";
2-
import { ColumnType } from "../grpc/models/rdb/relational";
1+
import { Schema } from "../../common/QueryRunner";
2+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational";
33

44
export const PrizeType: Schema = {
55
dbSchema: "tcs_catalog",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational";
2+
import { Schema } from "../../common/QueryRunner";
3+
import { AuditColumns } from "../common/AuditColumns";
4+
5+
export const ProjectPayment: Schema = {
6+
dbSchema: "tcs_catalog",
7+
tableName: "project_payment",
8+
columns: {
9+
place: { name: "place", type: ColumnType.COLUMN_TYPE_INT },
10+
prizeId: { name: "prize_id", type: ColumnType.COLUMN_TYPE_INT },
11+
project_id: { name: "project_id", type: ColumnType.COLUMN_TYPE_INT },
12+
prizeTypeId: { name: "prize_type_id", type: ColumnType.COLUMN_TYPE_INT },
13+
prizeAmount: { name: "prize_amount", type: ColumnType.COLUMN_TYPE_FLOAT },
14+
...AuditColumns,
15+
},
16+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational";
2+
import { Schema } from "../../common/QueryRunner";
3+
4+
export const ProjectPaymentAdjustment: Schema = {
5+
dbSchema: "tcs_catalog",
6+
tableName: "project_payment_adjustment",
7+
columns: {
8+
projectId: { name: "project_id", type: ColumnType.COLUMN_TYPE_INT },
9+
resourceRoleId: { name: "resource_role_id", type: ColumnType.COLUMN_TYPE_INT },
10+
fixedAmount: { name: "fixed_amount", type: ColumnType.COLUMN_TYPE_FLOAT },
11+
multiplier: { name: "multiplier", type: ColumnType.COLUMN_TYPE_INT },
12+
},
13+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational";
2+
import { Schema } from "../../common/QueryRunner";
3+
4+
export const ProjectPaymentAdjustment: Schema = {
5+
dbSchema: "tcs_catalog",
6+
tableName: "project_payment_type_lu",
7+
columns: {
8+
projectPaymentTypeId: { name: "project_payment_type_id", type: ColumnType.COLUMN_TYPE_INT },
9+
name: { name: "name", type: ColumnType.COLUMN_TYPE_STRING },
10+
mergeable: { name: "mergeable", type: ColumnType.COLUMN_TYPE_BOOLEAN },
11+
pactsPaymentTypeId: { name: "pacts_payment_type_id", type: ColumnType.COLUMN_TYPE_INT },
12+
},
13+
};

src/schema/resource/Resource.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Schema } from "../../common/QueryRunner.js";
2+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational.js";
3+
import { AuditColumns } from "../common/AuditColumns";
4+
5+
export const Resource: Schema = {
6+
dbSchema: "tcs_catalog",
7+
tableName: "resource",
8+
columns: {
9+
resourceId: { name: "resource_id", type: ColumnType.COLUMN_TYPE_INT },
10+
resourceRoleId: { name: "resource_role_id", type: ColumnType.COLUMN_TYPE_INT },
11+
projectId: { name: "project_id", type: ColumnType.COLUMN_TYPE_INT },
12+
projectPhaseId: { name: "project_phase_id", type: ColumnType.COLUMN_TYPE_INT },
13+
userId: { name: "user_id", type: ColumnType.COLUMN_TYPE_INT },
14+
...AuditColumns,
15+
},
16+
};

src/schema/resource/ResourceInfo.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Schema } from "../../common/QueryRunner.js";
2+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational.js";
3+
import { AuditColumns } from "../common/AuditColumns";
4+
5+
export const Resource: Schema = {
6+
dbSchema: "tcs_catalog",
7+
tableName: "resource_info",
8+
columns: {
9+
resourceId: { name: "resource_id", type: ColumnType.COLUMN_TYPE_INT },
10+
resourceInfoTypeId: { name: "resource_info_type_id", type: ColumnType.COLUMN_TYPE_INT },
11+
value: { name: "value", type: ColumnType.COLUMN_TYPE_STRING },
12+
...AuditColumns,
13+
},
14+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Schema } from "../../common/QueryRunner.js";
2+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational.js";
3+
import { AuditColumns } from "../common/AuditColumns";
4+
5+
export const Resource: Schema = {
6+
dbSchema: "tcs_catalog",
7+
tableName: "resource_info_type_lu",
8+
columns: {
9+
resourceInfoTypeId: { name: "resource_info_type_id", type: ColumnType.COLUMN_TYPE_INT },
10+
name: { name: "name", type: ColumnType.COLUMN_TYPE_STRING },
11+
description: { name: "description", type: ColumnType.COLUMN_TYPE_STRING },
12+
...AuditColumns,
13+
},
14+
};

src/schema/resource/ResourceRole.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Schema } from "../../common/QueryRunner.js";
2+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational.js";
3+
import { AuditColumns } from "../common/AuditColumns";
4+
5+
export const Resource: Schema = {
6+
dbSchema: "tcs_catalog",
7+
tableName: "resource_role_lu",
8+
columns: {
9+
resourceRoleId: { name: "resource_role_id", type: ColumnType.COLUMN_TYPE_INT },
10+
phaseTypeId: { name: "phase_type_id", type: ColumnType.COLUMN_TYPE_INT },
11+
name: { name: "name", type: ColumnType.COLUMN_TYPE_STRING },
12+
description: { name: "description", type: ColumnType.COLUMN_TYPE_STRING },
13+
...AuditColumns,
14+
},
15+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Schema } from "../../common/QueryRunner.js";
2+
import { ColumnType } from "../../../dist/grpc/models/rdb/relational.js";
3+
import { AuditColumns } from "../common/AuditColumns";
4+
5+
export const Resource: Schema = {
6+
dbSchema: "tcs_catalog",
7+
tableName: "resource_submission",
8+
columns: {
9+
resourceId: { name: "resource_id", type: ColumnType.COLUMN_TYPE_INT },
10+
submissionId: { name: "submission_id", type: ColumnType.COLUMN_TYPE_INT },
11+
...AuditColumns,
12+
},
13+
};

0 commit comments

Comments
 (0)