|
| 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(); |
0 commit comments