Skip to content

Commit

Permalink
[add] Questionnaire model & controller (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery authored Aug 29, 2024
1 parent b2f9c49 commit 8d27367
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 100 deletions.
3 changes: 2 additions & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
3. [Organizer](source/controller/Organizer.ts)
4. [Announcement](source/controller/Announcement.ts)
5. [Git template](source/controller/GitTemplate.ts)
6. [Enrollment](source/controller/Enrollment.ts)
6. [Questionnaire](source/controller/Questionnaire.ts)
7. [Enrollment](source/controller/Enrollment.ts)
5. Team management
1. [Meta](source/controller/Team.ts)
2. [Member](source/controller/Member.ts)
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kaiyuanshe/openhackathon-service",
"version": "0.19.0",
"version": "0.20.0",
"license": "LGPL-3.0",
"author": "[email protected]",
"description": "RESTful API service scaffold based on Node.js & TypeScript",
Expand All @@ -13,7 +13,6 @@
"@koa/cors": "^5.0.0",
"@koa/multer": "^3.0.2",
"@koa/router": "^13.0.0",
"@octokit/openapi-types": "^22.2.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"cross-env": "^7.0.3",
Expand All @@ -26,9 +25,9 @@
"koa-mount": "^4.0.0",
"koa2-swagger-ui": "^5.10.0",
"koagger": "^0.3.0",
"koajax": "^2.0.0",
"marked": "^14.1.0",
"mobx-restful": "^1.0.0",
"mobx-github": "^0.3.2",
"mobx-restful": "^0.7.0-rc.0",
"pg": "^8.12.0",
"pg-connection-string": "^2.6.4",
"reflect-metadata": "^0.2.2",
Expand Down
93 changes: 45 additions & 48 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 23 additions & 8 deletions source/controller/GitTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RepositoryModel } from 'mobx-github';
import {
Authorized,
Body,
Expand All @@ -18,21 +19,39 @@ import { ResponseSchema } from 'routing-controllers-openapi';
import {
BaseFilter,
dataSource,
GitRepository,
GitTemplate,
GitTemplateListChunk,
Hackathon,
HackathonBase,
User
} from '../model';
import { githubAPI, searchConditionOf } from '../utility';
import { searchConditionOf } from '../utility';
import { ActivityLogController } from './ActivityLog';
import { HackathonController } from './Hackathon';

const store = dataSource.getRepository(GitTemplate),
hackathonStore = dataSource.getRepository(Hackathon);
const repositoryStore = new RepositoryModel();

@JsonController('/hackathon/:name/git-template')
export class GitTemplateController {
static async getRepository(
URI: string
): Promise<Omit<GitTemplate, keyof HackathonBase>> {
const path = URI.replace(
new RegExp(String.raw`^https://github.com/`),
'repos'
);
const repository = await repositoryStore.getOne(path, ['languages']);

const { name, full_name, html_url, default_branch } = repository,
{ languages, topics, description, homepage } = repository;
return {
...{ name, full_name, html_url, default_branch },
...{ languages, topics, description, homepage }
};
}

@Post()
@Authorized()
@HttpCode(201)
Expand All @@ -48,13 +67,9 @@ export class GitTemplateController {

await HackathonController.ensureAdmin(createdBy.id, name);

const path = html_url.replace(
new RegExp(String.raw`^https://github.com`),
'repos'
);
const { body } = await githubAPI.get<GitRepository>(path);
const repository = await GitTemplateController.getRepository(html_url);

const saved = await store.save({ ...body, hackathon, createdBy });
const saved = await store.save({ ...repository, hackathon, createdBy });

await ActivityLogController.logCreate(
createdBy,
Expand Down
6 changes: 3 additions & 3 deletions source/controller/OAuth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { githubClient, User as GitHubUser } from 'mobx-github';
import { Body, JsonController, Post } from 'routing-controllers';
import { ResponseSchema } from 'routing-controllers-openapi';
import { isDeepStrictEqual } from 'util';

import { dataSource, GitHubUser, OAuthSignInData, User } from '../model';
import { githubAPI } from '../utility';
import { dataSource, OAuthSignInData, User } from '../model';
import { ActivityLogController } from './ActivityLog';
import { UserController } from './User';

Expand All @@ -14,7 +14,7 @@ export class OauthController {
@Post('/GitHub')
@ResponseSchema(User)
async signInWithGithub(@Body() { accessToken }: OAuthSignInData) {
const { body } = await githubAPI.get<GitHubUser>('user', {
const { body } = await githubClient.get<GitHubUser>('user', {
Authorization: `Bearer ${accessToken}`
});
const { email, login, avatar_url } = body!;
Expand Down
Loading

0 comments on commit 8d27367

Please sign in to comment.