Skip to content

Commit

Permalink
Merge pull request #141 from ntuscse/challenges-backend-bh
Browse files Browse the repository at this point in the history
feat/ add season codebase to challenges
  • Loading branch information
Albert481 authored Feb 1, 2024
2 parents 0100482 + 6fdff39 commit 175a7eb
Show file tree
Hide file tree
Showing 26 changed files with 2,560 additions and 258 deletions.
4 changes: 3 additions & 1 deletion apps/challenges/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
MONGO_URI=mongodb://localhost/
MONGO_URI=mongodb://localhost:27017/
MONGO_PORT=27017
MONGO_DATABSE_NAME=challenges
16 changes: 16 additions & 0 deletions apps/challenges/docker-compose-local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# this docker-compose file is for convenient setup of a local
# mongodb instance for local testing
version: "3"
services:
challenges-mongo:
image: mongo
container_name: challenges-mongo
restart: always
ports:
- "${MONGO_PORT}:27017"
env_file:
- ./.env
environment:
MONGO_INITDB_DATABASE: ${MONGO_DATABSE_NAME}
volumes:
- ./mock/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
5 changes: 5 additions & 0 deletions apps/challenges/mock/mongo-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
db.createCollection("seasons");
db.createCollection("rankings");
db.createCollection("questions");
db.createCollection("submissions");
db.createCollection("users");
6 changes: 4 additions & 2 deletions apps/challenges/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"supertest": "^6.3.4",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"turbo": "^1.10.1"
"turbo": "^1.10.1",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/express": "^4.17.21",
Expand All @@ -33,6 +34,7 @@
},
"scripts": {
"start": "nodemon src/index.ts",
"test": "cross-env NODE_ENV=test jest --testTimeout=5000 --forceExit --maxWorkers=1"
"test": "cross-env NODE_ENV=test jest --testTimeout=5000 --forceExit --maxWorkers=1",
"setup": "docker-compose -f ./docker-compose-local.yaml up -d"
}
}
15 changes: 0 additions & 15 deletions apps/challenges/src/config/db.js

This file was deleted.

20 changes: 20 additions & 0 deletions apps/challenges/src/config/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import moongose from "mongoose";
import * as dotenv from "dotenv";
import { ConnectionOptions } from "tls";
dotenv.config();

const connectDB = async () => {
try {
const mongoURL = process.env.MONGO_URI || 'mongodb://localhost:27017';
const conn = await moongose.connect(mongoURL, {
useNewUrlParser: true,
dbName: process.env.MONGO_DATABSE_NAME || 'challenges',
} as ConnectionOptions);
console.log(`MongoDB Connected: ${mongoURL}`);
} catch (error) {
console.log(error);
process.exit(1)
}
}

export { connectDB as default };
157 changes: 0 additions & 157 deletions apps/challenges/src/controllers/leaderboard.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/challenges/src/controllers/questionaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Request, Response } from "express";
const asyncHandler = require('express-async-handler');
const Question = require('../model/question');
const Submission = require('../model/submission');
const Leaderboard = require('../model/leaderboard');
import Season from "../model/season";
import { isValidObjectId } from "../utils/db";

// @desc Get questions
Expand Down
Loading

0 comments on commit 175a7eb

Please sign in to comment.