diff --git a/src/domain/LegacySubmission.ts b/src/domain/LegacySubmission.ts index eddf676..cab2140 100644 --- a/src/domain/LegacySubmission.ts +++ b/src/domain/LegacySubmission.ts @@ -1,8 +1,12 @@ -import { QueryBuilder, QueryResult } from "@topcoder-framework/client-relational"; +import { Query, QueryBuilder, QueryResult } from "@topcoder-framework/client-relational"; +import { UpdateResult } from "@topcoder-framework/lib-common"; +import { Util } from "../common/Util"; import SubmissionQueryHelper from "../helper/query-helper/SubmissionQueryHelper"; import { queryRunner } from "../helper/QueryRunner"; -import { CreateSubmissionInput } from "../models/domain-layer/legacy/submission"; -import { SubmissionSchema } from "../schema/project/Submission"; +import { + CreateSubmissionInput, UpdateSubmissionInput +} from "../models/domain-layer/legacy/submission"; +import { LegacySubmissionSchema } from "../schema/submission/Submission"; const submissionTypes = { 'Contest Submission': { id: 1, roleId: 1 }, @@ -97,6 +101,18 @@ class LegacySubmissionDomain { // }; // return Promise.resolve(10); // } + + public async update(input: UpdateSubmissionInput): Promise { + const query: Query = new QueryBuilder(LegacySubmissionSchema) + .update({ ...input }) + .where(...Util.toScanCriteria({ ...input } as { [key: string]: number|string|undefined })) + .build(); + + const { affectedRows } = await queryRunner.run(query); + return { + updatedCount: affectedRows || 0, + } + } } export default new LegacySubmissionDomain(); diff --git a/src/domain/LegacyUpload.ts b/src/domain/LegacyUpload.ts new file mode 100644 index 0000000..d8d204e --- /dev/null +++ b/src/domain/LegacyUpload.ts @@ -0,0 +1,24 @@ +import { Query, QueryBuilder } from "@topcoder-framework/client-relational"; +import { UpdateResult } from "@topcoder-framework/lib-common"; +import { Util } from "../common/Util"; +import { queryRunner } from "../helper/QueryRunner"; +import { + UpdateUploadInput, +} from "../models/domain-layer/legacy/upload"; +import { UploadSchema } from "../schema/submission/Upload"; + +class LegacySubmissionDomain { + public async update(input: UpdateUploadInput): Promise { + const query: Query = new QueryBuilder(UploadSchema) + .update({ ...input }) + .where(...Util.toScanCriteria({ ...input } as { [key: string]: number|string|undefined })) + .build(); + + const { affectedRows } = await queryRunner.run(query); + return { + updatedCount: affectedRows || 0, + } + } +} + +export default new LegacySubmissionDomain(); diff --git a/src/schema/submission/Submission.ts b/src/schema/submission/Submission.ts new file mode 100644 index 0000000..cbcbf70 --- /dev/null +++ b/src/schema/submission/Submission.ts @@ -0,0 +1,21 @@ +import { ColumnType, Schema } from "@topcoder-framework/client-relational"; +import { LegacySubmission } from "../../models/domain-layer/legacy/submission"; +import { AuditColumns } from "../common/AuditColumns"; + +export const LegacySubmissionSchema: Schema = { + dbSchema: "tcs_catalog", + tableName: "submission", + idColumn: "submission_id", + idSequence: "submission_id_seq", + idTable: "submission", + columns: { + submissionId: { name: "submission_id", type: ColumnType.COLUMN_TYPE_INT }, + submissionStatusId: { name: "submission_status_id", type: ColumnType.COLUMN_TYPE_INT }, + submissionTypeId: { name: "submission_type_id", type: ColumnType.COLUMN_TYPE_INT }, + uploadId: { name: "upload_id", type: ColumnType.COLUMN_TYPE_INT }, + screeningScore: { name: "screening_score", type: ColumnType.COLUMN_TYPE_INT }, + initialScore: { name: "initial_score", type: ColumnType.COLUMN_TYPE_INT }, + finalScore: { name: "final_score", type: ColumnType.COLUMN_TYPE_INT }, + ...AuditColumns, + }, +}; diff --git a/src/schema/submission/Upload.ts b/src/schema/submission/Upload.ts new file mode 100644 index 0000000..1fbe487 --- /dev/null +++ b/src/schema/submission/Upload.ts @@ -0,0 +1,22 @@ +import { ColumnType, Schema } from "@topcoder-framework/client-relational"; +import { Upload } from "../../models/domain-layer/legacy/upload"; +import { AuditColumns } from "../common/AuditColumns"; + +export const UploadSchema: Schema = { + dbSchema: "tcs_catalog", + tableName: "upload", + idColumn: "upload_id", + idSequence: "upload_id_seq", + idTable: "upload", + columns: { + uploadId: { name: "upload_id", type: ColumnType.COLUMN_TYPE_INT }, + projectId: { name: "project_id", type: ColumnType.COLUMN_TYPE_INT }, + resourceId: { name: "resource_id", type: ColumnType.COLUMN_TYPE_INT }, + projectPhaseId: { name: "project_phase_id", type: ColumnType.COLUMN_TYPE_INT }, + uploadTypeId: { name: "upload_type_id", type: ColumnType.COLUMN_TYPE_INT }, + url: { name: "url", type: ColumnType.COLUMN_TYPE_STRING }, + uploadStatusId: { name: "upload_status_id", type: ColumnType.COLUMN_TYPE_INT }, + parameter: { name: "parameter", type: ColumnType.COLUMN_TYPE_STRING }, + ...AuditColumns, + }, +}; diff --git a/src/server.ts b/src/server.ts index 71cfeea..6370fa4 100644 --- a/src/server.ts +++ b/src/server.ts @@ -29,6 +29,7 @@ import { LegacyResourceServer, LegacyResourceService } from "./service/Resource" import { LegacyReviewServer, LegacyReviewService } from "./service/Review"; import { LegacySyncServer, LegacySyncService } from "./service/Sync"; import { LegacyTermServer, LegacyTermService } from "./service/Term"; +import { LegacyUploadServer, LegacyUploadService } from "./service/LegacyUpload"; const server = new Server({ "grpc.max_send_message_length": -1, @@ -51,6 +52,7 @@ server.addService(LegacyResourceService, new LegacyResourceServer()); server.addService(LegacyGroupContestEligibilityService, new LegacyGroupContestEligibilityServer()); server.addService(LegacyChallengePaymentService, new LegacyChallengePaymentServer()); server.addService(LegacyPrizeServiceService, new LegacyPrizeServer()); +server.addService(LegacyUploadService, new LegacyUploadServer()); server.addService(LegacySyncService, new LegacySyncServer()); server.bindAsync( diff --git a/src/service/LegacySubmission.ts b/src/service/LegacySubmission.ts index 4939d23..a3436b9 100644 --- a/src/service/LegacySubmission.ts +++ b/src/service/LegacySubmission.ts @@ -47,7 +47,11 @@ class LegacySubmissionServerImpl implements LegacySubmissionServer { update: handleUnaryCall = ( call: ServerUnaryCall, callback: sendUnaryData - ) => { }; + ) => { + LegacySubmissionDomain.update(call.request) + .then((response) => callback(null, response)) + .catch((err) => callback(err, null)); + }; } -export { LegacySubmissionServerImpl as LegacySubmissionServer, LegacySubmissionService }; \ No newline at end of file +export { LegacySubmissionServerImpl as LegacySubmissionServer, LegacySubmissionService }; diff --git a/src/service/LegacyUpload.ts b/src/service/LegacyUpload.ts new file mode 100644 index 0000000..fd71c8e --- /dev/null +++ b/src/service/LegacyUpload.ts @@ -0,0 +1,52 @@ +import { handleUnaryCall, sendUnaryData, ServerUnaryCall, UntypedHandleCall } from "@grpc/grpc-js"; +import { CreateResult, Empty, LookupCriteria, ScanRequest, ScanResult, UpdateResult +} from "@topcoder-framework/lib-common"; +import LegacyUploadDomain from '../domain/LegacyUpload' + +import { LegacyUploadServer, LegacyUploadService } from '../models/domain-layer/legacy/services/upload'; +import { Upload, CreateUploadInput, DeleteUploadInput, UploadList, UpdateUploadInput } from "../models/domain-layer/legacy/upload"; + +class LegacyUploadServerImpl implements LegacyUploadServer { + [name: string]: UntypedHandleCall; + + scan: handleUnaryCall = ( + call: ServerUnaryCall, + callback: sendUnaryData + ) => { + // not implemented + }; + + lookup: handleUnaryCall + = ( + call: ServerUnaryCall, + callback: sendUnaryData + ) => { + // not implemented + }; + + create: handleUnaryCall = ( + call: ServerUnaryCall, + callback: sendUnaryData + ) => { + // not implemented + }; + + delete: handleUnaryCall = ( + call: ServerUnaryCall, + callback: sendUnaryData + ) => { + // not implemented + }; + + + update: handleUnaryCall = ( + call: ServerUnaryCall, + callback: sendUnaryData + ) => { + LegacyUploadDomain.update(call.request) + .then((response) => callback(null, response)) + .catch((err) => callback(err, null)); + }; +} + +export { LegacyUploadServerImpl as LegacyUploadServer, LegacyUploadService };