Skip to content

Commit a7be608

Browse files
author
Mubarak Imam
committed
chore(init): add backend project
- create backend project with nestjs - integrate africastalking and twili for sms - add signup and login with graphql and rest endpoints - add initial migrations - add basic tests
0 parents  commit a7be608

File tree

80 files changed

+9065
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+9065
-0
lines changed

nestpoc-api/.gitignore

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
.vscode
2+
# Logs
3+
logs
4+
*.log
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*
8+
lerna-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# Optional npm cache directory
48+
.npm
49+
50+
# Optional eslint cache
51+
.eslintcache
52+
53+
# Optional REPL history
54+
.node_repl_history
55+
56+
# Output of 'npm pack'
57+
*.tgz
58+
59+
# Yarn Integrity file
60+
.yarn-integrity
61+
62+
# dotenv environment variables file
63+
.env
64+
.env.test
65+
66+
# parcel-bundler cache (https://parceljs.org/)
67+
.cache
68+
69+
# next.js build output
70+
.next
71+
72+
# nuxt.js build output
73+
.nuxt
74+
75+
# vuepress build output
76+
.vuepress/dist
77+
78+
# Serverless directories
79+
.serverless/
80+
81+
# FuseBox cache
82+
.fusebox/
83+
84+
# DynamoDB Local files
85+
.dynamodb/
86+
**/.DS_Store
87+
dist
88+
development.env

nestpoc-api/.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}

nestpoc-api/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# NestPoc
2+
3+
NestPoc is my personal attempt at building scalable enterprise architecture using patterns similar to what is found in static language frameworks like C# ASP.NET and Java Spring.
4+
5+
## Structure
6+
7+
The app is structured into modules and the current modules on the app include:
8+
9+
- [x] Common Module
10+
- [ ] Gateway Module **(Started)**
11+
- [ ] Auth Module **(Started)**
12+
- [ ] SIS Module
13+
- [ ] LMS Module
14+
- [ ] Notification Module
15+
16+
## Setup
17+
18+
Currently running directly on npm, dockerization will happen soon.
19+
20+
You will find necessary environment variables in the `samples.env` file. This variables needs to be provided in the following ways:
21+
22+
- [x] passing them as command line arguments at startup
23+
- [x] loaded from `{environment}.env` file, (`environment` should be the same as the defined `NODE_ENV` value)
24+
25+
## Testing
26+
27+
Only unit tests have been implemented, and you can check that by running
28+
29+
```[bash]
30+
yarn test
31+
```
32+
33+
## Running
34+
35+
Simply start the app using any of the following depending on your environment
36+
37+
- Development: `yarn start:dev`
38+
- Production: `yarn start`
39+
40+
Brought to you by ['Barak Imam](https://barakimam.me) with 💝 from Lagos, Nigeria.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {MigrationInterface, QueryRunner} from 'typeorm';
2+
import { services } from '../src/modules/common/config/constants';
3+
4+
export class addNecessarySchemas1555134026445 implements MigrationInterface {
5+
6+
public async up(queryRunner: QueryRunner): Promise<any> {
7+
Object.entries(services).map((key) => {
8+
queryRunner.createSchema(key[1].schema, true);
9+
});
10+
}
11+
12+
public async down(queryRunner: QueryRunner): Promise<any> {
13+
Object.entries(services).map((key) => {
14+
queryRunner.dropSchema(key[1].schema, true, true);
15+
});
16+
}
17+
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {MigrationInterface, QueryRunner} from "typeorm";
2+
3+
export class addedInitialModels1558368688871 implements MigrationInterface {
4+
5+
public async up(queryRunner: QueryRunner): Promise<any> {
6+
await queryRunner.query(`CREATE TABLE "auth_schema"."user" ("created" TIMESTAMP NOT NULL DEFAULT now(), "updated" TIMESTAMP NOT NULL DEFAULT now(), "version" integer NOT NULL, "id" uuid NOT NULL DEFAULT uuid_generate_v4(), "username" character varying(30) NOT NULL, "email" character varying(100) NOT NULL, "hashedPassword" character varying NOT NULL, "twoFASecret" character varying, "temp2FASecret" character varying, CONSTRAINT "UQ_b87a45300b932446e90695f87e7" UNIQUE ("username"), CONSTRAINT "UQ_89f70f0dbb38c9929fdd73b7bfc" UNIQUE ("email"), CONSTRAINT "PK_72ee70fe54144c24f6880d0c6a0" PRIMARY KEY ("id"))`);
7+
await queryRunner.query(`CREATE TABLE "auth_schema"."personal_info" ("created" TIMESTAMP NOT NULL DEFAULT now(), "updated" TIMESTAMP NOT NULL DEFAULT now(), "version" integer NOT NULL, "firstName" character varying(30) NOT NULL, "lastName" character varying(30) NOT NULL, "dateOfBirth" TIMESTAMP NOT NULL, "countryCode" character varying(4) NOT NULL, "phoneNumber" character varying(20) NOT NULL, "profileId" uuid NOT NULL, CONSTRAINT "REL_2a64542334dc3539dfb59945ee" UNIQUE ("profileId"), CONSTRAINT "PK_2a64542334dc3539dfb59945eeb" PRIMARY KEY ("profileId"))`);
8+
await queryRunner.query(`ALTER TABLE "auth_schema"."personal_info" ADD CONSTRAINT "FK_2a64542334dc3539dfb59945eeb" FOREIGN KEY ("profileId") REFERENCES "auth_schema"."user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
9+
}
10+
11+
public async down(queryRunner: QueryRunner): Promise<any> {
12+
await queryRunner.query(`ALTER TABLE "auth_schema"."personal_info" DROP CONSTRAINT "FK_2a64542334dc3539dfb59945eeb"`);
13+
await queryRunner.query(`DROP TABLE "auth_schema"."personal_info"`);
14+
await queryRunner.query(`DROP TABLE "auth_schema"."user"`);
15+
}
16+
17+
}

nestpoc-api/nest-cli.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"language": "ts",
3+
"collection": "@nestjs/schematics",
4+
"sourceRoot": "src"
5+
}

nestpoc-api/nodemon-debug.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"watch": ["src"],
3+
"ext": "ts",
4+
"ignore": ["src/**/*.spec.ts"],
5+
"exec": "node --inspect-brk -r ts-node/register -r tsconfig-paths/register src/main.ts"
6+
}

nestpoc-api/nodemon.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"watch": ["src"],
3+
"ext": "ts",
4+
"ignore": ["src/**/*.spec.ts"],
5+
"exec": "ts-node -r tsconfig-paths/register src/main.ts"
6+
}

nestpoc-api/ormconfig.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"type": "postgres",
3+
"host": "localhost",
4+
"port": 5432,
5+
"username": "postgres",
6+
"password": "",
7+
"database": "nestpoc",
8+
"synchronize": true,
9+
"logging": false,
10+
"entities": [
11+
"./**/models/*.model.ts"
12+
],
13+
"migrations": [
14+
"./migrations/*.ts"
15+
],
16+
"subscribers": [
17+
"src/**/subscribers/*.ts"
18+
],
19+
"cli": {
20+
"migrationsDir": "./migrations"
21+
}
22+
}

nestpoc-api/package.json

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"name": "nest-poc",
3+
"version": "0.0.1",
4+
"description": "A proof of concept for NestJS, GraphQL and TOTP 2FA",
5+
"author": "Mubarak Imam",
6+
"license": "MIT",
7+
"scripts": {
8+
"prebuild": "rimraf dist",
9+
"tsc": "ts-node -r tsconfig-paths/register",
10+
"build": "tsc -b tsconfig.build.json",
11+
"format": "prettier --write \"src/**/*.ts\"",
12+
"start": "yarn tsc src/main.ts",
13+
"start:dev": "nodemon",
14+
"start:debug": "nodemon --config nodemon-debug.json",
15+
"prestart:prod": "yarn run build",
16+
"start:prod": "node dist/main.js",
17+
"lint": "tslint -p tsconfig.json -c tslint.json",
18+
"test:unit": "jest --config ./test/jest-unit.json",
19+
"test:unit:watch": "yarn test:unit:cov --watch",
20+
"test:unit:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --config ./test/jest-unit.json --runInBand",
21+
"test:integration": "jest --config ./test/jest-integration.json",
22+
"pretest:integration:full": "yarn db:refresh",
23+
"test:integration:full": "yarn test:integration",
24+
"test:e2e": "jest --config ./test/jest-e2e.json",
25+
"test:coverall": "jest --coverage",
26+
"typeorm": "yarn tsc ./node_modules/typeorm/cli.js",
27+
"db:rollback": "yarn typeorm schema:drop",
28+
"db:generate": "yarn typeorm migration:generate",
29+
"db:migrate": "yarn typeorm migration:run",
30+
"db:refresh": "yarn db:rollback && yarn db:migrate"
31+
},
32+
"dependencies": {
33+
"@hapi/joi": "^14.3.1",
34+
"@nestjs/common": "^6.0.0",
35+
"@nestjs/core": "^6.0.0",
36+
"@nestjs/graphql": "^6.0.5",
37+
"@nestjs/jwt": "^6.0.0",
38+
"@nestjs/passport": "^6.0.0",
39+
"@nestjs/platform-express": "^6.0.0",
40+
"africastalking": "^0.4.0",
41+
"apollo-server-express": "^2.4.8",
42+
"bcryptjs": "^2.4.3",
43+
"class-transformer": "^0.2.0",
44+
"class-validator": "^0.9.1",
45+
"cors": "^2.8.5",
46+
"dotenv": "^7.0.0",
47+
"graphql": "^14.2.1",
48+
"graphql-tools": "^4.0.4",
49+
"install": "^0.12.2",
50+
"nest-router": "^1.0.9",
51+
"passport": "^0.4.0",
52+
"passport-jwt": "^4.0.0",
53+
"pg": "^7.9.0",
54+
"qr-image": "^3.2.0",
55+
"rxjs": "^6.3.3",
56+
"speakeasy": "^2.0.0",
57+
"twilio": "^3.31.0",
58+
"typeorm": "^0.2.16"
59+
},
60+
"devDependencies": {
61+
"@nestjs/testing": "^6.0.0",
62+
"@types/express": "^4.16.0",
63+
"@types/hapi__joi": "^15.0.1",
64+
"@types/jest": "^23.3.13",
65+
"@types/node": "^11.13.0",
66+
"@types/supertest": "^2.0.7",
67+
"jest": "^23.6.0",
68+
"nodemon": "^1.18.9",
69+
"prettier": "^1.15.3",
70+
"reflect-metadata": "^0.1.12",
71+
"rimraf": "^2.6.2",
72+
"supertest": "^3.4.1",
73+
"ts-jest": "^23.10.5",
74+
"ts-node": "^7.0.1",
75+
"tsconfig-paths": "^3.7.0",
76+
"tslint": "5.14.0",
77+
"tslint-config-airbnb": "^5.11.1",
78+
"typescript": "^3.4.1",
79+
"uuid": "^3.3.2"
80+
},
81+
"jest": {
82+
"globalSetup": "<rootDir>/setup-jest.js",
83+
"moduleFileExtensions": [
84+
"js",
85+
"json",
86+
"ts"
87+
],
88+
"rootDir": "src",
89+
"testRegex": ".spec.ts$",
90+
"transform": {
91+
"^.+\\.(t|j)s$": "ts-jest"
92+
},
93+
"moduleNameMapper": {
94+
"@nestpoc/(.*)": "<rootDir>/modules/$1"
95+
},
96+
"coverageDirectory": "../coverage",
97+
"testEnvironment": "node",
98+
"collectCoverageFrom": [
99+
"<rootDir>/**/*.ts",
100+
"!<rootDir>/**/*.spec.ts",
101+
"!<rootDir>/**/index.ts",
102+
"!<rootDir>/main.ts",
103+
"!<rootDir>/**/*.d.ts",
104+
"!<rootDir>/**/dist/**/*.d.ts",
105+
"!**/__mocks__/**/*.ts"
106+
]
107+
}
108+
}

0 commit comments

Comments
 (0)