Skip to content

Commit

Permalink
feat: add package server
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyao27 committed Apr 25, 2022
1 parent ceaad0b commit 9cd7e14
Show file tree
Hide file tree
Showing 31 changed files with 3,097 additions and 165 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
build
public/build
postgres-data
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "@chenyueban"
"extends": "@chenyueban",
"rules": {
"@typescript-eslint/consistent-type-imports": "off"
}
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# compiled output
dist
node_modules
build
public/build
cypress/screenshots
cypress/videos
tailwind.css

# Logs
logs
Expand Down
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@
"build": "pnpm -r run build",
"docker": "docker-compose up -d",
"dev": "nr docker & pnpm -r run dev",
"setup": "pnpm -r run setup",
"dev:web": "nr docker & pnpm run dev --filter web",
"dev:server": "nr docker & pnpm run dev --filter server",
"setup": "prisma migrate dev && prisma db seed",
"lint": "eslint . --fix",
"prepublishOnly": "nr build",
"test": "pnpm -r run test"
},
"dependencies": {
"@prisma/client": "^3.11.1",
"bcryptjs": "^2.4.3"
},
"devDependencies": {
"@antfu/ni": "^0.14.0",
"@babel/types": "^7.17.0",
Expand All @@ -37,13 +43,20 @@
"@commitlint/cli": "^16.2.3",
"@types/node": "^17.0.26",
"commitizen": "^4.2.4",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.3.0",
"dotenv": "^16.0.0",
"eslint": "^8.14.0",
"esno": "^0.14.1",
"husky": "^7.0.4",
"lint-staged": "^12.4.0",
"prisma": "^3.11.1",
"rimraf": "^3.0.2",
"typescript": "^4.6.3",
"vite": "^2.9.5",
"vitest": "^0.9.4"
},
"prisma": {
"seed": "esno prisma/seed.ts"
}
}
73 changes: 73 additions & 0 deletions packages/server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->

## 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).
5 changes: 5 additions & 0 deletions packages/server/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
63 changes: 63 additions & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "server",
"private": true,
"sideEffects": false,
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"start": "nest start",
"dev": "nest start --watch",
"dev:debug": "nest start --debug --watch",
"dev:prod": "node dist/main",
"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": "^8.4.4",
"@nestjs/core": "^8.4.4",
"@nestjs/mapped-types": "^1.0.1",
"@nestjs/platform-fastify": "^8.4.4",
"@prisma/client": "^3.11.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.5.5"
},
"devDependencies": {
"@nestjs/cli": "^8.2.5",
"@nestjs/schematics": "^8.0.10",
"@nestjs/testing": "^8.4.4",
"@types/express": "^4.17.13",
"@types/jest": "27.4.1",
"@types/supertest": "^2.0.12",
"jest": "^27.5.1",
"prisma": "^3.11.1",
"source-map-support": "^0.5.21",
"supertest": "^6.2.2",
"ts-jest": "^27.1.4",
"ts-loader": "^9.2.8",
"ts-node": "^10.7.0",
"tsconfig-paths": "^3.14.1"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
5 changes: 5 additions & 0 deletions packages/server/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Module } from '@nestjs/common'
import { CatsModule } from './cats/cats.module'

@Module({ imports: [CatsModule] })
export class AppModule {}
21 changes: 21 additions & 0 deletions packages/server/src/cats/cats.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { TestingModule } from '@nestjs/testing'
import { Test } from '@nestjs/testing'
import { CatsController } from './cats.controller'
import { CatsService } from './cats.service'

describe('CatsController', () => {
let controller: CatsController

beforeEach(async() => {
const module: TestingModule = await Test.createTestingModule({
controllers: [CatsController],
providers: [CatsService],
}).compile()

controller = module.get<CatsController>(CatsController)
})

it('should be defined', () => {
expect(controller).toBeDefined()
})
})
34 changes: 34 additions & 0 deletions packages/server/src/cats/cats.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'
import { CatsService } from './cats.service'
import { CreateCatDto } from './dto/create-cat.dto'
import { UpdateCatDto } from './dto/update-cat.dto'

@Controller('cats')
export class CatsController {
constructor(private readonly catsService: CatsService) {}

@Post()
create(@Body() createCatDto: CreateCatDto) {
return this.catsService.create(createCatDto)
}

@Get()
findAll() {
return this.catsService.findAll()
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.catsService.findOne(+id)
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateCatDto: UpdateCatDto) {
return this.catsService.update(+id, updateCatDto)
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.catsService.remove(+id)
}
}
9 changes: 9 additions & 0 deletions packages/server/src/cats/cats.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common'
import { CatsService } from './cats.service'
import { CatsController } from './cats.controller'

@Module({
controllers: [CatsController],
providers: [CatsService],
})
export class CatsModule {}
17 changes: 17 additions & 0 deletions packages/server/src/cats/cats.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { TestingModule } from '@nestjs/testing'
import { Test } from '@nestjs/testing'
import { CatsService } from './cats.service'

describe('CatsService', () => {
let service: CatsService

beforeEach(async() => {
const module: TestingModule = await Test.createTestingModule({ providers: [CatsService] }).compile()

service = module.get<CatsService>(CatsService)
})

it('should be defined', () => {
expect(service).toBeDefined()
})
})
30 changes: 30 additions & 0 deletions packages/server/src/cats/cats.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Injectable } from '@nestjs/common'
import type { CreateCatDto } from './dto/create-cat.dto'
import type { UpdateCatDto } from './dto/update-cat.dto'

@Injectable()
export class CatsService {
create(createCatDto: CreateCatDto) {
console.warn(createCatDto)

return 'This action adds a new cat'
}

findAll() {
return 'This action returns all cats'
}

findOne(id: number) {
return `This action returns a #${id} cat`
}

update(id: number, updateCatDto: UpdateCatDto) {
console.warn(updateCatDto)

return `This action updates a #${id} cat`
}

remove(id: number) {
return `This action removes a #${id} cat`
}
}
1 change: 1 addition & 0 deletions packages/server/src/cats/dto/create-cat.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class CreateCatDto {}
4 changes: 4 additions & 0 deletions packages/server/src/cats/dto/update-cat.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types'
import { CreateCatDto } from './create-cat.dto'

export class UpdateCatDto extends PartialType(CreateCatDto) {}
1 change: 1 addition & 0 deletions packages/server/src/cats/entities/cat.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class Cat {}
22 changes: 22 additions & 0 deletions packages/server/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ValidationPipe } from '@nestjs/common'
import { NestFactory } from '@nestjs/core'
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
import { FastifyAdapter } from '@nestjs/platform-fastify'
import { AppModule } from './app.module'

async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
)

app.useGlobalPipes(new ValidationPipe())

await app.listen(4000, '0.0.0.0')
console.warn(`Application is running on: ${await app.getUrl()}`)
}
bootstrap()
.catch((error) => {
console.error(error)
process.exit(1)
})
23 changes: 23 additions & 0 deletions packages/server/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { TestingModule } from '@nestjs/testing'
import { Test } from '@nestjs/testing'
import type { 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!')
})
})
9 changes: 9 additions & 0 deletions packages/server/test/jest-e2e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}
Loading

0 comments on commit 9cd7e14

Please sign in to comment.