├── .github
└── workflows
│ ├── deploy-org.yml
│ └── precheck.yml
└── organizations
├── .eslintrc.js
├── .gitignore
├── .prettierrc
├── Dockerfile
├── README.md
├── nest-cli.json
├── package-lock.json
├── package.json
├── src
├── app.module.ts
├── main.ts
└── posts
│ ├── dto
│ ├── create-post.dto.ts
│ └── update-post.dto.ts
│ ├── entities
│ └── post.entity.ts
│ ├── posts.controller.ts
│ ├── posts.module.ts
│ └── posts.service.ts
├── test
├── app.e2e-spec.ts
└── jest-e2e.json
├── tsconfig.build.json
└── tsconfig.json
/.github/workflows/deploy-org.yml:
--------------------------------------------------------------------------------
1 | name: Deployment (DEV)
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | paths:
8 | - organizations/**
9 | workflow_dispatch:
10 |
11 | jobs:
12 | build:
13 | runs-on: ubuntu-latest
14 | steps:
15 | - name: Checkout code
16 | uses: actions/checkout@v3
17 |
18 | - name: Set up Docker Buildx
19 | uses: docker/setup-buildx-action@v2
20 |
21 | - name: Login to GitHub Container Registry
22 | uses: docker/login-action@v3
23 | with:
24 | registry: ghcr.io
25 | username: ${{ github.actor }}
26 | password: ${{ secrets.GITHUB_TOKEN }}
27 |
28 | - name: Push Docker image to GHCR
29 | uses: docker/build-push-action@v4
30 | with:
31 | context: organizations/
32 | push: true
33 | tags: ghcr.io/${{ github.repository }}:latest
34 |
35 | # deploy:
36 | # needs: [build]
37 |
38 | # runs-on: ubuntu-latest
39 |
40 | # steps:
41 | # - name: Deploy to Remote Server
42 | # uses: appleboy/ssh-action@master
43 | # with:
44 | # host: ${{ secrets.DEV_SSH_HOST }}
45 | # username: ${{ secrets.DEV_SSH_USERNAME }}
46 | # password: ${{ secrets.DEV_SSH_PASSWORD }}
47 | # script: |
48 | # echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
49 | # docker rm $(docker stop $(docker ps -a -q --filter ancestor=ghcr.io/${{ github.repository }}))
50 | # docker rmi ghcr.io/${{ github.repository }}
51 | # docker pull ghcr.io/${{ github.repository }}:latest
52 | # docker run -d --name daniconfigs-api --network nginxproxymanager_default --restart unless-stopped ghcr.io/${{ github.repository }}:latest
--------------------------------------------------------------------------------
/.github/workflows/precheck.yml:
--------------------------------------------------------------------------------
1 | name: PRs testing
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - master
7 | paths:
8 | - organizations/**
9 |
10 | jobs:
11 | installation:
12 | runs-on: ubuntu-latest
13 |
14 | strategy:
15 | matrix:
16 | node-version: [18.x]
17 |
18 | steps:
19 | - name: Checkout code
20 | uses: actions/checkout@v3
21 |
22 | - name: Set up Node.js
23 | uses: actions/setup-node@v4
24 | with:
25 | node-version: ${{ matrix.node-version }}
26 |
27 | - name: Install dependencies
28 | run: cd organizations && npm ci
29 |
30 | # - name: Eslint check
31 | # run: cd organizations && npx eslint . --fix
32 |
33 | # - name: Prettify
34 | # run: cd organizations && npx prettier . --write
35 |
36 | # - name: Test
37 | # run: cd organizations && npm run test
38 |
39 | # - name: Build
40 | # run: cd organizations && npm run builds
--------------------------------------------------------------------------------
/organizations/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | parser: '@typescript-eslint/parser',
3 | parserOptions: {
4 | project: 'tsconfig.json',
5 | tsconfigRootDir: __dirname,
6 | sourceType: 'module',
7 | },
8 | plugins: ['@typescript-eslint/eslint-plugin'],
9 | extends: [
10 | 'plugin:@typescript-eslint/recommended',
11 | 'plugin:prettier/recommended',
12 | ],
13 | root: true,
14 | env: {
15 | node: true,
16 | jest: true,
17 | },
18 | ignorePatterns: ['.eslintrc.js'],
19 | rules: {
20 | '@typescript-eslint/interface-name-prefix': 'off',
21 | '@typescript-eslint/explicit-function-return-type': 'off',
22 | '@typescript-eslint/explicit-module-boundary-types': 'off',
23 | '@typescript-eslint/no-explicit-any': 'off',
24 | },
25 | };
26 |
--------------------------------------------------------------------------------
/organizations/.gitignore:
--------------------------------------------------------------------------------
1 | # compiled output
2 | /dist
3 | /node_modules
4 | /build
5 |
6 | # Logs
7 | logs
8 | *.log
9 | npm-debug.log*
10 | pnpm-debug.log*
11 | yarn-debug.log*
12 | yarn-error.log*
13 | lerna-debug.log*
14 |
15 | # OS
16 | .DS_Store
17 |
18 | # Tests
19 | /coverage
20 | /.nyc_output
21 |
22 | # IDEs and editors
23 | /.idea
24 | .project
25 | .classpath
26 | .c9/
27 | *.launch
28 | .settings/
29 | *.sublime-workspace
30 |
31 | # IDE - VSCode
32 | .vscode/*
33 | !.vscode/settings.json
34 | !.vscode/tasks.json
35 | !.vscode/launch.json
36 | !.vscode/extensions.json
37 |
38 | # dotenv environment variable files
39 | .env
40 | .env.development.local
41 | .env.test.local
42 | .env.production.local
43 | .env.local
44 |
45 | # temp directory
46 | .temp
47 | .tmp
48 |
49 | # Runtime data
50 | pids
51 | *.pid
52 | *.seed
53 | *.pid.lock
54 |
55 | # Diagnostic reports (https://nodejs.org/api/report.html)
56 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
57 |
--------------------------------------------------------------------------------
/organizations/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "trailingComma": "all"
4 | }
--------------------------------------------------------------------------------
/organizations/Dockerfile:
--------------------------------------------------------------------------------
1 | # stage1: production build
2 | FROM node:18 as bulid
3 |
4 | # Create app directory
5 | WORKDIR /usr/src/app
6 |
7 | # Install app dependencies
8 | # A wildcard is used to ensure both package.json AND package-lock.json are copied
9 | COPY package*.json ./
10 |
11 | # Install Google Chrome Stable and fonts
12 | # Note: this installs the necessary libs to make the browser work with Puppeteer.
13 | RUN apt-get update && apt-get install curl gnupg -y \
14 | && curl --location --silent https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
15 | && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
16 | && apt-get update \
17 | && apt-get install google-chrome-stable -y --no-install-recommends \
18 | && rm -rf /var/lib/apt/lists/*
19 |
20 | RUN npm ci
21 |
22 | # Bundle app source
23 | COPY . .
24 |
25 | # Build the nestjs
26 | RUN npm run build
27 | EXPOSE 3005
28 | CMD [ "node", "dist/main" ]
--------------------------------------------------------------------------------
/organizations/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | [circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
6 | [circleci-url]: https://circleci.com/gh/nestjs/nest
7 |
8 | A progressive Node.js framework for building efficient and scalable server-side applications.
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
24 |
25 | ## Description
26 |
27 | [Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
28 |
29 | ## Installation
30 |
31 | ```bash
32 | $ npm install
33 | ```
34 |
35 | ## Running the app
36 |
37 | ```bash
38 | # development
39 | $ npm run start
40 |
41 | # watch mode
42 | $ npm run start:dev
43 |
44 | # production mode
45 | $ npm run start:prod
46 | ```
47 |
48 | ## Test
49 |
50 | ```bash
51 | # unit tests
52 | $ npm run test
53 |
54 | # e2e tests
55 | $ npm run test:e2e
56 |
57 | # test coverage
58 | $ npm run test:cov
59 | ```
60 |
61 | ## Support
62 |
63 | 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).
64 |
65 | ## Stay in touch
66 |
67 | - Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
68 | - Website - [https://nestjs.com](https://nestjs.com/)
69 | - Twitter - [@nestframework](https://twitter.com/nestframework)
70 |
71 | ## License
72 |
73 | Nest is [MIT licensed](LICENSE).
74 |
--------------------------------------------------------------------------------
/organizations/nest-cli.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/nest-cli",
3 | "collection": "@nestjs/schematics",
4 | "sourceRoot": "src",
5 | "compilerOptions": {
6 | "deleteOutDir": true
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/organizations/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nest-mongodb",
3 | "version": "0.0.2",
4 | "description": "",
5 | "author": "",
6 | "private": true,
7 | "license": "UNLICENSED",
8 | "scripts": {
9 | "build": "nest build",
10 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
11 | "start": "nest start",
12 | "start:dev": "nest start --watch",
13 | "start:debug": "nest start --debug --watch",
14 | "start:prod": "node dist/main",
15 | "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
16 | "test": "jest",
17 | "test:watch": "jest --watch",
18 | "test:cov": "jest --coverage",
19 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
20 | "test:e2e": "jest --config ./test/jest-e2e.json"
21 | },
22 | "dependencies": {
23 | "@nestjs/common": "^10.0.0",
24 | "@nestjs/core": "^10.3.3",
25 | "@nestjs/mapped-types": "*",
26 | "@nestjs/platform-express": "^10.0.0",
27 | "@nestjs/swagger": "^7.3.0",
28 | "@nestjs/typeorm": "^10.0.2",
29 | "class-validator": "^0.14.1",
30 | "mongodb": "^5.9.2",
31 | "reflect-metadata": "^0.2.0",
32 | "rxjs": "^7.8.1",
33 | "typeorm": "^0.3.20"
34 | },
35 | "devDependencies": {
36 | "@nestjs/cli": "^10.0.0",
37 | "@nestjs/schematics": "^10.0.0",
38 | "@nestjs/testing": "^10.0.0",
39 | "@types/express": "^4.17.17",
40 | "@types/jest": "^29.5.2",
41 | "@types/node": "^20.3.1",
42 | "@types/supertest": "^6.0.0",
43 | "@typescript-eslint/eslint-plugin": "^6.0.0",
44 | "@typescript-eslint/parser": "^6.0.0",
45 | "eslint": "^8.42.0",
46 | "eslint-config-prettier": "^9.0.0",
47 | "eslint-plugin-prettier": "^5.0.0",
48 | "jest": "^29.5.0",
49 | "prettier": "^3.0.0",
50 | "source-map-support": "^0.5.21",
51 | "supertest": "^6.3.3",
52 | "ts-jest": "^29.1.0",
53 | "ts-loader": "^9.4.3",
54 | "ts-node": "^10.9.1",
55 | "tsconfig-paths": "^4.2.0",
56 | "typescript": "^5.1.3"
57 | },
58 | "jest": {
59 | "moduleFileExtensions": [
60 | "js",
61 | "json",
62 | "ts"
63 | ],
64 | "rootDir": "src",
65 | "testRegex": ".*\\.spec\\.ts$",
66 | "transform": {
67 | "^.+\\.(t|j)s$": "ts-jest"
68 | },
69 | "collectCoverageFrom": [
70 | "**/*.(t|j)s"
71 | ],
72 | "coverageDirectory": "../coverage",
73 | "testEnvironment": "node"
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/organizations/src/app.module.ts:
--------------------------------------------------------------------------------
1 | import { Module } from '@nestjs/common';
2 | import { PostsModule } from './posts/posts.module';
3 | import { TypeOrmModule } from '@nestjs/typeorm';
4 | import { Post } from './posts/entities/post.entity';
5 |
6 | @Module({
7 | imports: [
8 | TypeOrmModule.forRoot({
9 | type: 'mongodb',
10 | host: '127.0.0.1',
11 | port: 27017,
12 | database: 'app',
13 | synchronize: true,
14 | entities: [Post],
15 | useUnifiedTopology: true,
16 | useNewUrlParser: true,
17 | }),
18 | PostsModule,
19 | ],
20 | })
21 | export class AppModule {}
22 |
--------------------------------------------------------------------------------
/organizations/src/main.ts:
--------------------------------------------------------------------------------
1 | import { NestFactory } from '@nestjs/core';
2 | import { AppModule } from './app.module';
3 | import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
4 |
5 | async function bootstrap() {
6 | const app = await NestFactory.create(AppModule);
7 |
8 | const config = new DocumentBuilder()
9 | .setTitle(
10 | 'Example Code (Nestjs + MongoDB + DTO + Entities + TypeORM + Swagger)',
11 | )
12 | .setDescription('The CRUD APIs Description')
13 | .addServer('http://localhost:3000/', 'Local Environment')
14 | .setVersion('1.0')
15 | .addTag('APIs')
16 | .build();
17 | const document = SwaggerModule.createDocument(app, config);
18 | SwaggerModule.setup('api-docs', app, document);
19 | await app.listen(3000);
20 | }
21 | bootstrap();
22 |
--------------------------------------------------------------------------------
/organizations/src/posts/dto/create-post.dto.ts:
--------------------------------------------------------------------------------
1 | // /nest-todo-app/src/todo/dto/create-todo.dto.ts
2 | import { ApiProperty } from '@nestjs/swagger';
3 | import { IsNotEmpty, MinLength } from 'class-validator';
4 |
5 | export class CreatePostDto {
6 | @ApiProperty({
7 | example: 'Please input title',
8 | required: true,
9 | })
10 | @IsNotEmpty()
11 | readonly title: string;
12 |
13 | @ApiProperty({
14 | example: 'Please input text',
15 | required: true,
16 | })
17 | @IsNotEmpty()
18 | @MinLength(10)
19 | readonly content: string;
20 | }
21 |
--------------------------------------------------------------------------------
/organizations/src/posts/dto/update-post.dto.ts:
--------------------------------------------------------------------------------
1 | import { PartialType } from '@nestjs/mapped-types';
2 | import { CreatePostDto } from './create-post.dto';
3 | import { ApiProperty } from '@nestjs/swagger';
4 |
5 | export class UpdatePostDto extends PartialType(CreatePostDto) {
6 | @ApiProperty({
7 | example: 'Please input title',
8 | })
9 | readonly title: string;
10 |
11 | @ApiProperty({
12 | example: 'Please input content',
13 | })
14 | readonly content: string;
15 | readonly updatedAt: Date;
16 | readonly createdAt: Date;
17 | }
18 |
--------------------------------------------------------------------------------
/organizations/src/posts/entities/post.entity.ts:
--------------------------------------------------------------------------------
1 | import { Column, Entity, ObjectIdColumn } from 'typeorm';
2 | import { ObjectId } from 'mongodb';
3 |
4 | @Entity()
5 | export class Post {
6 | @ObjectIdColumn({ name: '_id' })
7 | _id: ObjectId;
8 |
9 | @Column()
10 | title: string;
11 |
12 | @Column()
13 | content: string;
14 |
15 | @Column({ default: false })
16 | isPublished: boolean;
17 |
18 | @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
19 | createdAt: Date;
20 |
21 | @Column({ type: 'timestamp', default: null, nullable: true })
22 | updatedAt: Date;
23 | }
24 |
--------------------------------------------------------------------------------
/organizations/src/posts/posts.controller.ts:
--------------------------------------------------------------------------------
1 | import {
2 | Controller,
3 | Get,
4 | Post,
5 | Body,
6 | Patch,
7 | Param,
8 | Delete,
9 | } from '@nestjs/common';
10 | import { ObjectId } from 'mongodb';
11 | import { PostsService } from './posts.service';
12 | import { Post as PostEntity } from './entities/post.entity';
13 | import { CreatePostDto } from './dto/create-post.dto';
14 | import { UpdatePostDto } from './dto/update-post.dto';
15 |
16 | @Controller('posts')
17 | export class PostsController {
18 | constructor(private readonly postsService: PostsService) {}
19 |
20 | @Post()
21 | create(@Body() post: CreatePostDto): Promise {
22 | return this.postsService.create(post);
23 | }
24 |
25 | @Get()
26 | findAll() {
27 | return this.postsService.findAll();
28 | }
29 |
30 | @Get(':id')
31 | findOne(@Param('id') id: string) {
32 | return this.postsService.findOne(new ObjectId(id));
33 | }
34 |
35 | @Patch(':id')
36 | update(
37 | @Param('id') id: string,
38 | @Body() updatePostDto: UpdatePostDto,
39 | ): Promise {
40 | return this.postsService.update(new ObjectId(id), updatePostDto);
41 | }
42 |
43 | @Delete(':id')
44 | remove(@Param('id') id: string) {
45 | return this.postsService.remove(new ObjectId(id));
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/organizations/src/posts/posts.module.ts:
--------------------------------------------------------------------------------
1 | import { Module } from '@nestjs/common';
2 | import { PostsService } from './posts.service';
3 | import { PostsController } from './posts.controller';
4 | import { TypeOrmModule } from '@nestjs/typeorm';
5 | import { Post } from './entities/post.entity';
6 |
7 | @Module({
8 | imports: [TypeOrmModule.forFeature([Post])],
9 | controllers: [PostsController],
10 | providers: [PostsService],
11 | })
12 | export class PostsModule {}
13 |
--------------------------------------------------------------------------------
/organizations/src/posts/posts.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@nestjs/common';
2 | import { InjectRepository } from '@nestjs/typeorm';
3 | import { Repository } from 'typeorm';
4 | import { ObjectId } from 'mongodb';
5 | import { Post } from './entities/post.entity';
6 | import { CreatePostDto } from './dto/create-post.dto';
7 | import { UpdatePostDto } from './dto/update-post.dto';
8 |
9 | @Injectable()
10 | export class PostsService {
11 | constructor(
12 | @InjectRepository(Post)
13 | private readonly postRepository: Repository,
14 | ) {}
15 |
16 | async create(post: CreatePostDto): Promise {
17 | return await this.postRepository.save(post);
18 | }
19 |
20 | async findAll(): Promise {
21 | return await this.postRepository.find();
22 | }
23 |
24 | async findOne(id: ObjectId): Promise {
25 | const object = await this.postRepository.findOneBy({ _id: id });
26 | console.log(object);
27 | return object;
28 | // return id;
29 | }
30 |
31 | async update(
32 | id: ObjectId,
33 | updatePostDto: UpdatePostDto,
34 | ): Promise {
35 | await this.postRepository.update(id, updatePostDto);
36 | return this.postRepository.findOneBy({ _id: id });
37 | }
38 |
39 | async remove(id: ObjectId): Promise {
40 | const postToRemove = await this.postRepository.find({ where: { _id: id } });
41 | if (!postToRemove) {
42 | throw new Error('Post new Error');
43 | }
44 | return await this.postRepository.remove(postToRemove);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/organizations/test/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { Test, TestingModule } from '@nestjs/testing';
2 | import { INestApplication } from '@nestjs/common';
3 | import * as request from 'supertest';
4 | import { AppModule } from './../src/app.module';
5 |
6 | describe('AppController (e2e)', () => {
7 | let app: INestApplication;
8 |
9 | beforeEach(async () => {
10 | const moduleFixture: TestingModule = await Test.createTestingModule({
11 | imports: [AppModule],
12 | }).compile();
13 |
14 | app = moduleFixture.createNestApplication();
15 | await app.init();
16 | });
17 |
18 | it('/ (GET)', () => {
19 | return request(app.getHttpServer())
20 | .get('/')
21 | .expect(200)
22 | .expect('Hello World!');
23 | });
24 | });
25 |
--------------------------------------------------------------------------------
/organizations/test/jest-e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "moduleFileExtensions": ["js", "json", "ts"],
3 | "rootDir": ".",
4 | "testEnvironment": "node",
5 | "testRegex": ".e2e-spec.ts$",
6 | "transform": {
7 | "^.+\\.(t|j)s$": "ts-jest"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/organizations/tsconfig.build.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
4 | }
5 |
--------------------------------------------------------------------------------
/organizations/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "declaration": true,
5 | "removeComments": true,
6 | "emitDecoratorMetadata": true,
7 | "experimentalDecorators": true,
8 | "allowSyntheticDefaultImports": true,
9 | "target": "ES2021",
10 | "sourceMap": true,
11 | "outDir": "./dist",
12 | "baseUrl": "./",
13 | "incremental": true,
14 | "skipLibCheck": true,
15 | "strictNullChecks": false,
16 | "noImplicitAny": false,
17 | "strictBindCallApply": false,
18 | "forceConsistentCasingInFileNames": false,
19 | "noFallthroughCasesInSwitch": false
20 | }
21 | }
22 |
--------------------------------------------------------------------------------