Skip to content

Commit df637ce

Browse files
committed
Merge the latest development branch
2 parents b8042be + 27c8160 commit df637ce

28 files changed

+2810
-23
lines changed

.env.sample

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
1+
POSTGRES_SCHEMA="public"
2+
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=${POSTGRES_SCHEMA}"
3+
4+
# API configs
5+
BUS_API_URL="https://api.topcoder-dev.com/v5/bus/events"
6+
CHALLENGE_API_URL="https://api.topcoder-dev.com/v5/challenges/"
7+
MEMBER_API_URL="https://api.topcoder-dev.com/v5/members"
8+
# M2m configs
9+
M2M_AUTH_URL="https://auth0.topcoder-dev.com/oauth/token"
10+
M2M_AUTH_CLIENT_ID="<your-m2m-client-id>"
11+
M2M_AUTH_CLIENT_SECRET="<your-m2m-client-secret>"
12+
M2M_AUTH_DOMAIN="topcoder-dev.auth0.com"
13+
M2M_AUTH_AUDIENCE="https://m2m.topcoder-dev.com/"
14+
M2M_AUTH_PROXY_SERVER_URL=
15+
# Mock API configs
16+
M2M_MOCK_TOKEN="<your-m2m-mock-token>"
17+
#Sendgrid email templates
18+
SENDGRID_ACCEPT_REVIEW_APPLICATION="d-2de72880bd69499e9c16369398d34bb9"
19+
SENDGRID_REJECT_REVIEW_APPLICATION="d-82ed74e778e84d8c9bc02eeda0f44b5e"

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ $ pnpm run start:prod
2727
# run postgres in docker, or other approach
2828
docker run -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword postgres:14
2929
30-
export DATABASE_URL="postgresql://postgres:mysecretpassword@localhost:5432/postgres?schema=public"
30+
# Configure the database connection URL (without schema parameter)
31+
export DATABASE_URL="postgresql://postgres:mysecretpassword@localhost:5432/postgres"
32+
33+
# Configure the PostgreSQL schema (defaults to 'public' if not specified)
34+
export POSTGRES_SCHEMA="public"
3135
3236
# run migration
3337
npx prisma migrate dev
@@ -48,11 +52,32 @@ npx prisma migrate reset
4852
#- `update_foreign_keys`
4953
```
5054

55+
## Schema Configuration
56+
57+
The application supports configurable PostgreSQL schemas through the `POSTGRES_SCHEMA` environment variable:
58+
59+
```bash
60+
# Set the schema for development
61+
export POSTGRES_SCHEMA="dev_schema"
62+
63+
# Set the schema for production
64+
export POSTGRES_SCHEMA="prod_schema"
65+
66+
# If not specified, the application defaults to the 'public' schema
67+
```
68+
69+
This allows you to:
70+
- Use different schemas for different environments (development, testing, production)
71+
- Isolate data for different instances of the application
72+
- Improve security by separating schemas based on environment
73+
5174
## Data import
5275

5376
- create a .env file `mv .env.sample .env`
5477
- update the postgres database url in .env file —
55-
`DATABASE_URL="postgresql://postgres:mysecretpassword@localhost:5432/postgres?schema=public"`
78+
`DATABASE_URL="postgresql://postgres:mysecretpassword@localhost:5432/postgres"`
79+
- set the PostgreSQL schema in .env file —
80+
`POSTGRES_SCHEMA="public"` (or your preferred schema name)
5681
- place all the legacy json files in the `prisma/Scorecards` directory or specify it in .env file — `DATA_DIR=/path/to/Scorecards/folder/`
5782
- install dependencies `pnpm install`
5883
- run the prisma migration `npx prisma migrate dev`

appStartUp.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ set -eo pipefail
33

44
export DATABASE_URL=$(echo -e ${DATABASE_URL})
55

6+
# Set default schema to 'public' if not provided
7+
if [ -z "$POSTGRES_SCHEMA" ]; then
8+
echo "POSTGRES_SCHEMA not set, defaulting to 'public'"
9+
export POSTGRES_SCHEMA="public"
10+
else
11+
echo "Using PostgreSQL schema: $POSTGRES_SCHEMA"
12+
fi
13+
614
echo "Database - running migrations."
715
if $RESET_DB; then
816
echo "Resetting DB"

mock/mock-api.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const express = require('express')
2+
const winston = require('winston')
3+
const cors = require('cors')
4+
5+
const app = express()
6+
app.use(cors())
7+
app.use(express.json())
8+
app.set('port', 4000)
9+
10+
const logger = winston.createLogger({
11+
transports: [
12+
new winston.transports.Console({
13+
level: 'debug',
14+
format: winston.format.combine(
15+
winston.format.colorize(),
16+
winston.format.simple()
17+
),
18+
}),
19+
]
20+
});
21+
22+
// Event bus
23+
app.post('/eventBus', (req, res) => {
24+
logger.info(`Event Bus received message: ${JSON.stringify(req.body)}`);
25+
res.statusCode = 200;
26+
res.json({})
27+
})
28+
29+
// Use environment variable for M2M token instead of hardcoding
30+
const m2mToken = process.env.M2M_MOCK_TOKEN || 'dummy-token';
31+
32+
const m2mScope = 'write:bus_api,all:challenges';
33+
34+
// Auth0
35+
app.post('/oauth/token', (req, res) => {
36+
logger.info('Getting M2M tokens')
37+
res.json({
38+
access_token: m2mToken,
39+
scope: m2mScope,
40+
expires_in: 94608000,
41+
token_type: 'Bearer'
42+
})
43+
})
44+
45+
// Member API
46+
app.get('/members', (req, res) => {
47+
logger.info(`Member API receives params: ${JSON.stringify(req.query)}`)
48+
let userIdStr = req.query.userIds
49+
userIdStr = userIdStr.replaceAll('[', '').replaceAll(']', '')
50+
const userIds = userIdStr.split(',')
51+
// return result
52+
const ret = userIds.map(id => ({
53+
userId: parseInt(id),
54+
email: `${id}@topcoder.com`
55+
}))
56+
res.json(ret)
57+
})
58+
59+
// Challenge API
60+
app.get('/challenges/:id', (req, res) => {
61+
// directly challenge details
62+
const id = req.params.id
63+
logger.info(`Getting challenge with id ${id}`)
64+
if (id === '11111111-2222-3333-9999-444444444444') {
65+
res.statusCode = 404
66+
res.json({})
67+
return
68+
}
69+
res.json({
70+
id,
71+
name: `Test Challenge ${id}`,
72+
legacy: {
73+
track: 'DEVELOP',
74+
subTrack: 'CODE'
75+
},
76+
numOfSubmissions: 2,
77+
legacyId: 30376875,
78+
tags: ['Prisma', 'NestJS']
79+
})
80+
})
81+
82+
83+
app.listen(app.get('port'), '0.0.0.0', () => {
84+
logger.info(`Express server listening on port ${app.get('port')}`)
85+
})
86+

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
"postinstall": "npx prisma generate"
2222
},
2323
"dependencies": {
24+
"@nestjs/axios": "^4.0.0",
2425
"@nestjs/common": "^11.0.1",
2526
"@nestjs/core": "^11.0.1",
27+
"@nestjs/mapped-types": "^2.1.0",
2628
"@nestjs/platform-express": "^11.0.1",
2729
"@nestjs/swagger": "^11.0.3",
2830
"@prisma/client": "^6.3.1",
2931
"@types/jsonwebtoken": "^9.0.9",
32+
"axios": "^1.9.0",
3033
"class-transformer": "^0.5.1",
3134
"class-validator": "^0.14.1",
3235
"cors": "^2.8.5",
@@ -35,7 +38,8 @@
3538
"multer": "^2.0.1",
3639
"nanoid": "~5.1.2",
3740
"reflect-metadata": "^0.2.2",
38-
"rxjs": "^7.8.1"
41+
"rxjs": "^7.8.1",
42+
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v3.0.1"
3943
},
4044
"devDependencies": {
4145
"@eslint/eslintrc": "^3.2.0",
@@ -53,6 +57,7 @@
5357
"eslint": "^9.18.0",
5458
"eslint-config-prettier": "^10.0.1",
5559
"eslint-plugin-prettier": "^5.2.2",
60+
"express": "^5.1.0",
5661
"globals": "^15.14.0",
5762
"jest": "^29.7.0",
5863
"prettier": "^3.4.2",
@@ -64,7 +69,8 @@
6469
"ts-node": "^10.9.2",
6570
"tsconfig-paths": "^4.2.0",
6671
"typescript": "^5.7.3",
67-
"typescript-eslint": "^8.20.0"
72+
"typescript-eslint": "^8.20.0",
73+
"winston": "^3.17.0"
6874
},
6975
"prisma": {
7076
"seed": "ts-node prisma/migrate.ts",

0 commit comments

Comments
 (0)