Skip to content

Commit

Permalink
Merge pull request #72 from ItaloRAmaral/69-core-definir-schema-do-pr…
Browse files Browse the repository at this point in the history
…isma

Feature(CC-69): create psychologist endpoint and it's related methods and files
  • Loading branch information
luanavfg authored Oct 19, 2023
2 parents 7392a26 + 9243b71 commit 5d50b2a
Show file tree
Hide file tree
Showing 118 changed files with 4,570 additions and 2,965 deletions.
26 changes: 25 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
# Nx Cloud
NX_CLOUD_ACCESS_TOKEN="fake-token"

######### Aplication #########

# Environment
NODE_ENV="development"
PORT=3333

# Auth
JWT_SECRET="secret"
API_KEY="api-key"
JWT_PRIVATE_KEY=

JWT_PUBLIC_KEY=

######### Database #########

# PostegreSQL Prisma
POSTGRES_USER=cliniccontrol
POSTGRES_PASSWORD=cliniccontrolpassword
POSTGRES_DB=core-rest-api
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_SCHEMA=public

DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}?schema=${POSTGRES_SCHEMA}
63 changes: 31 additions & 32 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
name: 'CodeQL'

on:
push:
branches: [ "main" ]
branches: ['main']
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
branches: ['main']
schedule:
- cron: '22 1 * * 0'

Expand All @@ -38,45 +38,44 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
language: ['javascript']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: '/language:${{matrix.language}}'
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: 'Dependency Review'
uses: actions/dependency-review-action@v3
28 changes: 26 additions & 2 deletions .github/workflows/tests-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ env:
jobs:
tests-pipeline:
runs-on: ubuntu-latest
env:
JWT_PRIVATE_KEY: ${{ secrets.JWT_PRIVATE_KEY }}
JWT_PUBLIC_KEY: ${{ secrets.JWT_PUBLIC_KEY }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
POSTGRES_SCHEMA: ${{ secrets.POSTGRES_SCHEMA }}
API_KEY: ${{ secrets.API_KEY }}

defaults:
run:
working-directory: ${{ github.workspace }}

steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PNPM
uses: pnpm/[email protected]
Expand All @@ -30,5 +39,20 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Run tests
- name: Set up environment variables
run: |
echo "DATABASE_URL=postgresql://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@localhost:5432/${{ secrets.POSTGRES_DB }}?schema=${{ secrets.POSTGRES_SCHEMA }}" >> $GITHUB_ENV
- name: Setting up docker compose
run: docker compose up -d

- name: Setting up prisma postgresql database
run: |
pnpm run prisma:core:schema:generate
pnpm run prisma:core:schema:migrate
- name: Run E2E Tests
run: pnpm run test:e2e

- name: Run Unit Tests
run: pnpm run test:unit
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ testem.log
Thumbs.db

# Next.js
.next
.next

data
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit "$1"
npx --yes -- commitlint --edit "$1"
5 changes: 4 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm test:unit
echo "Husky pre commit script..."
echo "Running Unit Tests..."

pnpm run test:unit
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"singleQuote": true
"singleQuote": true,
"printWidth": 90
}
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@
"editor.formatOnSave": true,
"cSpell.words": [
"Amaral",
"cacheable",
"cliniccontrol",
"CODEOWNERS",
"commitlint",
"conventionalcommits",
"CQRS",
"github",
"GITHUB",
"instanceof",
"italo",
"keyof",
"Luana",
"nestjs",
"postgre",
"Postgre",
"postgresql",
"Postgresql",
"preid",
"Rockenbach",
"unplugin",
"Vefago"
],
"cSpell.language": "en,pt-BR"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,5 @@ Distributed under the MIT License. See [LICENSE](https://github.com/italoRAmaral
- [Explore](https://github.com/amaralc/explore)
- [DDD Hexagonal CQRS ES EDA](https://github.com/bitloops/ddd-hexagonal-cqrs-es-eda)
- [Domain Driven Hexagon](https://github.com/Sairyss/domain-driven-hexagon)

.
4 changes: 2 additions & 2 deletions apps/core-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"email": "[email protected]"
},
{
"name": "Luana Vefago",
"email": ""
"name": "Luana Vefago dos Santos",
"email": "[email protected]"
}
]
}
7 changes: 0 additions & 7 deletions apps/core-rest-api/src/guards/api-key.guard.spec.ts

This file was deleted.

11 changes: 0 additions & 11 deletions apps/core-rest-api/src/guards/api-key.guard.ts

This file was deleted.

29 changes: 16 additions & 13 deletions apps/core-rest-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
* This is not a production server yet!
* This is only a minimal backend to get started.
*/
import { Logger, ValidationPipe, INestApplication } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { version } from '@clinicControl/root/package.json';
import { INestApplication, Logger, ValidationPipe, VersioningType } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { version } from "@clinicControl/root/package.json"

import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

import { AppModule } from './app/app.module';
import { ApiModule } from '@clinicControl/core-rest-api/adapters/src/controllers/api/api.module';
import { EnvService } from '@clinicControl/core-rest-api/adapters/src/env/env.service';

const setupOpenApi = (app: INestApplication) => {
// Setting up Swagger document
const options = new DocumentBuilder()
.setTitle('Clinic Controll Restful API')
.setDescription('Clinic Controll Restful API')
.setTitle('Clinic Control Restful API')
.setDescription('Clinic Control Restful API')
.setVersion(version)
.build();

Expand All @@ -23,8 +23,8 @@ const setupOpenApi = (app: INestApplication) => {
};

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const globalPrefix = 'api';
const app = await NestFactory.create(ApiModule);
const globalPrefix = 'core';
app.setGlobalPrefix(globalPrefix);

app.useGlobalPipes(
Expand All @@ -35,15 +35,18 @@ async function bootstrap() {
})
);

// Enable version
app.enableVersioning({ type: VersioningType.URI });

// Setting up Swagger document
setupOpenApi(app);

// Listen on specified port
const port = process.env.PORT || 3000;
const configService = app.get(EnvService);
const port = configService.get('PORT');

await app.listen(port);
Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
);
Logger.log(`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`);
}

bootstrap();
25 changes: 25 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3.8'

volumes:
# postgresql data
core-rest-api-postgres-data:
driver: local

services:
postgres:
container_name: core-rest-api-pg
image: postgres
ports:
- 5432:5432
environment:
POSTGRES_USER: cliniccontrol
POSTGRES_PASSWORD: cliniccontrolpassword
POSTGRES_DB: core-rest-api
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_SCHEMA: public

# PGDATA: /data/postgres
volumes:
# - ./data/pg:/data/postgres
- core-rest-api-postgres-data:/var/lib/postgresql/data
14 changes: 14 additions & 0 deletions docs/others/links-to-read.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ type guard error handling: https://www.youtube.com/watch?v=xdQkEn3mx1k&t=114s
--

https://aykhanhuseyn.medium.com/typescript-naming-conventions-crafting-maintainable-code-7d872234fe17

--

# generate private key

openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048

# generate public key

openssl rsa -pubout -in private_key.pem -out public_key.pem

base64 -i private_key.pem -o private_key-base64.txt

https://www.elvisduru.com/blog/nestjs-jwt-authentication-refresh-token
Loading

0 comments on commit 5d50b2a

Please sign in to comment.