Skip to content

Commit

Permalink
Merge pull request #19 from maick05/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
maick05 authored Jun 23, 2022
2 parents 2e838ae + ad68d6f commit b1d1b9f
Show file tree
Hide file tree
Showing 82 changed files with 2,027 additions and 386 deletions.
Empty file removed .env
Empty file.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MIGRATE_dbConnectionUri=
41 changes: 21 additions & 20 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# name: e2e
# on:
# push:
# branches:
# - main
# - development
# jobs:
# e2eTests:
# name: e2e-Tests
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# with:
# fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
# - name: install
# run: npm install
# - name: e2e test
# run: npm run test:e2e
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
name: e2e
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
e2eTests:
name: e2e-Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: install
run: npm install
- name: e2e test
run: npm run test:e2e
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any

4 changes: 2 additions & 2 deletions .github/workflows/sonar-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: install
- name: Install
run: npm install
- name: unit test
- name: Unit test
run: npm run test:cov
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ node_modules
# Sonar
.scannerwork/.sonar_lock
.scannerwork/report-task.txt
*.ucfg
*.ucfg

# Env
.env

2 changes: 1 addition & 1 deletion config/yaml/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ repository:
url: 'https://www.guiamais.com.br/bairros'
database:
mongodb:
connection: 'mongodb+srv://dev-seeder-root:hpYpxyjrKExNQviu@devseeder.v6xtv.mongodb.net/places'
connection: 'mongodb+srv://dev-seeder-root:hpYpxyjrKExNQviu@devseeder.v6xtv.mongodb.net/places?retryWrites=true&w=majority&ssl=true&wtimeoutMS=0'
api:
port: 3000
3 changes: 3 additions & 0 deletions migrate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"migrations-dir": "./src/config/database/migrations"
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"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/e2e/jest-e2e.json"
"test:e2e": "jest --config ./test/e2e/jest-e2e.json",
"migrate:up": "migrate up",
"migrate:down": "migrate down",
"migrate:build-up": "npm run build & migrate up"
},
"dependencies": {
"@golevelup/ts-jest": "^0.3.3",
Expand Down Expand Up @@ -85,7 +88,8 @@
"coveragePathIgnorePatterns": [
"/node_modules/",
"/src/main.ts",
"/src/app.module.ts"
"/src/app.module.ts",
"/src/config/database"
],
"testEnvironment": "node"
}
Expand Down
4 changes: 3 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ sonar.test.inclusions=test/**/*.spec.ts

sonar.tests=./test

sonar.exclusions= .eslintrc.js, src/main.ts, src/test/*, test/app.e2e-spec.ts, src/app.module.ts
sonar.exclusions= .eslintrc.js, src/main.ts, src/test/*, test/app.e2e-spec.ts, src/app.module.ts, src/config/database/*, src/config/database/migrations/*

sonar.cpd.exclusions=src/config/database/*, src/config/database/migrations/*

sonar.typescript.tsconfigPath=tsconfig.json

Expand Down
7 changes: 4 additions & 3 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { ClassSerializerInterceptor, Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { MongooseModule } from '@nestjs/mongoose';
import { PuppeteerModule } from 'nest-puppeteer';
import { FiltersModule } from './core/error-handling/filters.module';
import { TransformResponseInterceptor } from './core/http/transform-response.interceptor';
import { ExtensionsModule } from './microservice/adapter/helper/extensions/exensions.module';
import { CustomPuppeteerModule } from './microservice/adapter/helper/modules/custom-puppeteer.module';
import { NeighborhoodsModule } from './microservice/adapter/neighborhoods.module';

@Module({
imports: [
FiltersModule,
ExtensionsModule,
PuppeteerModule.forRoot({
isGlobal: true
CustomPuppeteerModule.forRootLaunchOptions({
isGlobal: true,
ignoreHTTPSErrors: true
}),
MongooseModule.forRootAsync({
imports: [ConfigModule],
Expand Down
15 changes: 15 additions & 0 deletions src/config/database/migration-connection-factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable @typescript-eslint/no-var-requires */
require(`../../../dist/microservice/adapter/helper/extensions/string.extension.js`);
const config = require('../../../dist/config/configuration.js').default();

module.exports = async function (collectionName, schemaName = null) {
schemaName = schemaName ? schemaName : collectionName;
const mongoose = require('mongoose');
const schemaCollection = require(`../../../dist/microservice/domain/schemas/${schemaName}.schema`);
const modelSchema = schemaCollection[`${schemaName.capitalize()}Schema`];
await mongoose.connect(config.database.mongodb.connection, {
useNewUrlParser: true,
useUnifiedTopology: true
});
return mongoose.model(collectionName, modelSchema);
};
60 changes: 60 additions & 0 deletions src/config/database/migrations/1655748067450-add_alias_prop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-disable prettier/prettier */
/* eslint-disable @typescript-eslint/no-var-requires */
const mongoose = require('mongoose');

const startConnection = require('../migration-connection-factory.js');

const model = startConnection('countries', 'country');

/**
* Make any changes you need to make to the database here
*/
async function up() {
const res = (await model).aggregate([
{
$project: {
alias: { $objectToArray: '$translations' },
iso2: '$iso2',
iso3: '$iso3',
name: '$name'
}
}
]);

for await (const item of res) {
const arrAlias = await item.alias.map((obj) => obj.v);
arrAlias.push(item.name);
arrAlias.push(item.iso2);
arrAlias.push(item.iso3);
await (
await model
)
.findByIdAndUpdate(item._id, {
$set: {
alias: arrAlias
}
})
.exec();
}
}

/**
* Make any changes that UNDO the up function side effects here (if possible)
*/
async function down() {
await (
await model
)
.updateMany(
{},
{
$set: {
alias: []
}
}
)
.exec();
mongoose.connection.close();
}

module.exports = { up, down };
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* eslint-disable prettier/prettier */
/* eslint-disable @typescript-eslint/no-var-requires */
const mongoose = require('mongoose');

const startConnection = require('../migration-connection-factory.js');

const model = startConnection('countries', 'country');

/**
* Make any changes you need to make to the database here
*/
async function up() {
try {
await (
await model
)
.updateMany(
{},
{
$rename: {
numeric_code: 'numericCode',
phone_code: 'phoneCode',
currency_name: 'currencyName',
currency_symbol: 'currencySymbol'
}
},
{
// Strict allows to update keys that do not exist anymore in the schema
strict: false
}
)
.exec();
mongoose.connection.close();
} catch (err) {
console.log('err --> ');
console.log(err);
mongoose.connection.close();
}
}

/**
* Make any changes that UNDO the up function side effects here (if possible)
*/
async function down() {
try {
await (
await model
)
.updateMany(
{},
{
$rename: {
numericCode: 'numeric_code',
phoneCode: 'phone_code',
currencyName: 'currency_name',
currencySymbol: 'currency_symbol'
}
},
{
// Strict allows to update keys that do not exist anymore in the schema
strict: false
}
)
.exec();
mongoose.connection.close();
} catch (err) {
console.log('err --> ');
console.log(err);
mongoose.connection.close();
}
}

module.exports = { up, down };
73 changes: 73 additions & 0 deletions src/config/database/migrations/1655917316641-rename_state_props.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* eslint-disable prettier/prettier */
/* eslint-disable @typescript-eslint/no-var-requires */
const mongoose = require('mongoose');

const startConnection = require('../migration-connection-factory.js');

const model = startConnection('state');

/**
* Make any changes you need to make to the database here
*/
async function up() {
try {
await (
await model
)
.updateMany(
{},
{
$rename: {
state_code: 'stateCode',
country_id: 'countryId',
country_name: 'countryName',
country_code: 'countryCode'
}
},
{
// Strict allows to update keys that do not exist anymore in the schema
strict: false
}
)
.exec();
mongoose.connection.close();
} catch (err) {
console.log('err --> ');
mongoose.connection.close();
throw err;
}
}

/**
* Make any changes that UNDO the up function side effects here (if possible)
*/
async function down() {
try {
await (
await model
)
.updateMany(
{},
{
$rename: {
stateCode: 'state_code',
countryId: 'country_id',
countryName: 'country_name',
countryCode: 'country_code'
}
},
{
// Strict allows to update keys that do not exist anymore in the schema
strict: false
}
)
.exec();
mongoose.connection.close();
} catch (err) {
console.log('err --> ');
mongoose.connection.close();
throw err;
}
}

module.exports = { up, down };
Loading

0 comments on commit b1d1b9f

Please sign in to comment.