diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index a366d88b..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,48 +0,0 @@ -version: 2 -orbs: - coveralls: coveralls/coveralls@1.0.6 -jobs: - build: - docker: - - image: cimg/node:18.17.0 - steps: - - setup_remote_docker: - version: docker24 - - checkout - - run: - name: update-npm - command: "sudo npm install -g npm@latest" - - restore_cache: - keys: - - v1-dependencies-{{ checksum "package-lock.json" }} - - v1-dependencies- - - run: - name: Install dependencies - command: npm install - - save_cache: - paths: - - node_modules - key: v1-dependencies-{{ checksum "package-lock.json" }} - - run: - name: Run tests - command: npm test - when: always - - run: - name: Run coverage - command: npm run coverage - when: always - - run: - name: Setup Code Climate test-reporter - command: | - # download test reporter as a static binary - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter - ./cc-test-reporter before-build - when: always - - run: - name: Send coverage report to Code Climate - command: ./cc-test-reporter after-build -t lcov - when: always - - store_artifacts: - path: ./coverage/lcov.info - prefix: tests \ No newline at end of file diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 74d2ca91..00000000 --- a/.eslintrc +++ /dev/null @@ -1,41 +0,0 @@ -{ - "root": true, - "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint", "import"], - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended" - ], - "rules": { - "quotes": ["warn", "double"], - "one-var": 0, - "one-var-declaration-per-line": 0, - "new-cap": 0, - "consistent-return": 0, - "no-param-reassign": 0, - "comma-dangle": 2, - "curly": ["warn", "multi-line"], - "import/no-unresolved": "off", - "no-shadow": ["error", { "allow": ["req", "res", "err"] }], - "valid-jsdoc": [ - "warn", - { - "requireReturn": true, - "requireReturnType": true, - "requireParamDescription": false, - "requireReturnDescription": true - } - ], - "require-jsdoc": [ - "warn", - { - "require": { - "FunctionDeclaration": true, - "MethodDefinition": true, - "ClassDeclaration": true - } - } - ] - } - } \ No newline at end of file diff --git a/.github/workflows/blank.yml b/.github/workflows/blank.yml deleted file mode 100644 index cba4bd9e..00000000 --- a/.github/workflows/blank.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Deploy to Render - -on: - pull_request: - types: [closed] - -jobs: - main: - name: Deploy - if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - steps: - - name: Deploy - uses: bankfliptech/deploy-to-render@v1 - with: - serviceId: ${{ secrets.RENDER_SERVICE_ID }} - apiKey: ${{ secrets.RENDER_API_KEY }} - deployHookURL: ${{ secrets.RENDER_DEPLOY_HOOK_URL }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1adebdeb..08b25532 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +1 @@ -# Build and Release Folders -bin-debug/ -bin-release/ -[Oo]bj/ -[Bb]in/ - -# Other files and folders -.settings/ - -# Executables -*.swf -*.air -*.ipa -*.apk - -# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` -# should NOT be excluded as they contain compiler settings and other important -# information for Eclipse / Flash Builder. - -#node modules folder -node_modules/ - -#environment variables -.env -coverage -.nyc_output -.vscode -.cache_ggshield -dist - +node_modules diff --git a/.hintrc b/.hintrc deleted file mode 100644 index 12c4655b..00000000 --- a/.hintrc +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": [ - "development" - ], - "hints": { - "typescript-config/strict": "off" - } -} \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100644 index a845b850..00000000 --- a/.husky/pre-commit +++ /dev/null @@ -1 +0,0 @@ -npm run lint \ No newline at end of file diff --git a/.sequelizerc b/.sequelizerc deleted file mode 100644 index f348c7ec..00000000 --- a/.sequelizerc +++ /dev/null @@ -1,7 +0,0 @@ -const path = require("path"); -module.exports = { - 'config': path.resolve('dist/src', 'databases', 'config', 'config.js'), - 'models-path': path.resolve('dist/src', 'databases', 'models'), - 'seeders-path': path.resolve('dist/src', 'databases', 'seeders'), - 'migrations-path': path.resolve('dist/src', 'databases', 'migrations') -}; \ No newline at end of file diff --git a/Dockerfile.database b/Dockerfile.database deleted file mode 100644 index add33403..00000000 --- a/Dockerfile.database +++ /dev/null @@ -1 +0,0 @@ -FROM postgres:latest diff --git a/Dockerfile.server b/Dockerfile.server deleted file mode 100644 index ce92b044..00000000 --- a/Dockerfile.server +++ /dev/null @@ -1,13 +0,0 @@ -FROM node:20-alpine - -WORKDIR /app - -COPY ./package.json . - -RUN npm install - -COPY . . - -EXPOSE 3000 - -CMD ["npm", "start"] \ No newline at end of file diff --git a/README.Docker.md b/README.Docker.md deleted file mode 100644 index fa3048f6..00000000 --- a/README.Docker.md +++ /dev/null @@ -1,22 +0,0 @@ -### Building and running your application - -When you're ready, start your application by running: -`docker compose up --build`. - -Your application will be available at http://localhost:3000. - -### Deploying your application to the cloud - -First, build your image, e.g.: `docker build -t myapp .`. -If your cloud uses a different CPU architecture than your development -machine (e.g., you are on a Mac M1 and your cloud provider is amd64), -you'll want to build the image for that platform, e.g.: -`docker build --platform=linux/amd64 -t myapp .`. - -Then, push it to your registry, e.g. `docker push myregistry.com/myapp`. - -Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/) -docs for more detail on building and pushing. - -### References -* [Docker's Node.js guide](https://docs.docker.com/language/nodejs/) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index b258d36d..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,28 +0,0 @@ -version: "3" - -services: - server: - build: - context: . - dockerfile: Dockerfile.server - ports: - - "3000:3000" - env_file: - - .env - depends_on: - - database - - database: - build: - context: . - dockerfile: Dockerfile.database - ports: - - "5432:5432" - environment: - DATABASE_USER: ${DOCKER_DATABASE_USER} - DATABASE_NAME: ${DOCKER_DATABASE_NAME} - DATABASE_PASSWORD: ${DOCKER_DATABASE_PASSWORD} - POSTGRES_USER: ${DOCKER_DATABASE_USER} - POSTGRES_NAME: ${DOCKER_DATABASE_NAME} - POSTGRES_PASSWORD: ${DOCKER_DATABASE_PASSWORD} - POSTGRES_HOST_AUTH_METHOD: ${DOCKER_DATABASE_HOST_AUTH_METHOD} \ No newline at end of file diff --git a/src/databases/config/config.ts b/src/databases/config/config.ts deleted file mode 100644 index 33e59b5c..00000000 --- a/src/databases/config/config.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* eslint-disable comma-dangle */ -import dotenv from "dotenv"; - -dotenv.config(); - -const commonDatabaseConfig = { - dialect: "postgres", -}; - -const sequelizeConfig = { - development: { - ...commonDatabaseConfig, - url: process.env.DATABASE_URL_DEV, - }, - test: { - ...commonDatabaseConfig, - url: process.env.DATABASE_URL_TEST, - dialectOptions: { - ssl: { - require: true, - rejectUnauthorized: false, - }, - }, - }, - production: { - ...commonDatabaseConfig, - url: process.env.DATABASE_URL_PRO, - dialectOptions: { - ssl: { - require: true, - rejectUnauthorized: false, - }, - }, - }, -}; - -module.exports = sequelizeConfig; diff --git a/src/databases/config/db.config.ts b/src/databases/config/db.config.ts deleted file mode 100644 index 0c54a72d..00000000 --- a/src/databases/config/db.config.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* eslint-disable comma-dangle */ -import { config } from "dotenv"; -import { Sequelize } from "sequelize"; - -config(); -const NODE_ENV: string = process.env.NODE_ENV || "development"; -const DB_HOST_MODE: string = process.env.DB_HOST_TYPE || "remote"; - -/** - * Get the URI for the database connection. - * @returns {string} The URI string. - */ -function getDbUri(): string { - switch (NODE_ENV) { - case "development": - return process.env.DATABASE_URL_DEV as string; - case "test": - return process.env.DATABASE_URL_TEST as string; - default: - return process.env.DATABASE_URL_PRO as string; - } -} - -/** - * Get dialect options for Sequelize. - * @returns {DialectOptions} The dialect options. - */ -function getDialectOptions() { - return DB_HOST_MODE === "local" - ? {} - : { - ssl: { - require: true, - rejectUnauthorized: false, - }, - }; -} - -const sequelizeConnection: Sequelize = new Sequelize(getDbUri(), { - dialect: "postgres", - dialectOptions: getDialectOptions(), - logging: false, -}); - -export default sequelizeConnection; diff --git a/src/databases/models/tokens.ts b/src/databases/models/tokens.ts new file mode 100644 index 00000000..653face6 --- /dev/null +++ b/src/databases/models/tokens.ts @@ -0,0 +1,70 @@ +/* eslint-disable require-jsdoc */ +import { Model, DataTypes, Sequelize } from "sequelize"; + +interface TokenAttributes { + id: number; + userId: number; + device: string; + accessToken: string; + createdAt: Date; + updatedAt: Date; + expiresAt: Date; +} + +module.exports = (sequelize: Sequelize) => { + class Tokens extends Model implements TokenAttributes { + declare id: number; + declare userId: number; + declare device: string; + declare accessToken: string; + declare createdAt: Date; + declare updatedAt: Date; + declare expiresAt: Date; + } + + Tokens.init( + { + id: { + type: DataTypes.INTEGER, + autoIncrement: true, + primaryKey: true + }, + userId: { + type: new DataTypes.INTEGER(), + allowNull: false + }, + device: { + type: new DataTypes.STRING(280), + allowNull: false + }, + accessToken: { + type: new DataTypes.STRING(280), + allowNull: false + }, + createdAt: { + field: "createdAt", + type: DataTypes.DATE, + allowNull: false, + defaultValue: DataTypes.NOW + }, + updatedAt: { + field: "updatedAt", + type: DataTypes.DATE, + allowNull: false, + defaultValue: DataTypes.NOW + }, + expiresAt: { + type: DataTypes.DATE, + allowNull: false + } + }, + { + sequelize, + tableName: "tokens", + timestamps: true, + modelName: "Tokens" + } + ); + + return Tokens; +}; diff --git a/src/routes/authRouter.ts b/src/routes/authRouter.ts index 1b3ab9c6..4945c50e 100644 --- a/src/routes/authRouter.ts +++ b/src/routes/authRouter.ts @@ -52,4 +52,4 @@ router.get( googleAuth.authenticateWithGoogle); -export default router; \ No newline at end of file +export default router; diff --git a/src/services/sendEmail.ts b/src/services/sendEmail.ts deleted file mode 100644 index 816dce75..00000000 --- a/src/services/sendEmail.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { Request, Response } from "express"; -import nodemailer, { SendMailOptions } from "nodemailer"; -import dotenv from "dotenv"; - -dotenv.config(); -const transporter = nodemailer.createTransport({ - host: process.env.SMTP_HOST, - port: Number(process.env.SMTP_HOST_PORT), - secure: true, - auth: { - user: process.env.MAIL_ID, - pass: process.env.MP - } -}); - -const sendVerificationEmail = async(email: string, subject: string, message: string) => { - try { - const mailOptionsVerify: SendMailOptions = { - from: process.env.MAIL_ID, - to: email, - subject: subject, - text: message - }; - - await transporter.sendMail(mailOptionsVerify); - } catch (error) { - throw new Error(error); - } -}; - -export { sendVerificationEmail, transporter }; \ No newline at end of file diff --git a/swagger.json b/swagger.json index 69023501..a2acbc02 100644 --- a/swagger.json +++ b/swagger.json @@ -639,9 +639,7 @@ "type": "string" } }, - "required": [ - "status" - ] + "required": ["status"] } } } @@ -770,16 +768,10 @@ "properties": { "role": { "type": "string", - "enum": [ - "Admin", - "Buyer", - "Seller" - ] + "enum": ["Admin", "Buyer", "Seller"] } }, - "required": [ - "role" - ] + "required": ["role"] } } } @@ -1362,6 +1354,13 @@ } } } + }, + "securitySchemes": { + "BearerAuth": { + "type": "http", + "scheme": "bearer", + "bearerFormat": "JWT" + } } } -} \ No newline at end of file +}