Skip to content

Commit 64a946d

Browse files
committed
feat(submission): wip- legacy submission
1 parent 22e6a04 commit 64a946d

37 files changed

+10775
-393
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"license": "ISC",
1717
"dependencies": {
1818
"@grpc/grpc-js": "^1.7.1",
19-
"@topcoder-framework/client-relational": "^0.4.24-ci.0",
20-
"@topcoder-framework/lib-common": "^0.4.24-ci.0",
19+
"@topcoder-framework/client-relational": "^0.5.1-ci.0",
20+
"@topcoder-framework/lib-common": "^0.5.1-ci.0",
2121
"dayjs": "^1.11.5",
2222
"dotenv": "^16.0.3",
2323
"grpc-server-reflection": "^0.1.5",
@@ -37,4 +37,4 @@
3737
"node": "18.13.0",
3838
"yarn": "1.22.19"
3939
}
40-
}
40+
}

src/config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as dotenv from "dotenv";
2+
import assert from "assert";
3+
dotenv.config();
4+
5+
export const ENV = <string>process.env.ENV || "local";
6+
export const GRPC_SERVER_HOST = process.env.GRPC_SERVER_HOST || "";
7+
export const GRPC_SERVER_PORT = process.env.GRPC_SERVER_PORT || 9091;
8+
9+
export const GRPC_RDB_SERVER_HOST = process.env.GRPC_RDB_SERVER_HOST;
10+
export const GRPC_RDB_SERVER_PORT = process.env.GRPC_RDB_SERVER_PORT;
11+
12+
assert(GRPC_RDB_SERVER_HOST, "GRPC_RDB_SERVER_HOST is required");
13+
assert(GRPC_RDB_SERVER_PORT, "GRPC_RDB_SERVER_PORT is required");

src/domain/LegacySubmission.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { Operator, QueryBuilder } from "@topcoder-framework/client-relational";
2+
import { queryRunner } from "../helper/QueryRunner";
3+
import {
4+
CreateSubmissionInput,
5+
} from "../models/domain-layer/legacy/submission";
6+
import { ProjectSchema } from "../schema/project/Project";
7+
8+
class LegacySubmissionDomain {
9+
public async checkSubmissionExists(
10+
legacySubmissionId: number
11+
): Promise<any> {
12+
const { projectId } = ProjectSchema.columns;
13+
14+
const query = new QueryBuilder(ProjectSchema)
15+
.select(projectId)
16+
.where(projectId, Operator.OPERATOR_EQUAL, {
17+
value: {
18+
$case: "intValue",
19+
intValue: legacySubmissionId,
20+
},
21+
})
22+
.limit(1)
23+
.build();
24+
25+
const { rows } = await queryRunner.run(query);
26+
27+
return {
28+
exists: rows?.length == 1,
29+
};
30+
}
31+
32+
public async createLegacySubmission(input: CreateSubmissionInput): Promise<number> {
33+
const transaction = queryRunner.beginTransaction();
34+
35+
const createLegacySubmissionQuery = new QueryBuilder(ProjectSchema)
36+
.insert({
37+
submissionStatusId: input.submissionStatusId,
38+
submissionTypeId: input.submissionTypeId,
39+
uploadId: input.uploadId,
40+
createUser: input.createUser,
41+
modifyUser: input.modifyUser,
42+
createDate: input.createDate,
43+
modifyDate: input.modifyDate,
44+
})
45+
.build();
46+
47+
const createLegacySubmissionQueryResult = await transaction.add(createLegacySubmissionQuery);
48+
if (createLegacySubmissionQueryResult instanceof Error) {
49+
transaction.rollback();
50+
return Promise.reject({
51+
message: "Failed to create legacy submission",
52+
});
53+
}
54+
55+
const { lastInsertId: legacySubmissionId } = createLegacySubmissionQueryResult;
56+
57+
return Promise.resolve(legacySubmissionId!);
58+
}
59+
60+
// public async listAvailableSubmissionInfoTypes(key: string): Promise<number> {
61+
// const queryRequest: QueryRequest = {
62+
// query: {
63+
// query: {
64+
// $case: "select",
65+
// select: {
66+
// table: "project_info_type_lu",
67+
// join: [],
68+
// column: [
69+
// {
70+
// name: "",
71+
// type: ColumnType.COLUMN_TYPE_INT,
72+
// },
73+
// ],
74+
// where: [
75+
// {
76+
// key: "name",
77+
// operator: Operator.OPERATOR_EQUAL,
78+
// value: {
79+
// value: {
80+
// $case: "stringValue",
81+
// stringValue: key,
82+
// },
83+
// },
84+
// },
85+
// ],
86+
// groupBy: [],
87+
// orderBy: [],
88+
// limit: 1,
89+
// offset: 0,
90+
// },
91+
// },
92+
// },
93+
// };
94+
// return Promise.resolve(10);
95+
// }
96+
}
97+
98+
export default new LegacySubmissionDomain();

src/helper/QueryRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { GRPC_RDB_SERVER_HOST, GRPC_RDB_SERVER_PORT } = process.env;
1+
import { GRPC_RDB_SERVER_HOST, GRPC_RDB_SERVER_PORT } from '../config'
22

33
import { QueryRunner } from "@topcoder-framework/client-relational";
44

0 commit comments

Comments
 (0)