Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2 #50

Merged
merged 33 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3171a88
update libraries
janishar Dec 11, 2022
73be192
update all files
janishar Dec 11, 2022
eba2c46
fix code
janishar Dec 11, 2022
e5c61e5
fix renames
janishar Dec 11, 2022
22c5f9b
remove unused lib
janishar Dec 11, 2022
24144a2
fix test files
janishar Dec 11, 2022
508e3be
add template
janishar Dec 11, 2022
3cfa7d3
update images
janishar Dec 11, 2022
38953be
update version of docker build
janishar Dec 12, 2022
50ad515
update seed db schema
janishar Dec 12, 2022
d5ae4dc
add users in mongo init
janishar Dec 12, 2022
b9a4543
add redis docker compose
janishar Dec 12, 2022
703cfb3
fix docker db connection
janishar Dec 12, 2022
cb8af74
remove unused packages
janishar Dec 12, 2022
a8450bb
formatting fixes
janishar Dec 13, 2022
359101f
migrate static class to modules export
janishar Dec 14, 2022
e2378e2
convert static class into modules
janishar Dec 14, 2022
3ea7fb0
convert static class into module
janishar Dec 14, 2022
d744b29
implement caching in routes
janishar Dec 14, 2022
8e72035
fix seed user
janishar Dec 14, 2022
72026a2
fix redis connection
janishar Dec 14, 2022
10b5717
update apikey unit test
janishar Dec 19, 2022
7285550
update mock function
janishar Dec 19, 2022
16a1940
migrate authorization tests
janishar Dec 19, 2022
08e6e3a
migrate jwt tests
janishar Dec 19, 2022
319a409
fix signup test
janishar Dec 19, 2022
10f085b
migrate blog test
janishar Dec 19, 2022
d9539a9
fix writer test
janishar Dec 19, 2022
5fa436a
add database and cache mock
janishar Dec 19, 2022
a7da322
restructure test files
janishar Dec 19, 2022
25aff39
remove unused eslint libs
janishar Dec 19, 2022
a9f367d
format file with prettier rules
janishar Dec 19, 2022
caefa09
update readme
janishar Dec 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Environment Name
NODE_ENV=development

# TimeZone
TZ=UTC

# Server listen to this port
PORT=3000

Expand All @@ -11,7 +14,9 @@ CORS_URL=*

# Databse
# YOUR_MONGO_DB_NAME
DB_NAME=afteracademy-blog-db
DB_NAME=blogs-db
DB_MIN_POOL_SIZE=2
DB_MAX_POOL_SIZE=5

#localhost or IP of the server
# If using the docker installation then use 'mongo' for host name else localhost or ip or db server
Expand All @@ -21,7 +26,7 @@ DB_HOST=mongo
DB_PORT=27017

#YOUR_MONGO_DB_USER_NAME
DB_USER=afteracademy-blog-db-user
DB_USER=blogs-db-user

#YOUR_MONGO_DB_USER_PWD
DB_USER_PWD=changeit
Expand All @@ -30,13 +35,23 @@ DB_USER_PWD=changeit
DB_ADMIN=admin
DB_ADMIN_PWD=changeit

# Redis
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=changeit

# Log
# Example '/home/node/logs'
# DEFAUlT is this project's directory
# LOG_DIR=YOUR_DIRECTORY_PATH_FOR_LOG_FILES

# Token Info
ACCESS_TOKEN_VALIDITY_DAYS=30
REFRESH_TOKEN_VALIDITY_DAYS=120
TOKEN_ISSUER=afteracademy.com
TOKEN_AUDIENCE=afteracademy.com
# 2 DAYS: 172800 Sec
ACCESS_TOKEN_VALIDITY_SEC=172800
# 7 DAYS: 604800 Sec
REFRESH_TOKEN_VALIDITY_SEC=604800
TOKEN_ISSUER=api.dev.xyz.com
TOKEN_AUDIENCE=xyz.com

# Caching
CONTENT_CACHE_DURATION_MILLIS=600000
6 changes: 2 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
"@typescript-eslint/explicit-module-boundary-types": "off"
},
"extends": [
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
"plugin:@typescript-eslint/recommended" // Uses the recommended rules from the @typescript-eslint/eslint-plugin
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020, // Allows for the parsing of modern ECMAScript features
"ecmaVersion": "latest", // Allows for the parsing of modern ECMAScript features
"sourceType": "module" // Allows for the use of imports
},

Expand Down
15 changes: 14 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,17 @@ coverage

# Environment varibles
*.env
*.env.*
*.env.test
*.env copy

#keys
keys/*
!keys/*.md
!keys/*.example

#temp
temp
.DS_Store

*.save
*.save.*
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 100,
"printWidth": 80,
"tabWidth": 2
}
50 changes: 50 additions & 0 deletions .templates/database/model/Sample.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Schema, model, Types } from 'mongoose';

export const DOCUMENT_NAME = 'Sample';
export const COLLECTION_NAME = 'samples';

export enum Category {
ABC = 'ABC',
XYZ = 'XYZ',
}

export default interface Sample {
_id: Types.ObjectId;
category: Category;
status?: boolean;
createdAt?: Date;
updatedAt?: Date;
}

const schema = new Schema<Sample>(
{
category: {
type: Schema.Types.String,
required: true,
enum: Object.values(Category),
},
status: {
type: Schema.Types.Boolean,
default: true,
},
createdAt: {
type: Schema.Types.Date,
required: true,
select: false,
},
updatedAt: {
type: Schema.Types.Date,
required: true,
select: false,
},
},
{
versionKey: false,
},
);

export const SampleModel = model<Sample>(
DOCUMENT_NAME,
schema,
COLLECTION_NAME,
);
27 changes: 27 additions & 0 deletions .templates/database/repository/SampleRepo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Sample, { SampleModel } from '../model/Sample';
import { Types } from 'mongoose';

async function findById(id: Types.ObjectId): Promise<Sample | null> {
return SampleModel.findOne({ _id: id, status: true }).lean().exec();
}

async function create(sample: Sample): Promise<Sample> {
const now = new Date();
sample.createdAt = now;
sample.updatedAt = now;
const created = await SampleModel.create(sample);
return created.toObject();
}

async function update(sample: Sample): Promise<Sample | null> {
sample.updatedAt = new Date();
return SampleModel.findByIdAndUpdate(sample._id, sample, { new: true })
.lean()
.exec();
}

export default {
findById,
create,
update,
};
29 changes: 29 additions & 0 deletions .templates/route/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
import express from 'express';
import { ProtectedRequest } from 'app-request';
import { SuccessResponse } from '../../../core/ApiResponse';
import asyncHandler from '../../../helpers/asyncHandler';
import validator, { ValidationSource } from '../../../helpers/validator';
import schema from './schema';
import { BadRequestError } from '../../../core/ApiError';
import role from '../../../helpers/role';
import authentication from '../../../auth/authentication';
import authorization from '../../../auth/authorization';
import { RoleCode } from '../../../database/model/Role';

const router = express.Router();

//----------------------------------------------------------------
router.use(authentication, role(RoleCode.LEARNER), authorization);
//----------------------------------------------------------------

router.post(
'/sample',
validator(schema.sample, ValidationSource.BODY),
asyncHandler(async (req: ProtectedRequest, res) => {
new SuccessResponse('Success', {}).send(res);
}),
);

export default router;
*/
7 changes: 7 additions & 0 deletions .templates/route/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Joi from 'joi';

export default {
sample: Joi.object().keys({
key: Joi.string().required().min(1),
}),
};
45 changes: 21 additions & 24 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "2.0.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/src/server.ts",
"preLaunchTask": "tsc: build - tsconfig.json",
"runtimeArgs": [
"-r",
"dotenv/config"
],
"outFiles": [
"${workspaceFolder}/build/*.js",
"${workspaceFolder}/build/**/*.js",
"${workspaceFolder}/build/**/**/*.js",
"${workspaceFolder}/build/**/**/**/*.js"
]
}
]
}
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "2.0.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/build/server.js",
"preLaunchTask": "tsc: build - tsconfig.json",
"runtimeArgs": ["-r", "dotenv/config"],
"outFiles": [
"${workspaceFolder}/build/*.js",
"${workspaceFolder}/build/**/*.js",
"${workspaceFolder}/build/**/**/*.js",
"${workspaceFolder}/build/**/**/**/*.js"
]
}
]
}
85 changes: 85 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "vscode: Install Plugins",
"type": "shell",
"command": "chmod +x ./.vscode/extensions.list | ./.vscode/extensions.list",
"presentation": {
"reveal": "always",
"panel": "new"
}
},
{
"label": "Install Dependencies",
"type": "shell",
"command": "npm install",
"presentation": {
"reveal": "always",
"panel": "new"
}
},
{
"label": "Start Prod Server",
"type": "npm",
"script": "start"
},
{
"label": "Start Dev Server",
"type": "npm",
"script": "run watch"
},
{
"label": "Template: Generate V1 Route",
"type": "shell",
"command": "cp",
"presentation": {
"reveal": "never",
"panel": "shared"
},
"args": [
"-r",
"${workspaceFolder}/.templates/route",
"${workspaceFolder}/src/routes/v1/${input:routeName}"
]
},
{
"label": "Template: Generate Model",
"type": "shell",
"command": "cp",
"presentation": {
"reveal": "never",
"panel": "shared"
},
"args": [
"${workspaceFolder}/.templates/database/model/Sample.ts",
"${workspaceFolder}/src/database/model/${input:modelName}.ts"
]
},
{
"label": "Template: Generate Repo",
"type": "shell",
"command": "cp",
"presentation": {
"reveal": "never",
"panel": "shared"
},
"args": [
"${workspaceFolder}/.templates/database/repository/SampleRepo.ts",
"${workspaceFolder}/src/database/repository/${input:modelName}Repo.ts"
]
}
],
"inputs": [
{
"type": "promptString",
"id": "routeName",
"description": "Route name to create?"
},
{
"type": "promptString",
"id": "modelName",
"description": "Model name to create?"
}
]
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Here we are getting our node as Base image
FROM node:13
FROM node:18.12.1

# create user in the docker image
USER node
Expand Down
Loading