Skip to content

Commit 6df7407

Browse files
committed
Merge branch 'main' of https://github.com/call-0f-code/COC-API into Acheivements-Routes
2 parents ecf0938 + 72d3408 commit 6df7407

36 files changed

Lines changed: 1277 additions & 1237 deletions

.github/workflows/apidocs.yml

Whitespace-only changes.

.github/workflows/tests.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Set up Bun
1717
uses: oven-sh/setup-bun@v2
1818
with:
19-
bun-version: '1.2.18' # or pin to whatever Bun version you need
19+
bun-version: "1.2.18" # or pin to whatever Bun version you need
2020

2121
- name: Cache Bun dependencies
2222
uses: actions/cache@v4
@@ -30,10 +30,9 @@ jobs:
3030
3131
- name: Install dependencies
3232
run: bun install
33-
33+
3434
- name: Generate Prisma client
3535
run: bun run generate
3636

3737
- name: Run tests
3838
run: bun jest
39-

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ This repository contains the common Express.js API for the backends of our Codin
5454
5555
├── tests/ # integration and unit tests (Jest or Mocha)
5656
│ ├── members.test.ts
57-
│ └── ...
57+
│ └── ...
5858
5959
├── .env.example # template for environment variables
6060
├── package.json
@@ -65,7 +65,7 @@ This repository contains the common Express.js API for the backends of our Codin
6565

6666
### Prerequisite
6767

68-
* Install [Bun](https://bun.sh/) on your machine.
68+
- Install [Bun](https://bun.sh/) on your machine.
6969

7070
### 1. Clone the repo
7171

@@ -82,8 +82,8 @@ bun install
8282

8383
### 3. Configure environment
8484

85-
* Copy `.env.example` to `.env`
86-
* Update `.env` with your Supabase/PostgreSQL connection URL and any other variables:
85+
- Copy `.env.example` to `.env`
86+
- Update `.env` with your Supabase/PostgreSQL connection URL and any other variables:
8787

8888
### 4. Initialize Prisma & Database
8989

@@ -98,8 +98,8 @@ bun prisma generate
9898
bun run dev
9999
```
100100

101-
* By default, the server listens on `http://localhost:3000`
102-
* `app.ts` sets up your Express instance; `server.ts` starts the HTTP listener
101+
- By default, the server listens on `http://localhost:3000`
102+
- `app.ts` sets up your Express instance; `server.ts` starts the HTTP listener
103103

104104
### 6. Run tests
105105

apidoc.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"name": "COC API",
3-
"version": "1.0.0",
2+
"name": "COC API",
3+
"version": "1.0.0",
44
"description": "REST API for Coding Club backend",
5-
"title": "Coding Club API Docs",
5+
"title": "Coding Club API Docs",
66
"url": "http://localhost:3000/api/v1",
7-
"sampleUrl": false,
7+
"sampleUrl": false,
88
"template": {
99
"withCompare": true,
1010
"sort": true
1111
},
12-
"output": "docs/apidoc",
13-
"input": "src/routes",
14-
"includeFilters": ["\\.ts$"]
12+
"output": "docs/apidoc",
13+
"input": "src/routes",
14+
"includeFilters": ["\\.ts$"]
1515
}

eslint.config.mjs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import globals from "globals";
33
import tseslint from "typescript-eslint";
44
import { defineConfig } from "eslint/config";
55

6-
76
export default defineConfig([
8-
{ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"] },
9-
{ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], languageOptions: { globals: globals.browser } },
7+
{
8+
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
9+
plugins: { js },
10+
extends: ["js/recommended"],
11+
},
12+
{
13+
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
14+
languageOptions: { globals: globals.browser },
15+
},
1016
tseslint.configs.recommended,
1117
]);

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log("Hello via Bun!");
1+
console.log("Hello via Bun!");

jest.config.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
export default {
3-
preset: 'ts-jest',
4-
testEnvironment: 'node',
5-
moduleFileExtensions: ['ts', 'js', 'json'],
6-
testMatch: ['**/tests/**/*.test.ts'],
7-
}
2+
preset: "ts-jest",
3+
testEnvironment: "node",
4+
moduleFileExtensions: ["ts", "js", "json"],
5+
testMatch: ["**/tests/**/*.test.ts"],
6+
};

singleton.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
import { mockDeep, mockReset, DeepMockProxy } from 'jest-mock-extended'
2-
import { PrismaClient } from '@prisma/client'
1+
import { mockDeep, mockReset, DeepMockProxy } from "jest-mock-extended";
2+
import { PrismaClient } from "@prisma/client";
33

4-
let mock: DeepMockProxy<PrismaClient>
4+
let mock: DeepMockProxy<PrismaClient>;
55

6-
jest.mock('./src/db/client', () => {
7-
mock = mockDeep<PrismaClient>()
6+
jest.mock("./src/db/client", () => {
7+
mock = mockDeep<PrismaClient>();
88
return {
99
__esModule: true,
1010
prisma: mock,
11-
}
12-
})
11+
};
12+
});
1313

14+
import { prisma } from "./src/db/client";
1415

15-
import { prisma } from './src/db/client'
16-
17-
export const prismaMock = prisma as unknown as DeepMockProxy<PrismaClient>
16+
export const prismaMock = prisma as unknown as DeepMockProxy<PrismaClient>;
1817

1918
beforeEach(() => {
20-
mockReset(prismaMock)
21-
})
19+
mockReset(prismaMock);
20+
});

src/app.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
11
// src/app.ts
2-
import express from 'express'
3-
import cors from 'cors'
4-
import multer from 'multer'
5-
import { json, urlencoded } from 'body-parser'
6-
import routes from './routes'
7-
import { errorHandler } from './utils/apiError'
8-
import { createClient } from '@supabase/supabase-js'
9-
import config from './config'
10-
import path from 'path'
11-
2+
import express from "express";
3+
import cors from "cors";
4+
import multer from "multer";
5+
import { json, urlencoded } from "body-parser";
6+
import routes from "./routes";
7+
import { errorHandler } from "./utils/apiError";
8+
import { createClient } from "@supabase/supabase-js";
9+
import config from "./config";
10+
import path from "path";
1211

1312
// Initialize Supabase client for storage operations
1413
export const supabase = createClient(
1514
config.SUPABASE_URL,
16-
config.SUPABASE_SERVICE_ROLE_KEY
17-
)
15+
config.SUPABASE_SERVICE_ROLE_KEY,
16+
);
1817

19-
const app = express()
18+
const app = express();
2019

2120
// 1) Enable CORS for your domains
22-
app.use(cors({
23-
origin: config.ALLOWED_ORIGINS.split(','), // e.g. 'https://club.example.com'
24-
methods: ['GET','POST','PATCH','DELETE','OPTIONS'],
25-
credentials: true,
26-
}))
21+
app.use(
22+
cors({
23+
origin: config.ALLOWED_ORIGINS.split(","), // e.g. 'https://club.example.com'
24+
methods: ["GET", "POST", "PATCH", "DELETE", "OPTIONS"],
25+
credentials: true,
26+
}),
27+
);
2728

2829
// 2) Parse JSON and form data
29-
app.use(json())
30-
app.use(urlencoded({ extended: true }))
30+
app.use(json());
31+
app.use(urlencoded({ extended: true }));
3132

3233
// 3) Handle file uploads (in-memory)
33-
const upload = multer({ storage: multer.memoryStorage() })
34+
const upload = multer({ storage: multer.memoryStorage() });
3435

3536
// 4) Mount your routes, injecting `upload` middleware where needed
3637
// For endpoints that accept file uploads, you can do e.g.:
3738
// router.post('/members/:memberId/photo', upload.single('photo'), ...)
3839

39-
app.use('/api/v1', routes(upload, supabase))
40+
app.use("/api/v1", routes(upload, supabase));
4041

4142
// 5) 404 handler
4243
app.use((req, res) => {
43-
res.status(404).json({ message: 'Not Found' })
44-
})
44+
res.status(404).json({ message: "Not Found" });
45+
});
4546

4647
// 6) Global error handler
47-
app.use(errorHandler)
48+
app.use(errorHandler);
4849

4950
// 7) do 'npm run apidoc to generate the documentation, I have added it in the scripts
5051
// then you can go to localhost:3000/docs to see the docs
51-
app.use('/docs', express.static(path.join(__dirname, '..', 'docs/apidoc')))
52-
export default app
52+
app.use("/docs", express.static(path.join(__dirname, "..", "docs/apidoc")));
53+
export default app;

src/config/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ export default {
44
DIRECT_URL: process.env.DIRECT_URL!,
55
SUPABASE_URL: process.env.SUPABASE_URL!,
66
SUPABASE_SERVICE_ROLE_KEY: process.env.SUPABASE_SERVICE_ROLE_KEY!,
7-
ALLOWED_ORIGINS: process.env.ALLOWED_ORIGINS || '*'
8-
}
7+
ALLOWED_ORIGINS: process.env.ALLOWED_ORIGINS || "*",
8+
};

0 commit comments

Comments
 (0)