Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…injas-bn into ft-login-user-187584915
  • Loading branch information
ProgrammerDATCH committed May 29, 2024
2 parents 213e89c + 80e32f4 commit b6460a3
Show file tree
Hide file tree
Showing 20 changed files with 688 additions and 213 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
- image: cimg/node:18.17.0
steps:
- setup_remote_docker:
version: 20.10.7
version: docker24
- checkout
- run:
name: update-npm
Expand Down
28 changes: 23 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
PORT=
NODE_ENV=
NODE_EN=
DOCKER_DATABASE_HOST_AUTH_METHOD=
DOCKER_DATABASE_NAME=
DOCKER_DATABASE_PASSWORD=
JWT_SECRET=
NODE_ENV=

SMTP_HOST_PORT=
MP=
SMTP_HOST=
MAIL_ID=

CLOUD_NAME=
API_KEY=
API_SECRET=

SERVER_URL_DEV=
SERVER_URL_PRO=

DATABASE_URL_DEV=
DATABASE_URL_TEST=
DATABASE_URL_PRO=
DB_HOST_TYPE=



DB_HOST_TYPE=
DOCKER_DATABASE_USER=
DOCKER_DATABASE_HOST_AUTH_METHOD=
DOCKER_DATABASE_NAME=
DOCKER_DATABASE_PASSWORD=
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
push:
branches:
- develop

env:
PORT: ${{ secrets.PORT }}
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
Expand All @@ -17,6 +16,12 @@ env:
API_SECRET: ${{ secrets.API_SECRET }}
CLOUD_NAME: ${{ secrets.CLOUD_NAME }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
SERVER_URL_PRO : ${{ secrets.SERVER_URL_PRO }}
SMTP_HOST_PORT: ${{ secrets.SMTP_HOST_PORT }}
MP : ${{ secrets.MP }}
SMTP_HOST: ${{ secrets.SMTP_HOST }}
MAIL_ID: ${{ secrets.MAIL_ID }}
DB_HOST_TYPE: ${{ secrets.DB_HOST_TYPE }}

jobs:
build:
Expand Down Expand Up @@ -47,6 +52,7 @@ jobs:

- run: npm run coverage --if-present


- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
env:
Expand Down
7 changes: 7 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"check-coverage": true,
"lines": 80,
"functions": 80,
"branches": 80,
"statements": 80
}
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@ This is the backend for E-Commerce-Ninjas, written in Node.js with TypeScript.

- Welcome Endpoint
- Register Endpoint
- Verification Email Endpoint
- Resend verification Endpoint
- Login with Email and Password

## TABLE OF API ENDPOINTS SPECIFICATION AND DESCRIPTION


| No | VERBS | ENDPOINTS | STATUS | ACCESS | DESCRIPTION |
|----|-------|-------------------|--------|--------|-------------------- |
| 1 | GET | / | 200 OK | public | Show welcome message|
| 2 | POST | /api/auth/register| 200 OK | public | create user account |
| No | VERBS | ENDPOINTS | STATUS | ACCESS | DESCRIPTION |
|----|-------|------------------------------|-------------|--------|---------------------------|
| 1 | GET | / | 200 OK | public | Show welcome message |
| 2 | POST | /api/auth/register | 201 CREATED | public | create user account |
| 3 | GET | /api/auth/verify-email/:token| 200 OK | public | Verifying email |
| 4 | POST | /api/auth/send-verify-email | 200 OK | public | Resend verification email |
| 4 | POST | /api/auth/login | 200 OK | public | Login with Email and Password |



Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
},
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript",
"check-coverage": true,
"all": true,
"include": [
"src/**/!(*.test.*).[tj]s?(x)"
],
Expand All @@ -46,7 +44,8 @@
"text-summary"
],
"report-dir": "coverage",
"lines": 40
"check-coverage": true,
"all": true
},
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion src/databases/migrations/20240520180022-create-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default {
defaultValue: false
},
status: {
type: new DataTypes.BOOLEAN,
type: new DataTypes.STRING(128),
allowNull: false,
defaultValue: true
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import { QueryInterface, DataTypes } from "sequelize";
export default {
up: async (queryInterface: QueryInterface) => {
await queryInterface.createTable("tokens", {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
userId: {
type: new DataTypes.INTEGER,
allowNull: false
},
device: {
type: new DataTypes.STRING(280),
allowNull: true
},
accessToken: {
type: new DataTypes.STRING(280),
allowNull: true
},
verifyToken: {
type: new DataTypes.STRING(280),
allowNull: true
},
createdAt: {
field: "createdAt",
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updatedAt: {
field: "updatedAt",
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
},

down: async (queryInterface: QueryInterface) => {
await queryInterface.dropTable("tokens");
}
};
import { QueryInterface, DataTypes } from "sequelize";
export default {
up: async (queryInterface: QueryInterface) => {
await queryInterface.createTable("sessions", {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
userId: {
type: new DataTypes.INTEGER,
allowNull: false
},
device: {
type: new DataTypes.STRING(280),
allowNull: true
},
token: {
type: new DataTypes.STRING(280),
allowNull: true
},
otp: {
type: new DataTypes.STRING(280),
allowNull: true
},
createdAt: {
field: "createdAt",
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updatedAt: {
field: "updatedAt",
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
});
},

down: async (queryInterface: QueryInterface) => {
await queryInterface.dropTable("sessions");
}
};
146 changes: 73 additions & 73 deletions src/databases/models/tokens.ts → src/databases/models/session.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable require-jsdoc */
import { Model, DataTypes } from "sequelize";
import sequelizeConnection from "../config/db.config";
export interface TokenAttributes {
id: number;
userId: number;
device: string;
accessToken: string;
verifyToken: string;
createdAt: Date;
updatedAt: Date;
}

class Tokens extends Model<TokenAttributes> implements TokenAttributes {
declare id: number;
declare userId: number;
declare device: string;
declare accessToken: string;
declare verifyToken:string;
declare createdAt: Date;
declare updatedAt: Date;

static associate(models: any) {
Tokens.belongsTo(models.Users, { foreignKey: "userId",as: "user" });
}
}

Tokens.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
userId: {
type: new DataTypes.INTEGER,
allowNull: false
},
device: {
type: new DataTypes.STRING(280),
allowNull: true
},
accessToken: {
type: new DataTypes.STRING(280),
allowNull: true
},
verifyToken: {
type: new DataTypes.STRING(280),
allowNull: true
},
createdAt: {
field: "createdAt",
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updatedAt: {
field: "updatedAt",
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
},
{
sequelize: sequelizeConnection,
tableName: "tokens",
timestamps: true,
modelName:"Tokens"
}
);

export default Tokens;
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable require-jsdoc */
import { Model, DataTypes } from "sequelize";
import sequelizeConnection from "../config/db.config";
export interface SessionAttributes {
id: number;
userId: number;
device: string;
token: string;
otp: string;
createdAt: Date;
updatedAt: Date;
}

class Session extends Model<SessionAttributes> implements SessionAttributes {
declare id: number;
declare userId: number;
declare device: string;
declare token: string;
declare otp:string;
declare createdAt: Date;
declare updatedAt: Date;

static associate(models: any) {
Session.belongsTo(models.Users, { foreignKey: "userId",as: "user" });
}
}

Session.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
userId: {
type: new DataTypes.INTEGER,
allowNull: false
},
device: {
type: new DataTypes.STRING(280),
allowNull: true
},
token: {
type: new DataTypes.STRING(280),
allowNull: true
},
otp: {
type: new DataTypes.STRING(280),
allowNull: true
},
createdAt: {
field: "createdAt",
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
updatedAt: {
field: "updatedAt",
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
},
{
sequelize: sequelizeConnection,
tableName: "sessions",
timestamps: true,
modelName:"Sessions"
}
);

export default Session;
5 changes: 4 additions & 1 deletion src/databases/models/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class Users extends Model<UsersAttributes, UsersCreationAttributes> implements U
declare updatedAt?: Date;

// Define any static methods or associations here
static associate(models: any) {
Users.hasOne(models.Tokens, { foreignKey: "userId",as: "token" });
}
}

Users.init(
Expand Down Expand Up @@ -117,7 +120,7 @@ Users.init(
defaultValue: false
},
status: {
type: new DataTypes.BOOLEAN,
type: new DataTypes.STRING(128),
allowNull: true,
defaultValue: true
},
Expand Down
Loading

0 comments on commit b6460a3

Please sign in to comment.