Commit 13105d63 authored by nanahira's avatar nanahira

things to solve

parents
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/data
/output
/config.yaml
.git*
Dockerfile
.dockerignore
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/data
/output
/config.yaml
stages:
- build
- combine
- deploy
variables:
GIT_DEPTH: "1"
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_TEST_ARM_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
CONTAINER_TEST_X86_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build-x86:
stage: build
tags:
- docker
script:
- docker build --pull -t $CONTAINER_TEST_X86_IMAGE .
- docker push $CONTAINER_TEST_X86_IMAGE
build-arm:
stage: build
tags:
- docker-arm
script:
- docker build --pull -t $CONTAINER_TEST_ARM_IMAGE .
- docker push $CONTAINER_TEST_ARM_IMAGE
combine:
stage: combine
tags:
- docker
script:
- docker pull $CONTAINER_TEST_X86_IMAGE
- docker pull $CONTAINER_TEST_ARM_IMAGE
- docker manifest create $CONTAINER_TEST_IMAGE --amend $CONTAINER_TEST_X86_IMAGE --amend $CONTAINER_TEST_ARM_IMAGE
- docker manifest push $CONTAINER_TEST_IMAGE
deploy_latest:
stage: deploy
tags:
- docker
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE
only:
- master
deploy_tag:
stage: deploy
tags:
- docker
variables:
CONTAINER_TAG_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_TAG_IMAGE
- docker push $CONTAINER_TAG_IMAGE
only:
- tags
/install-npm.sh
.git*
/output
/dest
/config.yaml
.idea
.dockerignore
Dockerfile
\ No newline at end of file
{
"singleQuote": true,
"trailingComma": "all"
}
\ No newline at end of file
FROM node:buster-slim
LABEL Author="Nanahira <nanahira@momobako.com>"
RUN apt update && apt -y install python3 build-essential && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /usr/src/app
COPY ./package*.json ./
RUN npm ci
COPY . ./
RUN npm run build
CMD ["npm", "run", "start:prod"]
This diff is collapsed.
# cxcy-scoresheet
Chuangxinchuangye scoresheet PDF generator.
## Description
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
## Installation
```bash
$ npm install
```
## Running the app
```bash
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
```
## Test
```bash
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
```
## Support
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
## Stay in touch
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)
## License
Nest is [MIT licensed](LICENSE).
{
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
This diff is collapsed.
{
"name": "cxcy-scoresheet",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^7.5.1",
"@nestjs/core": "^7.5.1",
"@nestjs/platform-express": "^7.5.1",
"md-to-pdf": "^3.3.2",
"mustache": "^4.2.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.6.3"
},
"devDependencies": {
"@nestjs/cli": "^7.5.1",
"@nestjs/schematics": "^7.1.3",
"@nestjs/testing": "^7.5.1",
"@types/express": "^4.17.11",
"@types/jest": "^26.0.15",
"@types/mustache": "^4.1.1",
"@types/node": "^14.14.6",
"@types/supertest": "^2.0.10",
"@typescript-eslint/eslint-plugin": "^4.6.1",
"@typescript-eslint/parser": "^4.6.1",
"eslint": "^7.12.1",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.6.3",
"prettier": "^2.1.2",
"supertest": "^6.0.0",
"ts-jest": "^26.4.3",
"ts-loader": "^8.0.8",
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.0.5"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
# 创新创业成绩单
## 基本资料
* 学号: {{id}}
* 姓名: {{name}}
{{#sex}}
* 性别: {{sex}}
{{/sex}}
{{#collegeString}}
* 学院: {{collegeString}}
{{/collegeString}}
{{#professionString}}
* 专业: {{professionString}}
{{/professionString}}
## 项目经历
{{#projects}}
* {{.name}}
{{/projects}}
## 论文
{{#theses}}
* {{.name}}
{{/theses}}
## 专利
{{#patents}}
* {{.name}}
{{/patents}}
## 竞赛
{{#competitions}}
* {{.name}}
{{/competitions}}
\ No newline at end of file
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
/* it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
}); */
});
});
import { Body, Controller, Get, Post, Query, Res } from '@nestjs/common';
import { AppService, ScoreSheetData } from './app.service';
import { Response } from 'express';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get('report.pdf')
async getPdf(@Query('data') dataRaw: string, @Res() res: Response) {
let data: any;
try {
data = JSON.parse(dataRaw);
} catch (e) {
res.status(400).end('bad JSON');
return;
}
const pdf = await this.appService.getPdf(data);
res.set({
'Content-Type': 'application/pdf',
'Content-Disposition': `attachment; filename=${data.id}-${data.name}.pdf`,
'Content-Length': pdf.length,
// prevent cache
'Cache-Control': 'no-cache, no-store, must-revalidate',
Pragma: 'no-cache',
Expires: 0,
});
res.end(pdf);
}
}
import { Injectable, Scope, Logger } from '@nestjs/common';
@Injectable()
export class AppLogger extends Logger {}
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AppLogger } from './app.logger';
@Module({
imports: [],
controllers: [AppController],
providers: [AppService, AppLogger],
})
export class AppModule {}
import { Injectable } from '@nestjs/common';
import { AppLogger } from './app.logger';
import mustache from 'mustache';
import * as fs from 'fs';
import mdToPdf from 'md-to-pdf';
export interface NameWise {
name: string;
}
export interface ScoreSheetData {
name: string;
sex: string;
id: string;
collegeString: string;
professionString: string;
projects: NameWise[];
theses: NameWise[];
patents: NameWise[];
}
@Injectable()
export class AppService {
template: string;
constructor(private log: AppLogger) {
this.log.setContext('app');
this.template = fs.readFileSync('./report.md.mustache', 'utf8');
}
async getPdf(data: ScoreSheetData) {
this.log.log(data);
const renderedMarkdownContent = mustache.render(this.template, data, null, {
escape: (v) => v,
});
this.log.log(renderedMarkdownContent);
const { content } = await mdToPdf({ content: renderedMarkdownContent });
return content;
}
}
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors();
await app.listen(3000);
}
bootstrap();
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';
describe('AppController (e2e)', () => {
let app: INestApplication;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
/* it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
}); */
});
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}
{
"createTime": "2021-04-27 03:47:54",
"updateTime": "2021-04-27 03:47:57",
"status": 1,
"name": "Koral",
"id": "3118006867",
"sex": "男",
"email": null,
"mobile": null,
"password": null,
"grade": 3,
"professionId": null,
"professionString": "数学与应用数学",
"collegeString": "应用数学学院",
"role": null,
"profession": null,
"projects": [
{
"createTime": "2021-05-07 20:59:28",
"updateTime": "2021-05-07 13:06:27",
"status": 0,
"name": "创新创业网站",
"id": 1,
"type": "大创",
"startDate": "2021-05-07 20:58:17",
"startDateFrom": null,
"startDateTo": null,
"isAuthoritativeApplication": false,
"isGovermentEnterpriseApplication": false,
"solvedProblem": "各个学校办事处功能整合",
"students": null,
"teachers": null,
"companies": null,
"keyTech": null,
"reserchArea": null,
"patents": null,
"role": "_leader",
"deleted": false
}
],
"patents": [
{
"createTime": "2021-05-07 21:33:40",
"updateTime": "2021-05-07 13:37:45",
"status": 0,
"name": "创新创业网站",
"id": 1,
"createdRole": 4,
"createdUserId": "3118006867",
"type": "实用新型",
"patentNumber": "20210507000000",
"applyTime": "2021-05-07 21:33:33",
"applyTimeFrom": null,
"applyTimeTo": null,
"authorizeTime": "2021-05-07 21:33:31",
"authorizeTimeFrom": null,
"authorizeTimeTo": null,
"students": null,
"teachers": null,
"projects": null,
"role": "_leader",
"deleted": false
}
],
"competitions": [
{
"createTime": "2021-05-08 04:39:03",
"updateTime": "2021-05-08 04:39:05",
"status": 0,
"name": "数模校赛",
"id": 1,
"createdRole": 4,
"createdUserId": "3118006867",
"awardYearMonth": "2021-05-08 04:38:34",
"awardYearMonthFrom": null,
"awardYearMonthTo": null,
"awardOrganization": "学校",
"organizationType": "学校",
"college": "应数",
"awardWorks": "基于电视广告推送与竞卖的建模研究",
"competitionLevel": "校级",
"awardLevel": "一等奖",
"students": null,
"teachers": null,
"theses": null,
"role": "1",
"deleted": false
}
],
"theses": [
{
"createTime": "2021-05-07 20:59:06",
"updateTime": "2021-05-07 20:59:06",
"status": 0,
"name": "基于电视广告推送与竞卖的建模研究",
"id": 1,
"createdRole": 4,
"createdUserId": "3118006867",
"college": "应用数学",
"publicationName": "SCI",
"publicationLevel": "SCI一期",
"publicDate": "2021-05-07 20:58:09",
"publicDateFrom": null,
"publicDateTo": null,
"submissionDate": "2021-05-07 20:58:09",
"submissionDateFrom": null,
"submissionDateTo": null,
"competitions": null,
"students": null,
"teachers": null,
"role": "1",
"deleted": false
}
],
"enabled": true,
"deleted": false
}
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"esModuleInterop": true
},
"compileOnSave": true,
"allowJs": true
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment