Skip to content

feature: implement legacy challenge update #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b2a7a49
feat: add project, resource, payment schema
rakibansary Jan 26, 2023
df791a3
fix: use id_column, id_sequence from schema definition
rakibansary Jan 26, 2023
d5ace96
feat: use @topcoder-framework/lib-client for rdb types
rakibansary Jan 29, 2023
2a8c91f
feat: switch to @topcoder-framework/lib-common and @topcoder-framwork…
rakibansary Jan 31, 2023
302c087
feat: add type information to schema
rakibansary Feb 3, 2023
b83d3a6
feat(domain-acl): complete challenge update interfaces
ThomasKranitsas Feb 8, 2023
8526817
fix(acl): change folder naming convention
ThomasKranitsas Feb 9, 2023
8c22dc4
fix(domain-acl): create closeChallenge method
ThomasKranitsas Feb 9, 2023
19208bf
fix(domain-acl): fix reviewer type
ThomasKranitsas Feb 9, 2023
c6ade2f
refactor: use v0.0.13 proto definitions
rakibansary Feb 10, 2023
480070f
fix(domain-acl): add audit properties where needed
ThomasKranitsas Feb 9, 2023
56eda4e
fix(domain-acl): complete activateChallenge
ThomasKranitsas Feb 10, 2023
74456eb
refactor: use v0.0.14 proto definitions
rakibansary Feb 12, 2023
34b84a2
correct imports
ThomasKranitsas Feb 13, 2023
3ee328f
add prize service
ThomasKranitsas Feb 14, 2023
5809268
feat: implement challenge:create
rakibansary Feb 15, 2023
adcb9c4
refactor: challenge interfaces
rakibansary Feb 15, 2023
234ade3
fixes for challenge update
ThomasKranitsas Feb 21, 2023
0002e31
fix(domain-acl): fixes for challenge update
ThomasKranitsas Feb 22, 2023
b98f609
remove audit fields
ThomasKranitsas Feb 24, 2023
a468fb3
feat(ci): setup circleci (#7)
rakibansary Feb 26, 2023
cb5b617
chore: organize imports on save
rakibansary Feb 26, 2023
92329fe
chore: add pre-commit hook
rakibansary Feb 26, 2023
bb20642
ci: build & publish image to ecr
rakibansary Feb 26, 2023
53ec2c9
feat: add linting
rakibansary Feb 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: 2.1

jobs:
publish-image:
docker:
- image: cimg/aws:2023.01
environment:
CODEARTIFACT_ENV: PROD
ECR_ENV: QA
SERVICE_NAME: "anticorruption-layer"
OUT_DIR: "buildscripts"
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
name: "Setup deploy scripts"
command: |
git clone -b v1.4 https://github.com/topcoder-platform/tc-deploy-scripts ../${OUT_DIR}
cp ./../${OUT_DIR}/awsconfiguration.sh .
- run:
name: "Authenticate with AWS CodeArtifact and Build Docker Image"
command: |
./awsconfiguration.sh ${CODEARTIFACT_ENV}
source awsenvconf
aws codeartifact login --tool npm --repository topcoder-framework --domain topcoder --domain-owner $AWS_ACCOUNT_ID --region $AWS_REGION --namespace @topcoder-framework
cp ~/.npmrc .
rm -f awsenvconf
docker build -t ${SERVICE_NAME}:${CIRCLE_SHA1} .
- run:
name: "Set AWS environment variables"
command: |
./awsconfiguration.sh ${ECR_ENV}
- run:
name: "Publish docker image"
command: |
source awsenvconf
aws ecr get-login-password | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
docker tag ${SERVICE_NAME}:${CIRCLE_SHA1} $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/${SERVICE_NAME}:${CIRCLE_SHA1}
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/${SERVICE_NAME}:${CIRCLE_SHA1}

workflows:
version: 2
publish:
jobs:
- "publish-image":
context: "org-global"
filters:
branches:
only: "feature/legacy-challenge"
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
src/models/
src/typings/
node_modules/
dist-cjs/
dist-es/
23 changes: 23 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"env": {
"es2022": true
},
"plugins": ["@typescript-eslint", "prettier"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2022,
"project": "./tsconfig.json"
},
"rules": {
"prefer-const": "error",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-unsafe-member-access": "warn"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist/
.env
.DS_Store
.npmrc
yarn-error.log
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"printWidth": 100
"printWidth": 100,
"organizeImportsSkipDestructiveCodeActions": true
}
32 changes: 19 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
FROM node:18.11.0-alpine3.16 as ts-compile
WORKDIR /usr/tc-acl
FROM node:18.14.1-alpine3.17 as ts-compile
WORKDIR /usr/anticorruption-layer
COPY yarn*.lock ./
COPY package*.json ./
COPY tsconfig*.json ./
RUN npm install
COPY .npmrc ./
RUN yarn install --frozen-lockfile --production=false
COPY . ./
RUN npm run build:app
RUN yarn build:app

FROM node:18.11.0-alpine3.16 as ts-remove
WORKDIR /usr/tc-acl
COPY --from=ts-compile /usr/tc-acl/package*.json ./
COPY --from=ts-compile /usr/tc-acl/dist ./
RUN npm install --omit=dev
FROM node:18.14.1-alpine3.17 as ts-remove
WORKDIR /usr/anticorruption-layer
COPY --from=ts-compile /usr/anticorruption-layer/yarn*.lock ./
COPY --from=ts-compile /usr/anticorruption-layer/package*.json ./
COPY --from=ts-compile /usr/anticorruption-layer/dist ./
COPY --from=ts-compile /usr/anticorruption-layer/.npmrc ./
RUN yarn install --frozen-lockfile --production=false

FROM gcr.io/distroless/nodejs:18
WORKDIR /usr/tc-acl
COPY --from=ts-remove /usr/tc-acl ./
WORKDIR /usr/anticorruption-layer
COPY --from=ts-remove /usr/anticorruption-layer ./
USER 1000
ENV GRPC_SERVER_PORT=40020
ENV GRPC_SERVER_HOST=localhost
ENV GRPC_RDB_SERVER_HOST=localhost
ENV GRPC_RDB_SERVER_PORT=9090
CMD ["server.js"]


1 change: 0 additions & 1 deletion bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const protoConfig = [
`--plugin=${PLUGIN_PATH}`,
// https://github.com/stephenh/ts-proto/blob/main/README.markdown
"--ts_proto_opt=outputServices=grpc-js,env=node,useOptionals=messages,exportCommonSymbols=false,esModuleInterop=true",
`--ts_proto_opt=stringEnums=true`,
`--ts_proto_opt=useDate=string`,
`--ts_proto_opt=oneof=unions`,
`--ts_proto_opt=addGrpcMetadata=true`,
Expand Down
40 changes: 35 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,60 @@
"build:app": "rimraf dist && tsc -b",
"build": "node bin/server && rimraf dist && tsc -b",
"clean": "rimraf dist",
"start": "ts-node-dev --respawn --transpile-only src/server.ts"
"start": "ts-node-dev --respawn --transpile-only src/server.ts",
"prepare": "husky install",
"lint": "yarn eslint src --ext ts"
},
"keywords": [],
"keywords": [
"Topcoder",
"Anticorruption Layer",
"Topcoder Platform",
"Topcoder gRPC Service"
],
"author": "Rakib Ansary <rakibansary@topcoder.com>",
"license": "ISC",
"dependencies": {
"@grpc/grpc-js": "^1.7.1",
"@topcoder-framework/client-relational": "^0.4.24-ci.0",
"@topcoder-framework/lib-common": "^0.4.24-ci.0",
"@topcoder-framework/client-relational": "^0.4.3",
"@topcoder-framework/lib-common": "^0.4.3",
"dayjs": "^1.11.5",
"dotenv": "^16.0.3",
"grpc-server-reflection": "^0.1.5",
"lodash": "^4.17.21",
"moment": "^2.29.4",
"source-map-support": "^0.5.21",
"topcoder-interface": "github:topcoder-platform/plat-interface-definition#v0.0.11",
"topcoder-interface": "github:topcoder-platform/plat-interface-definition#v0.0.19",
"uuidv4": "^6.2.13"
},
"devDependencies": {
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@commitlint/config-lerna-scopes": "^17.2.1",
"@types/lodash": "^4.14.186",
"@types/node": "18.11.18",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"commitlint": "^17.3.0",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.0",
"lint-staged": "^13.1.2",
"prettier": "^2.8.1",
"prettier-plugin-organize-imports": "^3.2.2",
"ts-node-dev": "^2.0.0",
"ts-proto": "^1.126.1",
"typescript": "^4.9.4"
},
"lint-staged": {
"*.{ts,tsx}": [
"npx prettier --write",
"npx eslint --fix"
],
"*.{json,md,yml}": [
"npx prettier --write"
]
},
"volta": {
"node": "18.13.0",
"yarn": "1.22.19"
Expand Down
74 changes: 74 additions & 0 deletions src/common/Util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Row, Value as RelationalValue } from "@topcoder-framework/client-relational";
import { Operator, ScanCriteria, Value } from "@topcoder-framework/lib-common";
import _ from "lodash";

export class Util {
public static toScanCriteria(criteria: { [key: string]: any }): ScanCriteria[] {
Expand All @@ -11,4 +13,76 @@ export class Util {
} as ScanCriteria)
);
}

public static toIntValue(val: number): RelationalValue {
return {
value: {
$case: "intValue",
intValue: val,
},
};
}

public static toFloatValue(val: number): RelationalValue {
return {
value: {
$case: "floatValue",
floatValue: val,
},
};
}

public static toStringValue(val: string): RelationalValue {
return {
value: {
$case: "stringValue",
stringValue: val,
},
};
}

public static toDatetimeValue(val: string): RelationalValue {
return {
value: {
$case: "datetimeValue",
datetimeValue: val,
},
};
}

public static parseRow(row: Row): any {
const obj: any = {};
for (const key of Object.keys(row.values)) {
if (row.values[key].value?.$case) {
obj[_.camelCase(key)] = _.get(row.values[key].value, row.values[key].value!.$case);
}
}
return obj;
}

public static formatDate(str: string | undefined) {
if (str == null || str.length == 0) {
return undefined;
}
try {
const date = new Date(str);
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, "0");
const day = date.getDate().toString().padStart(2, "0");
const hours = date.getHours().toString().padStart(2, "0");
const minutes = date.getMinutes().toString().padStart(2, "0");
const seconds = date.getSeconds().toString().padStart(2, "0");
const milliseconds = date.getMilliseconds().toString().padStart(3, "0");

return (
[year, month, day].join("-") +
" " +
[hours, minutes, seconds].join(":") +
"." +
milliseconds
);
} catch {
return undefined;
}
}
}
63 changes: 63 additions & 0 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
export const PhaseStatusIds = {
Scheduled: 1,
Open: 2,
Closed: 3,
};

export const PhaseTypeIds = {
Submission: 2,
Review: 4,
IterativeReview: 18,
SpecificationSubmission: 13,
};

export const ProjectCategories = {
First2Finish: 38,
};

export const ResourceRoleTypeIds = {
Submitter: 1,
PrimaryScreener: 2,
Screener: 3,
Reviewer: 4,
Approver: 10,
Designer: 11,
Observer: 12,
Manager: 13,
Copilot: 14,
ClientManager: 15,
PostMortemReviewer: 16,
SpecificationSubmitter: 17,
SpecificationReviewer: 18,
CheckpointScreener: 19,
CheckpointReviewer: 20,
IterativeReviewer: 21,
};

export const ResourceInfoTypeIds = {
ExternalReferenceId: 1,
Handle: 2,
Email: 3,
Rating: 4,
Reliability: 5,
RegistrationDate: 6,
Payment: 7,
PaymentStatus: 8,
ScreeningScore: 9,
InitialScore: 10,
FinalScore: 11,
Placement: 12,
AppealsCompletedEarly: 13,
SVNPermissionAdded: 14,
ManualPayments: 15,
};

type ResourceInfoTypeIds = keyof typeof ResourceInfoTypeIds;

export const ObserverResourceInfoToAdd: ResourceInfoTypeIds[] = [
"ExternalReferenceId",
"Handle",
"RegistrationDate",
"PaymentStatus",
"AppealsCompletedEarly",
];
Loading