Skip to content

Commit 6bbba3a

Browse files
authored
[add] Team model & controller (#10)
1 parent c5c2ef4 commit 6bbba3a

File tree

16 files changed

+294
-60
lines changed

16 files changed

+294
-60
lines changed

.github/workflows/deploy-production.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ jobs:
3030
cat > .env <<EOF
3131
${{ secrets.ENV_FILE }}
3232
EOF
33-
- uses: docker/setup-qemu-action@v2
34-
- uses: docker/setup-buildx-action@v2
33+
- uses: docker/setup-qemu-action@v3
34+
- uses: docker/setup-buildx-action@v3
3535

3636
- name: Build Image
37-
uses: docker/build-push-action@v3
37+
uses: docker/build-push-action@v6
3838
with:
3939
context: .
4040
platforms: linux/amd64

.github/workflows/publish-type.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ jobs:
1010
contents: write
1111
packages: write
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414

15-
- uses: pnpm/action-setup@v2
15+
- uses: pnpm/action-setup@v4
1616
with:
1717
version: 9
18-
- uses: actions/setup-node@v3
18+
- uses: actions/setup-node@v4
1919
with:
20-
node-version: 18
20+
node-version: 20
2121
registry-url: https://npm.pkg.github.com
2222
cache: pnpm
2323
- name: Install, Build & Publish

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Reference: https://pnpm.io/docker#example-1-build-a-bundle-in-a-docker-container
22

3-
FROM node:18-slim AS base
3+
FROM node:20-slim AS base
44
RUN apt-get update && \
55
apt-get install curl -y --no-install-recommends
66
ENV PNPM_HOME="/pnpm"

ReadMe.md

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)][6]
1010
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)][7]
1111

12-
## Feature
12+
## Technology stack
1313

1414
1. HTTP server: [Koa][8]
1515
2. Controller framework: [Routing Controllers][9]
@@ -18,22 +18,39 @@
1818
5. API document: [Swagger][13]
1919
6. Mock API: [OpenAPI backend][14]
2020

21+
## Major features
22+
23+
1. [API entry & Health checking](source/controller/Base.ts)
24+
2. User management
25+
1. [Session](source/controller/User.ts)
26+
2. [OAuth sign in](source/controller/OAuth.ts)
27+
- recommend to use with [Next SSR middleware][15]
28+
3. [Platform Admin](source/controller/Admin.ts)
29+
3. [Activity logging](source/controller/ActivityLog.ts)
30+
4. Hackathon management
31+
1. [Meta](source/controller/Hackathon.ts)
32+
2. [Staff](source/controller/Staff.ts)
33+
3. [Organizer](source/controller/Organizer.ts)
34+
4. [Enrollment](source/controller/Enrollment.ts)
35+
5. Team management
36+
1. [Meta](source/controller/Team.ts)
37+
2138
## Best practice
2239

2340
1. Install GitHub apps in your organization or account:
2441

25-
1. [Probot settings][15]: set up Issue labels & Pull Request rules
26-
2. [PR badge][16]: set up Online [VS Code][17] editor entries in Pull Request description
42+
1. [Probot settings][16]: set up Issue labels & Pull Request rules
43+
2. [PR badge][17]: set up Online [VS Code][18] editor entries in Pull Request description
2744

28-
2. Click the **[<kbd>Use this template</kbd>][18] button** on the top of this GitHub repository's home page, then create your own repository in the app-installed namespace above
45+
2. Click the **[<kbd>Use this template</kbd>][19] button** on the top of this GitHub repository's home page, then create your own repository in the app-installed namespace above
2946

3047
3. Click the **[<kbd>Open in GitHub codespaces</kbd>][8] button** on the top of ReadMe file, then an **online VS Code development environment** will be started immediately
3148

32-
4. Recommend to add a [Notification step in GitHub actions][19] for your Team IM app
49+
4. Recommend to add a [Notification step in GitHub actions][20] for your Team IM app
3350

34-
5. Remind the PMs & users of your product to submit **Feature/Enhancement** requests or **Bug** reports with [Issue forms][20] instead of IM messages or Mobile Phone calls
51+
5. Remind the PMs & users of your product to submit **Feature/Enhancement** requests or **Bug** reports with [Issue forms][21] instead of IM messages or Mobile Phone calls
3552

36-
6. Collect all these issues into [Project kanbans][21], then create **Pull requests** & add `closes #issue_number` into its description for automation
53+
6. Collect all these issues into [Project kanbans][22], then create **Pull requests** & add `closes #issue_number` into its description for automation
3754

3855
## API Usage
3956

@@ -64,7 +81,7 @@ pnpm i
6481
pnpm dev
6582
```
6683

67-
or just press <kbd>F5</kbd> key in [VS Code][17].
84+
or just press <kbd>F5</kbd> key in [VS Code][18].
6885

6986
### Migration
7087

@@ -125,10 +142,11 @@ git push origin master --tags
125142
[12]: https://typeorm.io/
126143
[13]: https://swagger.io/
127144
[14]: https://github.com/anttiviljami/openapi-backend
128-
[15]: https://github.com/apps/settings
129-
[16]: https://pullrequestbadge.com/
130-
[17]: https://code.visualstudio.com/
131-
[18]: https://github.com/new?template_name=openhackathon-service&template_owner=kaiyuanshe
132-
[19]: https://github.com/kaiyuanshe/kaiyuanshe.github.io/blob/bb4675a56bf1d6b207231313da5ed0af7cf0ebd6/.github/workflows/pull-request.yml#L32-L56
133-
[20]: https://github.com/kaiyuanshe/OpenHackathon-service/issues/new/choose
134-
[21]: https://github.com/kaiyuanshe/OpenHackathon-service/projects
145+
[15]: https://github.com/idea2app/Next-SSR-middleware
146+
[16]: https://github.com/apps/settings
147+
[17]: https://pullrequestbadge.com/
148+
[18]: https://code.visualstudio.com/
149+
[19]: https://github.com/new?template_name=openhackathon-service&template_owner=kaiyuanshe
150+
[20]: https://github.com/kaiyuanshe/kaiyuanshe.github.io/blob/bb4675a56bf1d6b207231313da5ed0af7cf0ebd6/.github/workflows/pull-request.yml#L32-L56
151+
[21]: https://github.com/kaiyuanshe/OpenHackathon-service/issues/new/choose
152+
[22]: https://github.com/kaiyuanshe/OpenHackathon-service/projects

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kaiyuanshe/openhackathon-service",
3-
"version": "0.14.0",
3+
"version": "0.15.0",
44
"license": "LGPL-3.0",
55
"author": "shiy2008@gmail.com",
66
"description": "RESTful API service scaffold based on Node.js & TypeScript",
@@ -15,13 +15,12 @@
1515
"source": "source/index.ts",
1616
"main": "dist/index.js",
1717
"engines": {
18-
"node": ">=18"
18+
"node": ">=20"
1919
},
2020
"dependencies": {
2121
"@koa/cors": "^5.0.0",
2222
"@koa/multer": "^3.0.2",
2323
"@koa/router": "^13.0.0",
24-
"@octokit/openapi-types": "^22.2.0",
2524
"class-transformer": "^0.5.1",
2625
"class-validator": "^0.14.1",
2726
"cross-env": "^7.0.3",
@@ -41,21 +40,22 @@
4140
"reflect-metadata": "^0.2.2",
4241
"routing-controllers": "^0.10.4",
4342
"routing-controllers-openapi": "^4.0.0",
44-
"tslib": "^2.6.3",
43+
"tslib": "^2.7.0",
4544
"typeorm": "npm:@helveg/typeorm@^0.3.20",
4645
"web-utility": "^4.4.0"
4746
},
4847
"devDependencies": {
48+
"@octokit/openapi-types": "^22.2.0",
4949
"@types/jsonwebtoken": "^9.0.6",
5050
"@types/koa": "^2.15.0",
5151
"@types/koa-logger": "^3.1.5",
52-
"@types/node": "^18.19.44",
53-
"@typescript-eslint/eslint-plugin": "^8.1.0",
54-
"@typescript-eslint/parser": "^8.1.0",
52+
"@types/node": "^20.16.1",
53+
"@typescript-eslint/eslint-plugin": "^8.2.0",
54+
"@typescript-eslint/parser": "^8.2.0",
5555
"eslint": "^8.57.0",
5656
"eslint-plugin-simple-import-sort": "^12.1.1",
5757
"get-git-folder": "^0.1.2",
58-
"husky": "^9.1.4",
58+
"husky": "^9.1.5",
5959
"lint-staged": "^15.2.9",
6060
"prettier": "^3.3.3",
6161
"sqlite3": "^5.1.7",

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

render.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
healthCheckPath: /_health
99
envVars:
1010
- key: NODE_VERSION
11-
value: 18.20.4
11+
value: 20
1212
- key: NODE_ENV
1313
value: production
1414
- key: DATABASE_URL

source/controller/ActivityLog.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { Get, JsonController, QueryParams } from 'routing-controllers';
1+
import { Get, JsonController, Param, QueryParams } from 'routing-controllers';
22
import { ResponseSchema } from 'routing-controllers-openapi';
3+
import { FindOptionsWhere } from 'typeorm';
34

45
import {
56
ActivityLog,
67
ActivityLogFilter,
78
ActivityLogListChunk,
89
BaseFilter,
910
dataSource,
11+
LogableTable,
1012
Operation,
1113
User,
1214
UserRank,
@@ -66,17 +68,37 @@ export class ActivityLogController {
6668
return { list, count };
6769
}
6870

69-
@Get()
71+
@Get('/user/:id')
7072
@ResponseSchema(ActivityLogListChunk)
71-
async getList({
72-
operation,
73-
tableName,
74-
recordId,
75-
pageSize,
76-
pageIndex
77-
}: ActivityLogFilter) {
73+
getUserList(
74+
@Param('id') id: number,
75+
@QueryParams() { operation, pageSize, pageIndex }: ActivityLogFilter
76+
) {
77+
return this.queryList(
78+
{ operation, createdBy: { id } },
79+
{ pageSize, pageIndex }
80+
);
81+
}
82+
83+
@Get('/:table/:id')
84+
@ResponseSchema(ActivityLogListChunk)
85+
getList(
86+
@Param('table') tableName: keyof typeof LogableTable,
87+
@Param('id') recordId: number,
88+
@QueryParams() { operation, pageSize, pageIndex }: ActivityLogFilter
89+
) {
90+
return this.queryList(
91+
{ operation, tableName, recordId },
92+
{ pageSize, pageIndex }
93+
);
94+
}
95+
96+
async queryList(
97+
where: FindOptionsWhere<ActivityLog>,
98+
{ pageSize, pageIndex }: BaseFilter
99+
) {
78100
const [list, count] = await store.findAndCount({
79-
where: { operation, tableName, recordId },
101+
where,
80102
relations: ['createdBy'],
81103
skip: pageSize * (pageIndex - 1),
82104
take: pageSize

source/controller/Hackathon.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export class HackathonController {
4242
throw new ForbiddenError();
4343
}
4444

45+
static async ensureEnrolled(userId: number, hackathonName: string) {
46+
if (!(await EnrollmentController.isEnrolled(userId, hackathonName)))
47+
throw new ForbiddenError();
48+
}
49+
4550
@Patch('/:name')
4651
@Authorized()
4752
@ResponseSchema(Hackathon)

0 commit comments

Comments
 (0)