Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 3 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# 99Tech Code Challenge #1 #

Note that if you fork this repository, your responses may be publicly linked to this repo.
Please submit your application along with the solutions attached or linked.

It is important that you minimally attempt the problems, even if you do not arrive at a working solution.

## Submission ##
You can either provide a link to an online repository, attach the solution in your application, or whichever method you prefer.
We're cool as long as we can view your solution without any pain.
## Instructions to Run Projects
Each project inside this repository contains its own README with setup and run instructions.
Please refer to the respective project folder for details.
27 changes: 0 additions & 27 deletions src/problem2/index.html

This file was deleted.

Empty file removed src/problem2/script.js
Empty file.
8 changes: 0 additions & 8 deletions src/problem2/style.css

This file was deleted.

Empty file removed src/problem3/.keep
Empty file.
36 changes: 36 additions & 0 deletions src/problem4/problem4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

// Time complexity: O(n)
// Space complexity: O(1)
function sum_to_n_a(n: number): number {
let sum = 0;

for (let i = 1; i <= n; i++) {
sum += i;
}

return sum;
}


// Time complexity: O(1)
// Space complexity: O(1)
function sum_to_n_b(n: number): number {
return (n * (n + 1)) / 2;
}


// Time complexity: O(n)
// Space complexity: O(n)
function sum_to_n_c(n: number): number {
const memo = {};

function sum(x: number): number {
if (x <= 1) return x;
if (memo[x] !== undefined) return memo[x];

memo[x] = x + sum(x - 1);
return memo[x];
}

return sum(n);
}
4 changes: 4 additions & 0 deletions src/problem5/backend-game-inventory/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
.git
.env
3 changes: 3 additions & 0 deletions src/problem5/backend-game-inventory/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MONGO_URI=mongodb://db:27017/game_inventory
PORT=3000
NODE_ENV=development
4 changes: 4 additions & 0 deletions src/problem5/backend-game-inventory/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
# Keep environment variables out of version control
.env
dist
148 changes: 148 additions & 0 deletions src/problem5/backend-game-inventory/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Game Inventory API

A simple **Game Inventory Management API** built with **Node.js, Express, TypeScript, MongoDB, and Docker**.

---

# Tech Stack

- Node.js + Express
- TypeScript
- MongoDB
- Docker & Docker Compose

---

# Project Structure
```bash
├── app.ts
├── server.ts
├── config
│ ├── env.ts
│ └── index.ts
├── controllers
│ ├── game.controller.ts
│ └── tests
├── services
│ ├── game.service.ts
│ └── tests
├── routes
│ └── game.routes.ts
├── models
│ └── game.model.ts
├── db
│ └── mongo.ts
├── dto
│ └── game.dto.ts
├── validation
│ └── game.validation.ts
├── middleware
│ ├── errorHandler.ts
│ └── validate.ts
├── utils
│ ├── AppError.ts
│ ├── asyncWrapper.ts
│ ├── errors.ts
│ ├── handler.ts
│ └── response.ts
├── types
│ ├── express.d.ts
│ └── validated-request.ts
└── docs
└── openapi.yaml
```

# Environment Setup

## 1. Create `.env` file

Copy from `.env.example`:

```bash
cp .env.example .env
```
Example
```
PORT=3000
MONGO_URI=mongodb://db:27017/game_inventory
NODE_ENV=development
```

## 2. Development setup

Start dev environment
```bash
docker compose -f docker-compose.dev.yml up -d
```

View logs
```bash
docker compose -f docker-compose.dev.yml logs -f app
```
Access app
```
http://localhost:3000
```

Stop dev
```bash
docker compose -f docker-compose.dev.yml down
```

## 3. Production setup

Start production
```bash
docker compose -f docker-compose.prod.yml up -d --build
```

View logs
```bash
docker compose -f docker-compose.prod.yml logs -f app
```

Access app
```
http://localhost:3000
```

Stop production
```bash
docker compose -f docker-compose.prod.yml down
```

## 4. API Documentation

The API is documented using OpenAPI (Swagger).

After running the application, you can access the API documentation at:

```
http://localhost:3000/api-docs
```

## 5. Running Tests

The project uses Jest for unit testing.

Run all tests
```
npm run test
```

Run tests in watch mode
```
npm run test:watch
```
31 changes: 31 additions & 0 deletions src/problem5/backend-game-inventory/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: "3.9"

services:
db:
image: mongo:7
container_name: game-mongo
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db

app:
build:
context: .
dockerfile: docker/Dockerfile.dev
container_name: game-api
depends_on:
- db
ports:
- "3000:3000"
env_file:
- .env
volumes:
- .:/app
- /app/node_modules
environment:
CHOKIDAR_USEPOLLING: "true"
command: sh -c "npm run seed && npm run dev"

volumes:
mongo_data:
25 changes: 25 additions & 0 deletions src/problem5/backend-game-inventory/docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3.9"

services:
db:
image: mongo:7
container_name: game-mongo
restart: always
volumes:
- mongo_data:/data/db

app:
build:
context: .
dockerfile: docker/Dockerfile.prod
container_name: game-api
depends_on:
- db
ports:
- "3000:3000"
env_file:
- .env
command: node dist/server.js

volumes:
mongo_data:
13 changes: 13 additions & 0 deletions src/problem5/backend-game-inventory/docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:20

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "run", "dev"]
28 changes: 28 additions & 0 deletions src/problem5/backend-game-inventory/docker/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ===== BUILD STAGE =====
FROM node:20 AS builder

WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .

RUN npm run build


# ===== RUNTIME STAGE =====
FROM node:20

WORKDIR /app

COPY package*.json ./
RUN npm install --omit=dev

COPY --from=builder /app/dist ./dist

COPY --from=builder /app/src/docs ./dist/docs

EXPOSE 3000

CMD ["node", "dist/server.js"]
18 changes: 18 additions & 0 deletions src/problem5/backend-game-inventory/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { createDefaultPreset } = require("ts-jest");

const tsJestTransformCfg = createDefaultPreset().transform;

/** @type {import("jest").Config} **/
module.exports = {
testEnvironment: "node",
transform: {
...tsJestTransformCfg,
},
preset: "ts-jest",
roots: ["<rootDir>/src"],
moduleFileExtensions: ["ts", "js"],
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/src/$1"
},
clearMocks: true
};
Loading