-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): user, Shop - entities, send email via SES, serverless ofl…
…line
- Loading branch information
Showing
24 changed files
with
12,484 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module.exports = { | ||
env: { | ||
es2021: true, | ||
node: true, | ||
}, | ||
extends: [ | ||
'airbnb-base', | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
}, | ||
plugins: [ | ||
'@typescript-eslint', | ||
], | ||
rules: { | ||
'import/no-unresolved': 'off', | ||
'import/extensions': 'off', | ||
'import/no-import-module-exports': 'off', | ||
'import/prefer-default-export': 'off', | ||
'no-useless-constructor': 'off', | ||
'no-unused-vars': 'off', | ||
'no-empty-function': 'off', | ||
'import/no-extraneous-dependencies': 'off', | ||
'no-extra-semi': 'off', | ||
'dot-notation': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,14 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
# package directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
.serverless | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
# esbuild directories | ||
.esbuild | ||
.dynamodb | ||
.nvmrc | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
# autogenerated files | ||
swagger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
# Description | ||
It is a serverless application that uses AWS lambda, dynamodb, and api gateway. It is written in typescript and uses the serverless framework. | ||
|
||
# Setup | ||
## Prerequisites | ||
- nodejs | ||
- npm | ||
- serverless framework | ||
- aws cli | ||
- aws credentials | ||
- dynamodb local | ||
- dynamodb admin | ||
- dynamodb migrate | ||
|
||
# Features | ||
|
||
- User | ||
- Create a user | ||
- Get a user | ||
- Update a user | ||
- Delete a user | ||
- Shop | ||
- Create a shop | ||
- Get a shop | ||
- Mail - send an email via [AWS SES](https://aws.amazon.com/ses/) | ||
|
||
## Installation | ||
|
||
Setup npm dependencies | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
Setup serverless framework | ||
|
||
```bash | ||
npm install -g serverless | ||
``` | ||
|
||
Install dynamodb local | ||
|
||
```bash | ||
npx sls dynamodb install | ||
``` | ||
|
||
Install dynamodb admin | ||
|
||
```bash | ||
npm install -g dynamodb-admin | ||
``` | ||
after installation, run the following command to start dynamodb admin | ||
```bash | ||
dynamodb-admin | ||
``` | ||
_note: admin will be available at http://localhost:8001 | ||
|
||
Install dynamodb migrate | ||
|
||
```bash | ||
npm install -g dynamodb-migrate | ||
``` | ||
|
||
## Run | ||
```bash | ||
npx serverless offline start --stage=dev | ||
``` | ||
|
||
## Deploy | ||
```bash | ||
npx serverless deploy --stage=<name> | ||
``` | ||
|
||
## Remove | ||
```bash | ||
npx serverless remove --stage=<name> | ||
``` | ||
|
||
# API Documentation | ||
Will be available at http://localhost:3000/swagger | ||
|
||
# Project Structure | ||
```bash | ||
src | ||
├── functions | ||
│ │ ├── handler.ts | ||
│ │ └── routes.ts | ||
│ ├── shop | ||
│ │ ├── handler.ts | ||
│ │ └── routes.ts | ||
│ └── user | ||
│ ├── handler.ts | ||
│ └── routes.ts | ||
├── libs | ||
│ ├── api-gateway.ts | ||
│ ├── handler-resolver.ts | ||
│ └── lambda.ts | ||
├── model | ||
│ ├── Shop.ts | ||
│ ├── User.ts | ||
│ └── index.ts | ||
└── services | ||
├── index.ts | ||
├── shop-service.ts | ||
└── user-service.ts | ||
``` | ||
Each function has its own folder with a handler and routes file. The handler file contains the lambda function and the routes file contains the api gateway routes. | ||
Example of the handler file: | ||
```typescript | ||
const create = middyfy( | ||
{ | ||
type: 'object', | ||
required: ['body'], | ||
properties: { | ||
body: { | ||
type: 'object', | ||
required: ['email'], | ||
properties: { | ||
email: { type: 'string', format: 'email' }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
async (event: APIGatewayProxyEventWithBody<any>): Promise<APIGatewayProxyResult> => { | ||
const user = await userService.create({ | ||
email: event.body.email, | ||
userId: uuidv4(), | ||
isVerified: false, | ||
}); | ||
|
||
return formatJSONResponse({ | ||
user, | ||
}); | ||
}, | ||
); | ||
``` | ||
`middify` - is a helper function that wraps the lambda function with params validation and error handling. | ||
|
||
# Contributing Guide | ||
## Branching | ||
- `master` - production branch | ||
- `dev` - development branch | ||
- `feature/<name>` - feature branch | ||
- `bugfix/<name>` - bugfix branch | ||
- `hotfix/<name>` - hotfix branch | ||
- `release/<name>` - release branch | ||
- `docs/<name>` - documentation branch | ||
- `test/<name>` - test branch | ||
- `chore/<name>` - chore branch | ||
- `refactor/<name>` - refactor branch | ||
- `style/<name>` - style branch | ||
- `ci/<name>` - ci branch | ||
|
||
## Commit Message | ||
```bash | ||
<type>[optional scope]: <description> | ||
``` | ||
Example: | ||
```bash | ||
feat(api): send an email to the customer when a product is shipped | ||
``` | ||
Commit message should be with the next format - conventionalcommits We are use commitizen for commit message formatting. |
Oops, something went wrong.