first commit

This commit is contained in:
harshithnrao 2025-02-24 12:46:49 +05:30
commit 012b8c0104
104 changed files with 24842 additions and 0 deletions

8
.env Normal file
View File

@ -0,0 +1,8 @@
POSTGRES_HOST=127.0.0.1
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DATABASE=wastecare
PORT=3000
MODE=DEV
RUN_MIGRATIONS=false

24
.eslintrc.js Normal file
View File

@ -0,0 +1,24 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};

36
.gitignore vendored Normal file
View File

@ -0,0 +1,36 @@
# compiled output
/dist
/node_modules
/uploads/*
# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

1
Insomnia_2024-01-21.json Normal file

File diff suppressed because one or more lines are too long

73
README.md Normal file
View File

@ -0,0 +1,73 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
## Description
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
## Installation
```bash
$ npm install
```
## Running the app
```bash
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
```
## Test
```bash
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
```
## Support
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
## Stay in touch
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)
## License
Nest is [MIT licensed](LICENSE).

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,145 @@
CREATE TABLE "payment" (
"id" BIGSERIAL PRIMARY KEY,
"user_id" BIGINT NOT NULL,
"amount" NUMERIC,
"payment_date" DATE,
"method" TEXT,
"payment_signature" TEXT,
"from_account" TEXT,
"to_account" TEXT,
"remaining_amount" NUMERIC,
"status" TEXT,
"validFrom" DATE,
"validTill" DATE,
"createdAt" DATE,
"updatedAt" DATE,
"createdBy" TEXT,
"modifiedBy" TEXT,
"deletedAt" DATE,
"version" NUMERIC
);
CREATE TABLE "plans_ref" (
"id" BIGSERIAL PRIMARY KEY,
"name" TEXT,
"price" NUMERIC,
"duration" DATE,
"description" TEXT,
"status" TEXT,
"validFrom" DATE,
"validTill" DATE,
"createdAt" DATE,
"updatedAt" DATE,
"createdBy" TEXT,
"modifiedBy" TEXT,
"deletedAt" DATE,
"version" NUMERIC
);
CREATE TABLE "invoice" (
"id" BIGSERIAL PRIMARY KEY,
"user_id" BIGINT NOT NULL,
"payment_id" BIGINT NOT NULL,
"invoice_number" TEXT,
"amount" NUMERIC,
"remaining_balance" NUMERIC,
"tax" NUMERIC,
"issue_date" DATE,
"due_date" DATE,
"status" TEXT,
"validFrom" DATE,
"validTill" DATE,
"createdAt" DATE,
"updatedAt" DATE,
"createdBy" TEXT,
"modifiedBy" TEXT,
"deletedAt" DATE,
"version" NUMERIC
);
CREATE TABLE "refund" (
"id" BIGSERIAL PRIMARY KEY,
"payment_id" BIGINT NOT NULL,
"amount" NUMERIC,
"refund_date" DATE,
"reason" TEXT,
"to_account" TEXT,
"status" TEXT,
"validFrom" DATE,
"validTill" DATE,
"createdAt" DATE,
"updatedAt" DATE,
"createdBy" TEXT,
"modifiedBy" TEXT,
"deletedAt" DATE,
"version" NUMERIC
);
CREATE TABLE "plan_usage" (
"id" BIGSERIAL PRIMARY KEY,
"user_id" BIGINT NOT NULL,
"plan_id" BIGINT NOT NULL,
"usage_type" TEXT,
"usage_quantity" DATE,
"status" TEXT,
"validFrom" DATE,
"validTill" DATE,
"createdAt" DATE,
"updatedAt" DATE,
"createdBy" TEXT,
"modifiedBy" TEXT,
"deletedAt" DATE,
"version" NUMERIC
);
CREATE TABLE "offers" (
"id" BIGSERIAL PRIMARY KEY,
"code" TEXT,
"description" TEXT,
"discount_value" NUMERIC,
"status" TEXT,
"validFrom" DATE,
"validTill" DATE,
"createdAt" DATE,
"updatedAt" DATE,
"createdBy" TEXT,
"modifiedBy" TEXT,
"deletedAt" DATE,
"version" NUMERIC
);
CREATE TABLE "offers_redemption" (
"id" BIGSERIAL PRIMARY KEY,
"user_id" BIGINT NOT NULL,
"offer_id" BIGINT NOT NULL,
"payment_id" BIGINT NOT NULL,
"redemption_date" DATE,
"status" TEXT,
"validFrom" DATE,
"validTill" DATE,
"createdAt" DATE,
"updatedAt" DATE,
"createdBy" TEXT,
"modifiedBy" TEXT,
"deletedAt" DATE,
"version" NUMERIC
);
CREATE TABLE "quotes" (
"id" BIGSERIAL PRIMARY KEY,
"user_id" BIGINT NOT NULL,
"user_email" TEXT,
"institute_id" BIGINT,
"quote_type" TEXT,
"quote_est" NUMERIC,
"cust_estimate" NUMERIC,
"status" TEXT,
"validFrom" DATE,
"validTill" DATE,
"createdAt" DATE,
"updatedAt" DATE,
"createdBy" TEXT,
"modifiedBy" TEXT,
"deletedAt" DATE,
"version" NUMERIC
);

View File

@ -0,0 +1,283 @@
CREATE TABLE public.actions_ref (
id bigserial NOT NULL,
"appCode" text,
"actionCode" text,
"actionName" text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.apps_ref (
id bigserial NOT NULL,
"appCode" text,
"appName" text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.companies (
id bigserial NOT NULL,
"companyCode" text,
"companyName" text,
address text,
gst text,
status text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.company_details (
id bigserial NOT NULL,
"companyId" numeric,
"companyCode" text,
"addlDataType" text,
"addlDataName" text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.crud_config_info (
id bigserial NOT NULL,
"endPtNm" text,
"opsTypeName" text,
"sqlQueryText" text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.item_category_ref (
id bigserial NOT NULL,
"categoryName" text,
"categoryCode" text,
"categoryDescription" text,
"parentCode" text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.items_ref (
id bigserial NOT NULL,
"itemCode" text,
"itemName" text,
"itemCategoryCode" text,
"itemDesc" text,
"parentCode" text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.policies_ref (
id bigserial NOT NULL,
"appCode" text,
"roleCode" text,
"resourceCode" text,
"actionCode" text,
"canAllow" boolean,
priority boolean,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.resources_ref (
id bigserial NOT NULL,
"appCode" text,
"resourceCode" text,
"resourceName" text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.roles_ref (
id bigserial NOT NULL,
"appCode" text,
"roleCode" text,
"roleName" text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.user_additional_details (
id bigserial NOT NULL,
"userId" numeric,
"addlDataType" text,
"addlDataName" text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.users (
id bigserial NOT NULL,
email text,
password text,
name text,
"userTypeCode" text,
"primaryRole" text,
"companyCode" text,
status text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.master_config_category_ref (
id bigserial NOT NULL,
"categoryName" text,
"categoryCode" text,
"categoryDescription" text,
"categoryType" text,
"parentCode" text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.master_config_ref (
id bigserial NOT NULL,
"configCode" text,
"configName" text,
"configCategoryCode" text,
"configDesc" text,
"parentCode" text,
"configType" text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.master_config_mapping (
id bigserial NOT NULL,
"configCode" text,
"companyCode" text,
"status" text,
"dispSerialNumber" text,
"defaultValue" text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.config_transcations (
id bigserial NOT NULL,
"configCode" text,
"companyCode" text,
"itemCategoryCode" text,
"itemCode" text,
"status" text,
"value" text,
"fileUrl" text,
"weight" numeric,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
);
CREATE TABLE public.config_logs (
id bigserial NOT NULL,
"tableName" text,
"prevValue" text,
"currValue" text,
"validFrom" date,
"validTill" date,
"createdAt" date,
"updatedAt" date,
"createBy" text,
"modifiedBy" text,
"deletedAt" date,
version numeric
)

10
nest-cli.json Normal file
View File

@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"assets": ["mail/templates/**/*"],
"watchAssets": true
}
}

11
nodemon.json Normal file
View File

@ -0,0 +1,11 @@
{
"watch": [
"src"
],
"ext": "ts",
"ignore": [
"src/**/*.spec.ts"
],
"exec": "node --inspect=127.0.0.1:9223 -r ts-node/register -- src/main.ts",
"env": {}
}

20337
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

88
package.json Normal file
View File

@ -0,0 +1,88 @@
{
"name": "abnandan-skeleton-be",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "node script-util.js config.local.json config.json && nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "node script-util.js config.local.json config.json && nest start",
"start:local": "node script-util.js config.local.json config.json && nest start --watch",
"start:debug": "node script-util.js config.local.json config.json && nest start --debug --watch",
"start:prod": "node dist/main",
"build:dev": "node script-util.js config.dev.json config.json && nest build && cp package.json dist/package.json && cp -r config dist/",
"build:prod": "node script-util.js config.prod.json config.json && nest build && cp package.json dist/package.json && cp -r config dist/",
"build:test": "node script-util.js config.test.json config.json && nest build && cp package.json dist/package.json && cp -r config dist/",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs-modules/mailer": "^1.10.3",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/typeorm": "^10.0.1",
"dotenv": "^16.3.1",
"handlebars": "^4.7.8",
"moment": "^2.30.1",
"nodemailer": "^6.9.9",
"otp-generator": "^4.0.1",
"pg": "^8.11.3",
"reflect-metadata": "^0.1.14",
"rxjs": "^7.8.1",
"sequelize": "^6.35.2",
"sequelize-typescript": "^2.1.6",
"typeorm": "^0.3.17"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/multer": "^1.4.11",
"@types/node": "^20.10.6",
"@types/nodemailer": "^6.4.14",
"@types/supertest": "^2.0.12",
"@types/validator": "^13.11.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"nodemon": "^3.0.2",
"prettier": "^3.0.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}

11
script-util.js Normal file
View File

@ -0,0 +1,11 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// Import the required modules
const fs = require('fs');
// Get the source and destination file paths from the command-line arguments
const sourcePath = `src/app-config/${process.argv[2]}`;
const destinationPath = `src/app-config/${process.argv[3]}`;
// Read the source file
fs.writeFileSync(destinationPath, fs.readFileSync(sourcePath));

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppConfigController } from './app-config.controller';
describe('AppConfigController', () => {
let controller: AppConfigController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AppConfigController],
}).compile();
controller = module.get<AppConfigController>(AppConfigController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

View File

@ -0,0 +1,41 @@
import { Controller, Get, Post, Query, Req, Res } from '@nestjs/common';
import { getFile, updateFile } from './file.util';
import { Request, Response } from 'express';
import { Utility } from 'src/common/Utility';
@Controller('app-config')
export class AppConfigController {
@Get('/')
async get(@Req() req: Request, @Query() query, @Res() res: Response) {
console.log('Inside Config Controller GET', query);
const filePath = (query.path) ? `${Utility.fileConfig.configPath}/${query.path}` : `${Utility.fileConfig.configPath}`;
const response = await getFile(filePath, 'UTF-8');
return res.status(200).send(response);
}
@Post('/')
async post(@Req() req: Request, @Res() res: Response) {
const filePath = `${Utility.fileConfig.configPath}`;
const fileName = (req.body && req.body.fileName) ? req.body.fileName : null;
let data = (req.body && req.body.data) ? req.body.data : null;
let resultSet = {};
console.log('Inside Config Controller Post');
console.log(`File Path ${filePath}`);
console.log(`File Name ${fileName}`);
console.log(`File Data ${data}`);
if (!filePath || !fileName || !data) {
resultSet = {
exception: true,
exceptionMessage: 'Invalid Params',
exceptionSeverity: 'high'
}
return res.status(400).send(resultSet);
}
if(typeof data === 'object') {
data = JSON.stringify(data);
}
const response = await updateFile(filePath,fileName,data);
resultSet['result'] = response;
return res.status(200).send(resultSet);
}
}

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppConfigService } from './app-config.service';
describe('AppConfigService', () => {
let service: AppConfigService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AppConfigService],
}).compile();
service = module.get<AppConfigService>(AppConfigService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

View File

@ -0,0 +1,44 @@
import { Injectable } from '@nestjs/common';
import * as configMaster from './config.json';
@Injectable()
export class AppConfigService {
defaultEnv = 'local';
constructor() {
}
private getValue(key: string, throwOnMissing = true): any {
const value = configMaster[this.defaultEnv].dbConfig[key];
if (!value && throwOnMissing) {
throw new Error(`config error - missing env.${key}`);
}
return value;
}
public ensureValues(keys: string[]) {
keys.forEach(k => this.getValue(k, true));
return this;
}
public getPort() {
return this.getValue('PORT', true);
}
public isProduction() {
const mode = this.getValue('MODE', false);
return mode != 'DEV';
}
getDbConfig() {
return configMaster[this.defaultEnv].dbConfig;
}
initializeFileSystem() {
return configMaster[this.defaultEnv].fileConfig;
}
getMailConfig() {
return configMaster[this.defaultEnv].mailConfig;
}
}

View File

@ -0,0 +1,34 @@
{
"local": {
"appConfig": {
"port": 3003
},
"dbConfig": {
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "postgres",
"database": "epr",
"MODE": "DEV",
"loggerEnabled": true
},
"fileConfig": {
"storagePath": "/opt/www/wastecare-uploads/dev",
"configPath": "/opt/wastecare/config/dev"
},
"mailConfig": {
"transport": {
"host": "smtppro.zoho.in",
"secure": true,
"port": 465,
"auth": {
"user": "admin@wct.co.in",
"pass": "Wastecare@123"
}
},
"defaults": {
"from": "\"No Reply\" <admin@wct.co.in>"
}
}
}
}

View File

@ -0,0 +1,34 @@
{
"local": {
"appConfig": {
"port": 3002
},
"dbConfig": {
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "postgres",
"database": "remedify-payment-local",
"MODE": "DEV",
"loggerEnabled": true
},
"fileConfig": {
"storagePath": "./uploads",
"configPath": "./config"
},
"mailConfig": {
"transport": {
"host": "smtppro.zoho.in",
"secure": true,
"port": 465,
"auth": {
"user": "admin@wct.co.in",
"pass": "Wastecare@123"
}
},
"defaults": {
"from": "\"No Reply\" <admin@wct.co.in>"
}
}
}
}

View File

@ -0,0 +1,34 @@
{
"local": {
"appConfig": {
"port": 3002
},
"dbConfig": {
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "postgres",
"database": "remedify-payment-local",
"MODE": "DEV",
"loggerEnabled": true
},
"fileConfig": {
"storagePath": "./uploads",
"configPath": "./config"
},
"mailConfig": {
"transport": {
"host": "smtppro.zoho.in",
"secure": true,
"port": 465,
"auth": {
"user": "admin@wct.co.in",
"pass": "Wastecare@123"
}
},
"defaults": {
"from": "\"No Reply\" <admin@wct.co.in>"
}
}
}
}

View File

@ -0,0 +1,34 @@
{
"local": {
"appConfig": {
"port": 3003
},
"dbConfig": {
"host": "127.0.0.1",
"port": 5432,
"user": "postgres",
"password": "postgres",
"database": "epr",
"MODE": "PROD",
"loggerEnabled": true
},
"fileConfig": {
"storagePath": "/opt/www/wastecare-uploads/prod",
"configPath": "/opt/wastecare/config/prod"
},
"mailConfig": {
"transport": {
"host": "smtppro.zoho.in",
"secure": true,
"port": 465,
"auth": {
"user": "admin@wct.co.in",
"pass": "Wastecare@123"
}
},
"defaults": {
"from": "\"No Reply\" <admin@wct.co.in>"
}
}
}
}

View File

@ -0,0 +1,34 @@
{
"local": {
"appConfig": {
"port": 3003
},
"dbConfig": {
"host": "127.0.0.1",
"port": 5432,
"user": "postgres",
"password": "postgres",
"database": "epr",
"MODE": "TEST",
"loggerEnabled": true
},
"fileConfig": {
"storagePath": "/opt/www/wastecare-uploads/test",
"configPath": "/opt/wastecare/config/test"
},
"mailConfig": {
"transport": {
"host": "smtppro.zoho.in",
"secure": true,
"port": 465,
"auth": {
"user": "admin@wct.co.in",
"pass": "Wastecare@123"
}
},
"defaults": {
"from": "\"No Reply\" <admin@wct.co.in>"
}
}
}
}

View File

@ -0,0 +1,82 @@
// This file should exist in `src/common/helpers`
import * as fs from 'fs';
import { promisify } from 'util';
/**
* Check if a file exists at a given path.
*
* @param {string} path
*
* @returns {boolean}
*/
export const checkIfFileOrDirectoryExists = (path: string): boolean => {
return fs.existsSync(path);
};
/**
* Gets file data from a given path via a promise interface.
*
* @param {string} path
* @param {string} encoding
*
* @returns {Promise<Buffer>}
*/
export const getFile = async (
path: string,
encoding: string,
): Promise<string | Buffer> => {
const readFile = promisify(fs.readFile);
return encoding ? readFile(path) : readFile(path, {});
};
/**
* Writes a file at a given path via a promise interface.
*
* @param {string} path
* @param {string} fileName
* @param {string} data
*
* @return {Promise<void>}
*/
export const createFile = async (
path: string,
fileName: string,
data: string,
): Promise<void> => {
if (!checkIfFileOrDirectoryExists(path)) {
fs.mkdirSync(path);
}
const writeFile = promisify(fs.writeFile);
return await writeFile(`${path}/${fileName}`, data, 'utf8');
};
export const updateFile = async (
path: string,
fileName: string,
data: string,
): Promise<void> => {
const fqdn = `${path}/${fileName}`
if (!checkIfFileOrDirectoryExists(path)) {
fs.mkdirSync(path);
}
// const writeFile = promisify(fs.writeFile);
return fs.writeFileSync(`${fqdn}`, data);
};
/**
* Delete file at the given path via a promise interface
*
* @param {string} path
*
* @returns {Promise<void>}
*/
export const deleteFile = async (path: string): Promise<void> => {
const unlink = promisify(fs.unlink);
return await unlink(path);
};

View File

@ -0,0 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});

14
src/app.controller.ts Normal file
View File

@ -0,0 +1,14 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {
this.appService.initializeSequelize();
}
@Get()
getHello(): string {
return this.appService.getHello();
}
}

40
src/app.module.ts Normal file
View File

@ -0,0 +1,40 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
// import { UserModule } from './user/user.module';
import { CommonService } from './common/common.service';
import { AppConfigService } from './app-config/app-config.service';
// import { CompanyModule } from './company/company.module';
import { DataModule } from './data/data.module';
import { MailModule } from './mail/mail.module';
import { AppConfigController } from './app-config/app-config.controller';
// import { ItemsModule } from './items/item.module';
import { MasterConfigModule } from './master-config/master-config.module';
import { ConfigModule } from './config/config.module';
import { PlanUsageModule } from './plan-usage/plan-usage.module';
import { PlansModule } from './plans/plans.module';
import { OffersRedemptionModule } from './offers-redemption/offers-redemption.module';
import { InvoiceModule } from './invoice/invoice.module';
import { OfferModule } from './offers/offers.module';
import { PaymentModule } from './payment/payment.module';
import { QuoteModule } from './quotes/quotes.module';
import { RefundsModule } from './refund/refund.module';
@Module({
imports: [
InvoiceModule,
PlansModule,
OfferModule,
OffersRedemptionModule,
PaymentModule,
PlanUsageModule,
QuoteModule,
RefundsModule,
DataModule,
MailModule,
MasterConfigModule,
ConfigModule,
],
controllers: [AppController, AppConfigController],
providers: [CommonService, AppConfigService, AppService],
})
export class AppModule {}

76
src/app.service.ts Normal file
View File

@ -0,0 +1,76 @@
import { Injectable } from '@nestjs/common';
import { CommonService } from './common/common.service';
import * as fs from 'fs';
import * as path from 'path';
import { Sequelize } from 'sequelize-typescript';
import { AppConfigService } from './app-config/app-config.service';
import { Utility } from './common/Utility';
@Injectable()
export class AppService {
modelFilePaths: string[] = [] as string[];
constructor(private commonService: CommonService, private configService: AppConfigService) { }
getHello(): string {
return 'Hello World!';
}
initializeSequelize() {
this.getModels();
const dbConfig = this.configService.getDbConfig();
if (this.modelFilePaths.length > 0) {
this.commonService.sequelize = new Sequelize({
database: dbConfig.database,
dialect: 'postgres',
username: dbConfig.user,
password: dbConfig.password,
models: this.modelFilePaths,
modelMatch: (filename, member) => {
return filename.substring(0, filename.indexOf('.entity')) === member.toLowerCase();
},
});
Utility.sequelize = this.commonService.sequelize;
}
const fileConfig = this.configService.initializeFileSystem();
this.commonService.fileConfig = fileConfig;
Utility.fileConfig = fileConfig;
const emailConfig = this.configService.getMailConfig();
this.commonService.mailConfig = emailConfig;
Utility.mailConfig = emailConfig;
}
getModels() {
this.fromDir(__dirname, '.entity', ['.js', '.ts']);
if (this.modelFilePaths.length > 0) {
}
}
fromDir(startPath, filter, extensions) {
if (!fs.existsSync(startPath) || !extensions || extensions.length === 0) {
console.log("no dir ", startPath);
return;
}
const files = fs.readdirSync(startPath);
for (let i = 0; i < files.length; i++) {
const filename = path.join(startPath, files[i]);
const stat = fs.lstatSync(filename);
if (stat.isDirectory()) {
this.fromDir(filename, filter, extensions); //recurse
} else if (filename.includes(filter)) {
extensions.map((extension) => {
if (filename.endsWith(`${filter}${extension}`)) {
this.modelFilePaths.push(filename);
}
})
};
};
}
}

View File

@ -0,0 +1,18 @@
export class Exception {
public exception: boolean;
public exceptionSeverity: 'HIGH' | 'MEDIUM' | 'LOW';
public exceptionMessage: string;
public stackTrace: any;
constructor(
exception,
exceptionSeverity,
exceptionMessage,
stackTrace = null,
) {
this.exception = exception;
this.exceptionSeverity = exceptionSeverity;
this.exceptionMessage = exceptionMessage;
this.stackTrace = stackTrace;
}
}

View File

@ -0,0 +1,14 @@
import { Exception } from "./Exception.model";
export class GenericResponse {
public notification: Exception;
data: any
constructor(
exception: Exception,
data
) {
this.notification = exception;
this.data = data;
}
}

22
src/common/Utility.ts Normal file
View File

@ -0,0 +1,22 @@
import { Sequelize } from "sequelize";
export class Utility {
static sequelize: Sequelize;
static appPort: number = 3000;
static models: any;
static fileConfig: any = {"storagePath": "./uploads"};
static mailConfig: any = {
"transport": {
"host": "smtppro.zoho.in",
"secure": true,
"port": 465,
"auth": {
"user": "admin@wct.co.in",
"pass": "Wastecare@123"
}
},
"defaults": {
"from": "\"No Reply\" <admin@wct.co.in>"
}
};
}

View File

@ -0,0 +1,13 @@
import { Injectable } from '@nestjs/common';
import {Sequelize} from 'sequelize-typescript';
@Injectable()
export class CommonService {
sequelize: Sequelize;
models: any;
fileConfig: any;
mailConfig: any;
constructor() {
}
}

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigLogsController } from './config-logs.controller';
describe('ConfigLogsController', () => {
let controller: ConfigLogsController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ConfigLogsController],
}).compile();
controller = module.get<ConfigLogsController>(ConfigLogsController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

View File

@ -0,0 +1,103 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Response } from 'express';
import { ConfigLogsService } from './config-logs.service';
import ConfigLog from './config-logs.entity';
import { GenericResponse } from 'src/common/GenericResponse.model';
@Controller('config/logs')
export class ConfigLogsController {
constructor(private configService: ConfigLogsService) {}
@Get("/all")
async getAll(@Res() res: Response) {
const response = await this.configService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Get(':id')
async findById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.configService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/filter')
async filter(@Body() config: ConfigLog, @Res() res: Response) {
if(!config) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.configService.filter(config) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post()
async insert(@Body() config: ConfigLog, @Res() res: Response) {
if(!config) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
delete config.id;
const response = await this.configService.upsert(config, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async update(@Body() config: ConfigLog, @Res() res: Response) {
if(!config || !config.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.configService.upsert(config, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async deleteById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.configService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

View File

@ -0,0 +1,29 @@
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
@Table({tableName: 'config_logs'})
export default class ConfigLog extends Model {
@Column({type: DataType.TEXT})
tableName: string;
@Column({type: DataType.TEXT})
prevValue: string;
@Column({type: DataType.TEXT})
currValue: string;
@Default(new Date())
@Column({type: DataType.DATEONLY})
validFrom: Date;
@Default(new Date("2070-12-31"))
@Column({type: DataType.DATEONLY})
validTill: Date;
@Column({type: DataType.TEXT})
createBy: string;
@Column({type: DataType.TEXT})
modifiedBy: string;
}

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigLogsService } from './config-logs.service';
describe('ConfigLogsService', () => {
let service: ConfigLogsService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ConfigLogsService],
}).compile();
service = module.get<ConfigLogsService>(ConfigLogsService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

View File

@ -0,0 +1,37 @@
import { Injectable } from '@nestjs/common';
import ConfigLog from './config-logs.entity';
@Injectable()
export class ConfigLogsService {
async findAll(): Promise<{rows: ConfigLog[], count: number}> {
return ConfigLog.findAndCountAll();
}
findByPk(id: number): Promise<ConfigLog> {
return ConfigLog.findByPk(id)
}
filter(config: ConfigLog) : Promise<ConfigLog[]> {
return ConfigLog.findAll({where: config as any})
}
findOne(config: ConfigLog): Promise<ConfigLog> {
return ConfigLog.findOne({where: config as any})
}
async remove(id: number): Promise<number> {
return ConfigLog.destroy({where: {id: id}});
}
async upsert(config: ConfigLog, insertIfNotFound: boolean): Promise<ConfigLog | [affectedCount: number]> {
if(config.id) {
const existingUser = await this.findByPk(config.id);
if(existingUser) {
return ConfigLog.update(config, {where: {id: config.id}});
}
}
if(insertIfNotFound) {
return ConfigLog.create(config as any)
}
}
}

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigController } from './config.controller';
describe('ConfigController', () => {
let controller: ConfigController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ConfigController],
}).compile();
controller = module.get<ConfigController>(ConfigController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

View File

@ -0,0 +1,104 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Response } from 'express';
import { ConfigService } from './config.service';
import Config from './config.entity';
import { GenericResponse } from 'src/common/GenericResponse.model';
@Controller('config')
export class ConfigController {
constructor(private configService: ConfigService) {}
@Get("/all")
async getAll(@Res() res: Response) {
const response = await this.configService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Get(':id')
async findById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.configService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/filter')
async filter(@Body() config: Config, @Res() res: Response) {
if(!config) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.configService.filter(config) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post()
async insert(@Body() config: Config, @Res() res: Response) {
if(!config) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
delete config.id;
const response = await this.configService.upsert(config, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async update(@Body() config: Config, @Res() res: Response) {
if(!config || !config.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.configService.upsert(config, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async deleteById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.configService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

View File

@ -0,0 +1,44 @@
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
@Table({tableName: 'config_transcations'})
export default class Config extends Model {
@Column({type: DataType.TEXT})
configCode: string;
@Column({type: DataType.TEXT})
companyCode: string;
@Column({type: DataType.TEXT})
itemCategoryCode: string;
@Column({type: DataType.TEXT})
itemCode: string;
@Column({type: DataType.TEXT})
status: string;
@Column({type: DataType.TEXT})
value: string;
@Column({type: DataType.TEXT})
fileUrl: string;
@Column({type: DataType.NUMBER})
weight: string;
@Default(new Date())
@Column({type: DataType.DATEONLY})
validFrom: Date;
@Default(new Date("2070-12-31"))
@Column({type: DataType.DATEONLY})
validTill: Date;
@Column({type: DataType.TEXT})
createBy: string;
@Column({type: DataType.TEXT})
modifiedBy: string;
}

View File

@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { ConfigController } from './config.controller';
import { ConfigService } from './config.service';
import { ConfigLogsController } from './config-logs/config-logs.controller';
import { ConfigLogsService } from './config-logs/config-logs.service';
@Module({
controllers: [ConfigController, ConfigLogsController],
providers: [ConfigService, ConfigLogsService]
})
export class ConfigModule {}

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigService } from './config.service';
describe('ConfigService', () => {
let service: ConfigService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ConfigService],
}).compile();
service = module.get<ConfigService>(ConfigService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

View File

@ -0,0 +1,37 @@
import { Injectable } from '@nestjs/common';
import Config from './config.entity';
@Injectable()
export class ConfigService {
async findAll(): Promise<{rows: Config[], count: number}> {
return Config.findAndCountAll();
}
findByPk(id: number): Promise<Config> {
return Config.findByPk(id)
}
filter(config: Config) : Promise<Config[]> {
return Config.findAll({where: config as any})
}
findOne(config: Config): Promise<Config> {
return Config.findOne({where: config as any})
}
async remove(id: number): Promise<number> {
return Config.destroy({where: {id: id}});
}
async upsert(config: Config, insertIfNotFound: boolean): Promise<Config | [affectedCount: number]> {
if(config.id) {
const existingUser = await this.findByPk(config.id);
if(existingUser) {
return Config.update(config, {where: {id: config.id}});
}
}
if(insertIfNotFound) {
return Config.create(config as any)
}
}
}

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { DataController } from './data.controller';
describe('DataController', () => {
let controller: DataController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [DataController],
}).compile();
controller = module.get<DataController>(DataController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

132
src/data/data.controller.ts Normal file
View File

@ -0,0 +1,132 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { GenericResponse } from 'src/common/GenericResponse.model';
import DataModel from './data.entity';
import { DataService } from './data.service';
import { Response } from 'express';
@Controller('data')
export class DataController {
constructor(private dataService: DataService) {}
@Get("/all")
async getAllUsers(@Res() res: Response) {
const response: any = await this.dataService.findAll() || [];
res.send((response && response.rows) ? response.rows : []);
}
@Get(':id')
async findById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.dataService.findByPk(id) || {};
res.send(response);
}
@Post('/:endPtNm/:opType')
async performOperation(@Param('endPtNm') endPtNm: string, @Param('opType') opType: string, @Body() body, @Res() res: Response) {
if(!opType || !endPtNm) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response: DataModel = await this.dataService.findOne({endPtNm: endPtNm, opsTypeName: opType.toUpperCase()} as any);
if(response && response.sqlQueryText) {
if(body) {
for(const key in body) {
response.sqlQueryText = response.sqlQueryText.replaceAll(`:${key}`, (typeof body[key] === 'string') ? `'${body[key]}'` : body[key]);
}
}
let dataResponse = await this.dataService.executeQuery(response.sqlQueryText);
if(dataResponse && dataResponse.length && Array.isArray(dataResponse[0])) {
dataResponse = dataResponse[0];
}
res.send(dataResponse);
return;
}
return new GenericResponse(null, []);
}
@Post('/filter')
async filter(@Body() quote: DataModel, @Res() res: Response) {
if(!quote) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.dataService.filter(quote) || [];
res.send(response);
}
@Post()
async insert(@Body() quote: DataModel, @Res() res: Response) {
if(!quote) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
delete quote.id;
const response = await this.dataService.upsert(quote, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async update(@Body() quote: DataModel, @Res() res: Response) {
if(!quote || !quote.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.dataService.upsert(quote, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async deleteById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.dataService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

29
src/data/data.entity.ts Normal file
View File

@ -0,0 +1,29 @@
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
@Table({tableName: 'crud_config_info'})
export default class DataModel extends Model {
@Column({type: DataType.NUMBER})
endPtNm: number;
@Column({type: DataType.TEXT})
sqlQueryText: string;
@Column({type: DataType.TEXT})
opsTypeName: string;
@Default(new Date())
@Column({type: DataType.DATEONLY})
validFrom: Date;
@Default(new Date("2070-12-31"))
@Column({type: DataType.DATEONLY})
validTill: Date;
@Column({type: DataType.TEXT})
createBy: string;
@Column({type: DataType.TEXT})
modifiedBy: string;
}

9
src/data/data.module.ts Normal file
View File

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { DataService } from './data.service';
import { DataController } from './data.controller';
@Module({
providers: [DataService],
controllers: [DataController]
})
export class DataModule {}

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { DataService } from './data.service';
describe('DataService', () => {
let service: DataService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [DataService],
}).compile();
service = module.get<DataService>(DataService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

44
src/data/data.service.ts Normal file
View File

@ -0,0 +1,44 @@
import { Injectable } from '@nestjs/common';
import DataModel from './data.entity';
import { Utility } from 'src/common/Utility';
@Injectable()
export class DataService {
constructor() { }
async findAll(): Promise<{rows: DataModel[], count: number}> {
return DataModel.findAndCountAll();
}
findByPk(id: number): Promise<DataModel> {
return DataModel.findByPk(id)
}
findOne(dataDetail: DataModel): Promise<DataModel> {
return DataModel.findOne({where: dataDetail as any})
}
filter(dataDetail: DataModel) : Promise<DataModel[]> {
return DataModel.findAll({where: dataDetail as any})
}
async remove(id: number): Promise<number> {
return DataModel.destroy({where: {id: id}});
}
async upsert(dataDetail: DataModel, insertIfNotFound: boolean): Promise<DataModel | [affectedCount: number]> {
if(dataDetail.id) {
const existingUser = await this.findByPk(dataDetail.id);
if(existingUser) {
return DataModel.update(dataDetail, {where: {id: dataDetail.id}});
}
}
if(insertIfNotFound) {
return DataModel.create(dataDetail as any)
}
}
executeQuery(sqlQueryText: string): Promise<any> {
return Utility.sequelize.query(sqlQueryText);
}
}

View File

@ -0,0 +1,103 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Response } from 'express';
import { InvoicesService } from './invoice.service';
import { GenericResponse } from 'src/common/GenericResponse.model';
import Invoice from './invoice.entity';
@Controller('invoice')
export class InvoicesController {
constructor(private invoiceService: InvoicesService) { }
@Get("/all")
async getAll(@Res() res: Response) {
const response = await this.invoiceService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Get(':id')
async findById(@Param('id') id: number, @Res() res: Response) {
if (!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_IN_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.invoiceService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/filter')
async filter(@Body() user: Invoice, @Res() res: Response) {
if (!user) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.invoiceService.filter(user) || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post()
async insert(@Body() user: Invoice, @Res() res: Response) {
if (!user) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
delete user.id;
const response = await this.invoiceService.upsert(user, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async update(@Body() user: Invoice, @Res() res: Response) {
if (!user || !user.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.invoiceService.upsert(user, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async deleteById(@Param('id') id: number, @Res() res: Response) {
if (!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.invoiceService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

View File

@ -0,0 +1,61 @@
import { Table, Column, Model, Default, DataType, ForeignKey } from 'sequelize-typescript';
import Payment from 'src/payment/payment.entity';
@Table({ tableName: 'invoice' })
export default class Invoice extends Model {
@Column({ type: DataType.BIGINT, allowNull: false })
user_id: number;
@ForeignKey(() => Payment)
@Column({ type: DataType.BIGINT, allowNull: false, field: 'payment_id' })
payment_id: number;
@Column({ type: DataType.TEXT, field: 'invoice_number' })
invoice_number: string;
@Column({ type: DataType.NUMBER, field: 'amount' })
amount: number;
@Column({ type: DataType.NUMBER, field: 'remaining_balance' })
remaining_balance: number;
@Column({ type: DataType.NUMBER, field: 'tax' })
tax: number;
@Column({ type: DataType.DATEONLY, field: 'issue_date' })
issue_date: Date;
@Column({ type: DataType.DATEONLY, field: 'due_date' })
due_date: Date;
@Column({ type: DataType.TEXT, field: 'status' })
status: string;
@Default(new Date())
@Column({ type: DataType.DATEONLY, field: 'validFrom' })
valid_from: Date;
@Default(new Date("2070-12-31"))
@Column({ type: DataType.DATEONLY, field: 'validTill' })
valid_till: Date;
@Column({ type: DataType.DATEONLY, field: 'createdAt' })
created_at: Date;
@Column({ type: DataType.DATEONLY, field: 'updatedAt' })
updated_at: Date;
@Column({ type: DataType.TEXT, field: 'createdBy' })
created_by: string;
@Column({ type: DataType.TEXT, field: 'modifiedBy' })
modified_by: string;
@Column({ type: DataType.DATEONLY, field: 'deletedAt' })
deleted_at: Date;
@Column({ type: DataType.NUMBER, field: 'version' })
version: number;
}

View File

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { InvoicesService } from './invoice.service';
import { InvoicesController } from './invoice.controller';
@Module({
imports: [],
providers: [InvoicesService],
controllers: [InvoicesController]
})export class InvoiceModule {}

View File

@ -0,0 +1,37 @@
import { Injectable } from '@nestjs/common';
import Invoice from './invoice.entity';
@Injectable()
export class InvoicesService {
async findAll(): Promise<{rows: Invoice[], count: number}> {
return Invoice.findAndCountAll();
}
findByPk(id: number): Promise<Invoice> {
return Invoice.findByPk(id)
}
filter(userAdditionalDetail: Invoice) : Promise<Invoice[]> {
return Invoice.findAll({where: userAdditionalDetail as any})
}
findOne(user: Invoice): Promise<Invoice> {
return Invoice.findOne({where: user as any})
}
async remove(id: number): Promise<number> {
return Invoice.destroy({where: {id: id}});
}
async upsert(invoice: Invoice, insertIfNotFound: boolean): Promise<Invoice | [affectedCount: number]> {
if(invoice.id) {
const existingUser = await this.findByPk(invoice.id);
if(existingUser) {
return Invoice.update(invoice, {where: {id: invoice.id}});
}
}
if(insertIfNotFound) {
return Invoice.create(invoice as any)
}
}
}

27
src/mail/mail.module.ts Normal file
View File

@ -0,0 +1,27 @@
import { MailerModule } from '@nestjs-modules/mailer';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
import { Module } from '@nestjs/common';
import { MailService } from './mail.service';
import { join } from 'path';
import { Utility } from 'src/common/Utility';
@Module({
imports: [
MailerModule.forRoot({
// transport: 'smtps://user@example.com:topsecret@smtp.example.com',
// or
transport: Utility.mailConfig.transport,
defaults: Utility.mailConfig.defaults,
template: {
dir: join(__dirname, 'templates'),
adapter: new HandlebarsAdapter(), // or new PugAdapter() or new EjsAdapter()
options: {
strict: true,
},
},
}),
],
providers: [MailService],
exports: [MailService], // 👈 export for DI
})
export class MailModule {}

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { MailService } from './mail.service';
describe('MailService', () => {
let service: MailService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [MailService],
}).compile();
service = module.get<MailService>(MailService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

19
src/mail/mail.service.ts Normal file
View File

@ -0,0 +1,19 @@
import { MailerService } from '@nestjs-modules/mailer';
import { Injectable } from '@nestjs/common';
@Injectable()
export class MailService {
constructor(private mailerService: MailerService) { }
async sendEmail(templateName: string, subject: string, context: any, toEmail: string, ccEmails?: string[], bccEmails?: string[]) {
await this.mailerService.sendMail({
to: toEmail,
cc: ccEmails,
bcc: bccEmails,
subject: subject,
template: templateName, // `.hbs` extension is appended automatically
context,
})
}
}

View File

@ -0,0 +1,82 @@
<head>
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.gjs-row {
display: flex;
justify-content: flex-start;
align-items: stretch;
flex-wrap: nowrap;
padding: 10px;
}
.gjs-cell {
min-height: 75px;
flex-grow: 1;
flex-basis: 100%;
}
#im43 {
background-repeat: repeat;
background-position: left top;
background-attachment: scroll;
background-size: auto;
background-image: linear-gradient(#39960c 0%, #39960c 100%);
}
#ij93 {
padding: 10px;
}
#ilfj {
color: #ffffff;
text-align: left;
font-weight: 900;
font-size: 3rem;
}
#ihfp {
height: 577px;
}
#i23r {
padding: 10px;
}
@media (max-width: 768px) {
.gjs-row {
flex-wrap: wrap;
}
}
</style>
</head>
<body id="iohk">
<div class="gjs-row" id="iir1">
<div class="gjs-cell" id="im43">
<div id="ij93">
<span id="ilfj">Waste Care Technologies</span>
</div>
</div>
</div>
<div class="gjs-row" id="ihfp">
<div class="gjs-cell">
<div id="i23r">Dear {{ name }},
<br />
<br />Welcome to Waste Care Technologies.
<br />
<br />Use Password {{ password }} to login to your account.
<br />
<br />Contact our Support if you need any queries.
<br />
<br />Thank you for choosing us
</div>
</div>
</div>
</body>

View File

@ -0,0 +1,79 @@
<head>
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.gjs-row {
display: flex;
justify-content: flex-start;
align-items: stretch;
flex-wrap: nowrap;
padding: 10px;
}
.gjs-cell {
min-height: 75px;
flex-grow: 1;
flex-basis: 100%;
}
#im43 {
background-repeat: repeat;
background-position: left top;
background-attachment: scroll;
background-size: auto;
background-image: linear-gradient(#39960c 0%, #39960c 100%);
}
#ij93 {
padding: 10px;
}
#ilfj {
color: #ffffff;
text-align: left;
font-weight: 900;
font-size: 3rem;
}
#ihfp {
height: 577px;
}
#i23r {
padding: 10px;
}
@media (max-width: 768px) {
.gjs-row {
flex-wrap: wrap;
}
}
</style>
</head>
<body id="iohk">
<div class="gjs-row" id="iir1">
<div class="gjs-cell" id="im43">
<div id="ij93">
<span id="ilfj">Waste Care Technologies</span>
</div>
</div>
</div>
<div class="gjs-row" id="ihfp">
<div class="gjs-cell" id="ihbs">
<div id="i23r">Dear {{ email }},
<br/>
<br/>A Quote with {{ quoteID }} is created by you.
<br/>
<br/>Current Quote is in {{ status }} status.
<br/>
<br/>Thank you for choosing us
</div>
</div>
</div>
</body>

16
src/main.ts Normal file
View File

@ -0,0 +1,16 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as bodyParser from 'body-parser';
import * as configMaster from './app-config/config.json';
import { Utility } from './common/Utility';
async function bootstrap() {
Utility.appPort = configMaster.local.appConfig.port;
Utility.mailConfig = configMaster.local.mailConfig;
Utility.fileConfig = configMaster.local.fileConfig;
const app = await NestFactory.create(AppModule, { cors: true });
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
await app.listen(Utility.appPort);
}
bootstrap();

View File

@ -0,0 +1,104 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Response } from 'express';
import { GenericResponse } from 'src/common/GenericResponse.model';
import MasterConfigCategory from './master-config-category.entity';
import { MasterConfigCategoryService } from './master-config-category.service';
@Controller('master-config/category')
export class MasterConfigCategoryController {
constructor(private masterConfigService: MasterConfigCategoryService) { }
@Get("/all")
async getAll(@Res() res: Response) {
const response = await this.masterConfigService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Get(':id')
async findById(@Param('id') id: number, @Res() res: Response) {
if (!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_IN_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.masterConfigService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/filter')
async filter(@Body() masterConfig: MasterConfigCategory, @Res() res: Response) {
if (!masterConfig) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.masterConfigService.filter(masterConfig) || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post()
async insert(@Body() masterConfig: MasterConfigCategory, @Res() res: Response) {
if (!masterConfig) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
delete masterConfig.id;
const response = await this.masterConfigService.upsert(masterConfig, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async update(@Body() masterConfig: MasterConfigCategory, @Res() res: Response) {
if (!masterConfig || !masterConfig.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.masterConfigService.upsert(masterConfig, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async deleteById(@Param('id') id: number, @Res() res: Response) {
if (!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.masterConfigService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

View File

@ -0,0 +1,34 @@
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
@Table({tableName: 'master_config_category_ref'})
export default class MasterConfigCategory extends Model {
@Column({type: DataType.TEXT})
categoryName: string;
@Column({type: DataType.TEXT})
categoryCode: number;
@Column({type: DataType.TEXT})
categoryDescription: string;
@Column({type: DataType.TEXT})
categoryType: string;
@Column({type: DataType.TEXT})
parentCode: string;
@Default(new Date())
@Column({type: DataType.DATEONLY})
validFrom: Date;
@Default(new Date("2070-12-31"))
@Column({type: DataType.DATEONLY})
validTill: Date;
@Column({type: DataType.TEXT})
createBy: string;
@Column({type: DataType.TEXT})
modifiedBy: string;
}

View File

@ -0,0 +1,37 @@
import { Injectable } from '@nestjs/common';
import MasterConfigCategory from './master-config-category.entity';
@Injectable()
export class MasterConfigCategoryService {
async findAll(): Promise<{rows: MasterConfigCategory[], count: number}> {
return MasterConfigCategory.findAndCountAll();
}
findByPk(id: number): Promise<MasterConfigCategory> {
return MasterConfigCategory.findByPk(id)
}
filter(masterConfig: MasterConfigCategory) : Promise<MasterConfigCategory[]> {
return MasterConfigCategory.findAll({where: masterConfig as any})
}
findOne(masterConfig: MasterConfigCategory): Promise<MasterConfigCategory> {
return MasterConfigCategory.findOne({where: masterConfig as any})
}
async remove(id: number): Promise<number> {
return MasterConfigCategory.destroy({where: {id: id}});
}
async upsert(masterConfig: MasterConfigCategory, insertIfNotFound: boolean): Promise<MasterConfigCategory | [affectedCount: number]> {
if(masterConfig.id) {
const existingmasterConfig = await this.findByPk(masterConfig.id);
if(existingmasterConfig) {
return MasterConfigCategory.update(masterConfig, {where: {id: masterConfig.id}});
}
}
if(insertIfNotFound) {
return MasterConfigCategory.create(masterConfig as any)
}
}
}

View File

@ -0,0 +1,105 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Response } from 'express';
import { GenericResponse } from 'src/common/GenericResponse.model';
import { MasterConfigMappingService } from './master-config-mapping.service';
import MasterConfigMapping from './master-config-mapping.entity';
@Controller('master-config/mapping')
export class MasterConfigMappingController {
constructor(private masterConfigService: MasterConfigMappingService) {
}
@Get("/all")
async getAll(@Res() res: Response) {
const response = await this.masterConfigService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Get(':id')
async findById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_IN_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.masterConfigService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/filter')
async filter(@Body() masterConfig: MasterConfigMapping, @Res() res: Response) {
if(!masterConfig) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.masterConfigService.filter(masterConfig) || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post()
async insert(@Body() masterConfig: MasterConfigMapping, @Res() res: Response) {
if(!masterConfig) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
delete masterConfig.id;
const response = await this.masterConfigService.upsert(masterConfig, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async update(@Body() masterConfig: MasterConfigMapping, @Res() res: Response) {
if(!masterConfig || !masterConfig.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.masterConfigService.upsert(masterConfig, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async deleteById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.masterConfigService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

View File

@ -0,0 +1,34 @@
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
@Table({tableName: 'master_config_mapping'})
export default class MasterConfigMapping extends Model {
@Column({type: DataType.TEXT})
configCode: string;
@Column({type: DataType.TEXT})
companyCode: string;
@Column({type: DataType.TEXT})
status: string;
@Column({type: DataType.TEXT})
dispSerialNumber: string;
@Column({type: DataType.TEXT})
defaultValue: string;
@Default(new Date())
@Column({type: DataType.DATEONLY})
validFrom: Date;
@Default(new Date("2070-12-31"))
@Column({type: DataType.DATEONLY})
validTill: Date;
@Column({type: DataType.TEXT})
createBy: string;
@Column({type: DataType.TEXT})
modifiedBy: string;
}

View File

@ -0,0 +1,39 @@
import { Injectable } from '@nestjs/common';
import MasterConfigMapping from './master-config-mapping.entity';
@Injectable()
export class MasterConfigMappingService {
async findAll(): Promise<{rows: MasterConfigMapping[], count: number}> {
return MasterConfigMapping.findAndCountAll();
}
findByPk(id: number): Promise<MasterConfigMapping> {
return MasterConfigMapping.findByPk(id)
}
filter(masterConfig: MasterConfigMapping) : Promise<MasterConfigMapping[]> {
return MasterConfigMapping.findAll({where: masterConfig as any})
}
findOne(masterConfig: MasterConfigMapping): Promise<MasterConfigMapping> {
return MasterConfigMapping.findOne({where: masterConfig as any})
}
async remove(id: number): Promise<number> {
return MasterConfigMapping.destroy({where: {id: id}});
}
async upsert(masterConfig: MasterConfigMapping, insertIfNotFound: boolean): Promise<MasterConfigMapping | [affectedCount: number]> {
if(masterConfig.id) {
const existingUser = await this.findByPk(masterConfig.id);
if(existingUser) {
return MasterConfigMapping.update(masterConfig, {where: {id: masterConfig.id}});
}
}
if(insertIfNotFound) {
return MasterConfigMapping.create(masterConfig as any)
}
}
}

View File

@ -0,0 +1,102 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { MasterConfigService } from './master-config.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import MasterConfig from './master-config.entity';
@Controller('master-config')
export class MasterConfigController {
constructor(private masterConfigService: MasterConfigService) {}
@Get("/all")
async getAll(@Res() res: Response) {
const response = await this.masterConfigService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Get(':id')
async findById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.masterConfigService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/filter')
async filter(@Body() masterConfig: MasterConfig, @Res() res: Response) {
if(!masterConfig) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.masterConfigService.filter(masterConfig) || [];
const httpResponse = new GenericResponse(null, response)
res.status(200).send(httpResponse);
}
@Post()
async insert(@Body() masterConfig: MasterConfig, @Res() res: Response) {
if(!masterConfig) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.masterConfigService.upsert(masterConfig, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async update(@Body() masterConfig: MasterConfig, @Res() res: Response) {
if(!masterConfig || !masterConfig.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.masterConfigService.upsert(masterConfig, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async deleteById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.masterConfigService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

View File

@ -0,0 +1,38 @@
import { Table, Column, Model, Default, DataType, Unique } from 'sequelize-typescript';
@Table({tableName: 'master_config_ref'})
export default class MasterConfig extends Model {
@Unique(true)
@Column({type: DataType.TEXT})
configCode: string;
@Column({type: DataType.TEXT})
configName: string;
@Column({type: DataType.TEXT})
configCategoryCode: string;
@Column({type: DataType.TEXT})
configDesc: string;
@Column({type: DataType.TEXT})
parentCode: string;
@Column({type: DataType.TEXT})
configType: string;
@Default(new Date())
@Column({type: DataType.DATEONLY})
validFrom: Date;
@Default(new Date("2070-12-31"))
@Column({type: DataType.DATEONLY})
validTill: Date;
@Column({type: DataType.TEXT})
createBy: string;
@Column({type: DataType.TEXT})
modifiedBy: string;
}

View File

@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { MasterConfigMappingController } from './master-config-mapping/master-config-mapping.controller';
import { MasterConfigCategoryController } from './master-config-category/master-config-category.controller';
import { MasterConfigController } from './master-config.controller';
import { MasterConfigService } from './master-config.service';
import { MasterConfigMappingService } from './master-config-mapping/master-config-mapping.service';
import { MasterConfigCategoryService } from './master-config-category/master-config-category.service';
@Module({
controllers: [MasterConfigController, MasterConfigMappingController, MasterConfigCategoryController],
providers: [MasterConfigService, MasterConfigMappingService, MasterConfigCategoryService],
imports: []
})
export class MasterConfigModule { }

View File

@ -0,0 +1,43 @@
import { Injectable } from '@nestjs/common';
import MasterConfig from './master-config.entity';
@Injectable()
export class MasterConfigService {
constructor() { }
async findAll(): Promise<{rows: MasterConfig[], count: number}> {
return MasterConfig.findAndCountAll();
}
findByPk(id: number): Promise<MasterConfig> {
return MasterConfig.findByPk(id)
}
findOne(masterConfig: MasterConfig): Promise<MasterConfig> {
return MasterConfig.findOne({where: masterConfig as any})
}
filter(masterConfig: MasterConfig) : Promise<MasterConfig[]> {
return MasterConfig.findAll({where: masterConfig as any})
}
async remove(id: number): Promise<number> {
return MasterConfig.destroy({where: {id: id}});
}
async upsert(masterConfig: MasterConfig, insertIfNotFound: boolean): Promise<MasterConfig | [affectedCount: number]> {
if(masterConfig.id) {
const existingUser = await this.findByPk(masterConfig.id);
if(existingUser) {
return MasterConfig.update(masterConfig, {where: {id: masterConfig.id}});
}
}
if(insertIfNotFound) {
return MasterConfig.create(masterConfig as any)
}
}
async login(masterConfig: MasterConfig): Promise<MasterConfig> {
return MasterConfig.findOne({where: masterConfig as any})
}
}

View File

@ -0,0 +1,103 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Response } from 'express';
import { OffersRedemptionsService } from './offers-redemption.service';
import { GenericResponse } from 'src/common/GenericResponse.model';
import OffersRedemption from './offers-redemption.entity';
@Controller('offers-redemption')
export class OffersRedemptionsController {
constructor(private offersRedemptionService: OffersRedemptionsService) {}
@Get("/all")
async getAllCompanys(@Res() res: Response) {
const response = await this.offersRedemptionService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Get(':id')
async findById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.offersRedemptionService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/filter')
async filter(@Body() offersRedemption: OffersRedemption, @Res() res: Response) {
if(!offersRedemption) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.offersRedemptionService.findOne(offersRedemption) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post()
async insert(@Body() offersRedemption: OffersRedemption, @Res() res: Response) {
if(!offersRedemption) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
delete offersRedemption.id;
const response = await this.offersRedemptionService.upsert(offersRedemption, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async update(@Body() offersRedemption: OffersRedemption, @Res() res: Response) {
if(!offersRedemption || !offersRedemption.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.offersRedemptionService.upsert(offersRedemption, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async deleteById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.offersRedemptionService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

View File

@ -0,0 +1,46 @@
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
@Table({ tableName: 'offers_redemption' })
export default class OfferRedemption extends Model {
@Column(DataType.BIGINT)
user_id: number;
@Column(DataType.BIGINT)
offer_id: number;
@Column(DataType.BIGINT)
payment_id: number;
@Column(DataType.DATEONLY)
redemption_date: Date;
@Column(DataType.TEXT)
status: string;
@Default(new Date())
@Column(DataType.DATEONLY)
validFrom: Date;
@Default(new Date("2070-12-31"))
@Column(DataType.DATEONLY)
validTill: Date;
@Column(DataType.DATEONLY)
createdAt: Date;
@Column(DataType.DATEONLY)
updatedAt: Date;
@Column(DataType.TEXT)
createdBy: string;
@Column(DataType.TEXT)
modifiedBy: string;
@Column(DataType.DATEONLY)
deletedAt: Date;
@Column(DataType.NUMBER)
version: number;
}

View File

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { OffersRedemptionsService } from './offers-redemption.service';
import { OffersRedemptionsController } from './offers-redemption.controller';
@Module({
providers:[OffersRedemptionsService],
controllers:[OffersRedemptionsController]
})
export class OffersRedemptionModule {}

View File

@ -0,0 +1,33 @@
import { Injectable } from '@nestjs/common';
import OffersRedemption from './offers-redemption.entity';
@Injectable()
export class OffersRedemptionsService {
async findAll(): Promise<{rows: OffersRedemption[], count: number}> {
return OffersRedemption.findAndCountAll();
}
findByPk(id: number): Promise<OffersRedemption> {
return OffersRedemption.findByPk(id)
}
findOne(offersRedemption: OffersRedemption): Promise<OffersRedemption> {
return OffersRedemption.findOne({where: offersRedemption as any})
}
async remove(id: number): Promise<number> {
return OffersRedemption.destroy({where: {id: id}});
}
async upsert(offersRedemption: OffersRedemption, insertIfNotFound: boolean): Promise<OffersRedemption | [affectedCount: number]> {
if(offersRedemption.id) {
const existingUser = await this.findByPk(offersRedemption.id);
if(existingUser) {
return OffersRedemption.update(offersRedemption, {where: {id: offersRedemption.id}});
}
}
if(insertIfNotFound) {
return OffersRedemption.create(offersRedemption as any)
}
}
}

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CompanyController } from './company.controller';
describe('CompanyController', () => {
let controller: CompanyController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [CompanyController],
}).compile();
controller = module.get<CompanyController>(CompanyController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

View File

@ -0,0 +1,103 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { OfferService } from './offers.service';
import { Response } from 'express';
import { GenericResponse } from 'src/common/GenericResponse.model';
import Offer from './offers.entity';
@Controller('offers')
export class OfferController {
constructor(private offersService: OfferService) {}
@Get("/all")
async getAllOffers(@Res() res: Response) {
const response = await this.offersService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Get(':id')
async findById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.offersService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/filter')
async filter(@Body() offers: Offer, @Res() res: Response) {
if(!offers) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.offersService.filter(offers) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post()
async insert(@Body() offers: Offer, @Res() res: Response) {
if(!offers) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
delete offers.id;
const response = await this.offersService.upsert(offers, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async update(@Body() offers: Offer, @Res() res: Response) {
if(!Offer || !offers.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.offersService.upsert(offers, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async deleteById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.offersService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

View File

@ -0,0 +1,43 @@
import { Table, Column, Model, Default, DataType, Unique } from 'sequelize-typescript';
@Table({ tableName: 'offers' })
export default class Offer extends Model {
@Column(DataType.TEXT)
code: string;
@Column(DataType.TEXT)
description: string;
@Column(DataType.NUMBER)
discount_value: number;
@Column(DataType.TEXT)
status: string;
@Default(new Date())
@Column(DataType.DATEONLY)
validFrom: Date;
@Default(new Date("2070-12-31"))
@Column(DataType.DATEONLY)
validTill: Date;
@Column(DataType.DATEONLY)
createdAt: Date;
@Column(DataType.DATEONLY)
updatedAt: Date;
@Column(DataType.TEXT)
createdBy: string;
@Column(DataType.TEXT)
modifiedBy: string;
@Column(DataType.DATEONLY)
deletedAt: Date;
@Column(DataType.NUMBER)
version: number;
}

View File

@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { OfferController } from './offers.controller';
import { OfferService } from './offers.service';
@Module({
imports: [],
providers: [OfferService],
controllers: [OfferController]
})
export class OfferModule { }

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CompanyService } from './company.service';
describe('CompanyService', () => {
let service: CompanyService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [CompanyService],
}).compile();
service = module.get<CompanyService>(CompanyService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

View File

@ -0,0 +1,38 @@
import { Injectable } from '@nestjs/common';
import Offer from './offers.entity';
@Injectable()
export class OfferService {
async findAll(): Promise<{rows: Offer[], count: number}> {
return Offer.findAndCountAll();
}
findByPk(id: number): Promise<Offer> {
return Offer.findByPk(id, )
}
filter(offers: Offer) : Promise<Offer[]> {
return Offer.findAll({where: offers as any})
}
findOne(offers: Offer): Promise<Offer> {
return Offer.findOne({where: offers as any})
}
async remove(id: number): Promise<number> {
return Offer.destroy({where: {id: id}});
}
async upsert(offers: Offer, insertIfNotFound: boolean): Promise<Offer | [affectedCount: number]> {
if(offers.id) {
const existingUser = await this.findByPk(offers.id);
if(existingUser) {
return Offer.update(offers, {where: {id: offers.id}});
}
}
if(insertIfNotFound) {
return Offer.create(offers as any)
}
}
}

View File

@ -0,0 +1,105 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { PaymentService } from './payment.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import Payment from './payment.entity';
@Controller('payments')
export class PaymentController {
constructor(private paymentService: PaymentService) { }
@Get("/all")
async getAllPayments(@Res() res: Response) {
const response = await this.paymentService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Get(':id')
async findById(@Param('id') id: number, @Res() res: Response) {
if (!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.paymentService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/filter')
async filter(@Body() payment: Payment, @Res() res: Response) {
if (!payment) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.paymentService.filter(payment) || [];
const httpResponse = new GenericResponse(null, response)
res.status(200).send(httpResponse);
}
@Post()
async insert(@Body() payment: Payment, @Res() res: Response) {
if (!payment) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
delete payment.id;
const response = await this.paymentService.upsert(payment, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async update(@Body() payment: Payment, @Res() res: Response) {
if (!payment || !payment.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.paymentService.upsert(payment, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async deleteById(@Param('id') id: number, @Res() res: Response) {
if (!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.paymentService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

View File

@ -0,0 +1,58 @@
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
@Table({ tableName: 'payment' })
export default class Payment extends Model {
@Column(DataType.BIGINT)
user_id: number;
@Column(DataType.NUMBER)
amount: number;
@Column(DataType.DATEONLY)
payment_date: Date;
@Column(DataType.TEXT)
method: string;
@Column(DataType.TEXT)
payment_signature: string;
@Column(DataType.TEXT)
from_account: string;
@Column(DataType.TEXT)
to_account: string;
@Column(DataType.NUMBER)
remaining_amount: number;
@Column(DataType.TEXT)
status: string;
@Default(new Date())
@Column(DataType.DATEONLY)
validFrom: Date;
@Default(new Date("2070-12-31"))
@Column(DataType.DATEONLY)
validTill: Date;
@Column(DataType.DATEONLY)
createdAt: Date;
@Column(DataType.DATEONLY)
updatedAt: Date;
@Column(DataType.TEXT)
createdBy: string;
@Column(DataType.TEXT)
modifiedBy: string;
@Column(DataType.DATEONLY)
deletedAt: Date;
@Column(DataType.NUMBER)
version: number;
}

View File

@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { PaymentController } from './payment.controller';
import { PaymentService } from './payment.service';
@Module({
controllers: [PaymentController],
providers: [PaymentService],
imports: []
})
export class PaymentModule { }

View File

@ -0,0 +1,45 @@
import { Injectable } from '@nestjs/common';
import Payment from './payment.entity';
// import { Payment } from './payment.entity';
// import PaymentAdditionalDetail from './payment-additional-details/payment-additional-details.entity';
@Injectable()
export class PaymentService {
constructor() { }
async findAll(): Promise<{rows: Payment[], count: number}> {
return Payment.findAndCountAll();
}
findByPk(id: number): Promise<Payment> {
return Payment.findByPk(id,)
}
findOne(payment: Payment): Promise<Payment> {
return Payment.findOne({where: payment as any})
}
filter(payment: Payment) : Promise<Payment[]> {
return Payment.findAll({where: payment as any})
}
async remove(id: number): Promise<number> {
return Payment.destroy({where: {id: id}});
}
async upsert(paymentDetail: Payment, insertIfNotFound: boolean): Promise<Payment | [affectedCount: number]> {
if(paymentDetail.id) {
const existingPayment = await this.findByPk(paymentDetail.id);
if(existingPayment) {
return Payment.update(paymentDetail, {where: {id: paymentDetail.id}});
}
}
if(insertIfNotFound) {
return Payment.create(paymentDetail as any)
}
}
// async login(payment: Payment): Promise<Payment> {
// return Payment.findOne({where: payment as any, include})
// }
}

View File

@ -0,0 +1,103 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Response } from 'express';
import { GenericResponse } from 'src/common/GenericResponse.model';
import { PlanUsageService } from './plan-usage.service';
import PlanUsage from './plan-usage.entity';
@Controller('plans-usage')
export class PlanUsageController {
constructor(private itemsService: PlanUsageService) {}
@Get("/all")
async getAll(@Res() res: Response) {
const response = await this.itemsService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Get(':id')
async findById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.itemsService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/filter')
async filter(@Body() item: PlanUsage, @Res() res: Response) {
if(!item) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.itemsService.filter(item) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post()
async insert(@Body() item: PlanUsage, @Res() res: Response) {
if(!item) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
delete item.id;
const response = await this.itemsService.upsert(item, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async update(@Body() item: PlanUsage, @Res() res: Response) {
if(!item || !item.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.itemsService.upsert(item, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async deleteById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.itemsService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

View File

@ -0,0 +1,46 @@
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
@Table({ tableName: 'plan_usage' })
export default class PlanUsage extends Model {
@Column(DataType.BIGINT)
user_id: number;
@Column(DataType.BIGINT)
plan_id: number;
@Column(DataType.TEXT)
usage_type: string;
@Column(DataType.DATEONLY)
usage_quantity: Date;
@Column(DataType.TEXT)
status: string;
@Default(new Date())
@Column(DataType.DATEONLY)
validFrom: Date;
@Default(new Date("2070-12-31"))
@Column(DataType.DATEONLY)
validTill: Date;
@Column(DataType.DATEONLY)
createdAt: Date;
@Column(DataType.DATEONLY)
updatedAt: Date;
@Column(DataType.TEXT)
createdBy: string;
@Column(DataType.TEXT)
modifiedBy: string;
@Column(DataType.DATEONLY)
deletedAt: Date;
@Column(DataType.NUMBER)
version: number;
}

View File

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { PlanUsageService } from './plan-usage.service';
import { PlanUsageController } from './plan-usage.controller';
@Module({
providers: [PlanUsageService],
controllers: [PlanUsageController],
})
export class PlanUsageModule {}

View File

@ -0,0 +1,37 @@
import { Injectable } from '@nestjs/common';
import PlanUsage from './plan-usage.entity';
@Injectable()
export class PlanUsageService {
async findAll(): Promise<{rows: PlanUsage[], count: number}> {
return PlanUsage.findAndCountAll();
}
findByPk(id: number): Promise<PlanUsage> {
return PlanUsage.findByPk(id)
}
findOne(planUsage: PlanUsage): Promise<PlanUsage> {
return PlanUsage.findOne({where: planUsage as any})
}
async remove(id: number): Promise<number> {
return PlanUsage.destroy({where: {id: id}});
}
filter(item: PlanUsage) : Promise<PlanUsage[]> {
return PlanUsage.findAll({where: item as any})
}
async upsert(planUsage: PlanUsage, insertIfNotFound: boolean): Promise<PlanUsage | [affectedCount: number]> {
if(planUsage.id) {
const existingUser = await this.findByPk(planUsage.id);
if(existingUser) {
return PlanUsage.update(planUsage, {where: {id: planUsage.id}});
}
}
if(insertIfNotFound) {
return PlanUsage.create(planUsage as any)
}
}
}

View File

@ -0,0 +1,108 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Response } from 'express';
import { GenericResponse } from 'src/common/GenericResponse.model';
import Plan from './plans.entity';
import { PlansService } from './plans.service';
@Controller('plans')
export class PlansController {
constructor(private planService?: PlansService) {
if(!planService) {
planService = new PlansService();
}
}
@Get("/all")
async plangetAll(@Res() res: Response) {
const response = await this.planService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Get(':id')
async planFindById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_IN_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.planService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/filter')
async planFilter(@Body() user: Plan, @Res() res: Response) {
if(!user) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.planService.filter(user) || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post()
async planInsert(@Body() user: Plan, @Res() res: Response) {
if(!user) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
delete user.id;
const response = await this.planService.upsert(user, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async planUpdate(@Body() user: Plan, @Res() res: Response) {
if(!user || !user.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.planService.upsert(user, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async planDeleteById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.planService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

46
src/plans/plans.entity.ts Normal file
View File

@ -0,0 +1,46 @@
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
@Table({ tableName: 'plans_ref' })
export default class Plan extends Model {
@Column(DataType.TEXT)
name: string;
@Column(DataType.NUMBER)
price: number;
@Column(DataType.DATEONLY)
duration: Date;
@Column(DataType.TEXT)
description: string;
@Column(DataType.TEXT)
status: string;
@Default(new Date())
@Column(DataType.DATEONLY)
validFrom: Date;
@Default(new Date("2070-12-31"))
@Column(DataType.DATEONLY)
validTill: Date;
@Column(DataType.DATEONLY)
createdAt: Date;
@Column(DataType.DATEONLY)
updatedAt: Date;
@Column(DataType.TEXT)
createdBy: string;
@Column(DataType.TEXT)
modifiedBy: string;
@Column(DataType.DATEONLY)
deletedAt: Date;
@Column(DataType.NUMBER)
version: number;
}

View File

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { PlansController } from './plans.controller';
import { PlansService } from './plans.service';
@Module({
controllers:[PlansController],
providers:[PlansService]
})
export class PlansModule {}

View File

@ -0,0 +1,39 @@
import { Injectable } from '@nestjs/common';
import Plan from './plans.entity';
@Injectable()
export class PlansService {
async findAll(): Promise<{rows: Plan[], count: number}> {
return Plan.findAndCountAll();
}
findByPk(id: number): Promise<Plan> {
return Plan.findByPk(id)
}
filter(plan: Plan) : Promise<Plan[]> {
return Plan.findAll({where: plan as any})
}
findOne(user: Plan): Promise<Plan> {
return Plan.findOne({where: user as any})
}
async remove(id: number): Promise<number> {
return Plan.destroy({where: {id: id}});
}
async upsert(userDetail: Plan, insertIfNotFound: boolean): Promise<Plan | [affectedCount: number]> {
if(userDetail.id) {
const existingUser = await this.findByPk(userDetail.id);
if(existingUser) {
return Plan.update(userDetail, {where: {id: userDetail.id}});
}
}
if(insertIfNotFound) {
return Plan.create(userDetail as any)
}
}
}

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CompanyController } from './company.controller';
describe('CompanyController', () => {
let controller: CompanyController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [CompanyController],
}).compile();
controller = module.get<CompanyController>(CompanyController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

View File

@ -0,0 +1,103 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { QuoteService } from './quotes.service';
import { Response } from 'express';
import { GenericResponse } from 'src/common/GenericResponse.model';
import Quote from './quotes.entity';
@Controller('quotes')
export class QuoteController {
constructor(private quotesService: QuoteService) {}
@Get("/all")
async getAllQuotes(@Res() res: Response) {
const response = await this.quotesService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Get(':id')
async findById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.quotesService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/filter')
async filter(@Body() quotes: Quote, @Res() res: Response) {
if(!quotes) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.quotesService.filter(quotes) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post()
async insert(@Body() quotes: Quote, @Res() res: Response) {
if(!quotes) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
delete quotes.id;
const response = await this.quotesService.upsert(quotes, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async update(@Body() quotes: Quote, @Res() res: Response) {
if(!Quote || !quotes.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.quotesService.upsert(quotes, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async deleteById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.quotesService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

View File

@ -0,0 +1,52 @@
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
@Table({ tableName: 'quotes' })
export default class Quote extends Model {
@Column(DataType.BIGINT)
user_id: number;
@Column(DataType.TEXT)
user_email: string;
@Column(DataType.BIGINT)
institute_id: number;
@Column(DataType.TEXT)
quote_type: string;
@Column(DataType.NUMBER)
quote_est: number;
@Column(DataType.NUMBER)
cust_estimate: number;
@Column(DataType.TEXT)
status: string;
@Default(new Date())
@Column(DataType.DATEONLY)
validFrom: Date;
@Default(new Date("2070-12-31"))
@Column(DataType.DATEONLY)
validTill: Date;
@Column(DataType.DATEONLY)
createdAt: Date;
@Column(DataType.DATEONLY)
updatedAt: Date;
@Column(DataType.TEXT)
createdBy: string;
@Column(DataType.TEXT)
modifiedBy: string;
@Column(DataType.DATEONLY)
deletedAt: Date;
@Column(DataType.NUMBER)
version: number;
}

View File

@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { QuoteController } from './quotes.controller';
import { QuoteService } from './quotes.service';
@Module({
imports: [],
providers: [QuoteService, ],
controllers: [QuoteController,]
})
export class QuoteModule {}

View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CompanyService } from './company.service';
describe('CompanyService', () => {
let service: CompanyService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [CompanyService],
}).compile();
service = module.get<CompanyService>(CompanyService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

View File

@ -0,0 +1,38 @@
import { Injectable } from '@nestjs/common';
import Quote from './quotes.entity';
@Injectable()
export class QuoteService {
async findAll(): Promise<{rows: Quote[], count: number}> {
return Quote.findAndCountAll();
}
findByPk(id: number): Promise<Quote> {
return Quote.findByPk(id, )
}
filter(quotes: Quote) : Promise<Quote[]> {
return Quote.findAll({where: quotes as any})
}
findOne(quotes: Quote): Promise<Quote> {
return Quote.findOne({where: quotes as any})
}
async remove(id: number): Promise<number> {
return Quote.destroy({where: {id: id}});
}
async upsert(quotes: Quote, insertIfNotFound: boolean): Promise<Quote | [affectedCount: number]> {
if(quotes.id) {
const existingUser = await this.findByPk(quotes.id);
if(existingUser) {
return Quote.update(quotes, {where: {id: quotes.id}});
}
}
if(insertIfNotFound) {
return Quote.create(quotes as any)
}
}
}

View File

@ -0,0 +1,103 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Response } from 'express';
import { GenericResponse } from 'src/common/GenericResponse.model';
import { RefundService } from './refund.service';
import Refund from './refund.entity';
@Controller('refunds')
export class RefundController {
constructor(private refundsService: RefundService) {}
@Get("/all")
async getAll(@Res() res: Response) {
const response = await this.refundsService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Get(':id')
async findById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.refundsService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/filter')
async filter(@Body() refund: Refund, @Res() res: Response) {
if(!refund) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.refundsService.filter(refund) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post()
async insert(@Body() refund: Refund, @Res() res: Response) {
if(!refund) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
delete refund.id;
const response = await this.refundsService.upsert(refund, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Put()
async update(@Body() refund: Refund, @Res() res: Response) {
if(!refund || !refund.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.refundsService.upsert(refund, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Delete(':id')
async deleteById(@Param('id') id: number, @Res() res: Response) {
if(!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
}
const response = await this.refundsService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
}

View File

@ -0,0 +1,49 @@
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
@Table({ tableName: 'refund' })
export default class Refund extends Model {
@Column(DataType.BIGINT)
payment_id: number;
@Column(DataType.NUMBER)
amount: number;
@Column(DataType.DATEONLY)
refund_date: Date;
@Column(DataType.TEXT)
reason: string;
@Column(DataType.TEXT)
to_account: string;
@Column(DataType.TEXT)
status: string;
@Default(new Date())
@Column(DataType.DATEONLY)
validFrom: Date;
@Default(new Date("2070-12-31"))
@Column(DataType.DATEONLY)
validTill: Date;
@Column(DataType.DATEONLY)
createdAt: Date;
@Column(DataType.DATEONLY)
updatedAt: Date;
@Column(DataType.TEXT)
createdBy: string;
@Column(DataType.TEXT)
modifiedBy: string;
@Column(DataType.DATEONLY)
deletedAt: Date;
@Column(DataType.NUMBER)
version: number;
}

View File

@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { RefundService } from './refund.service';
import { RefundController } from './refund.controller';
@Module({
imports: [],
providers: [RefundService, ],
controllers: [RefundController, ]
})
export class RefundsModule {}

View File

@ -0,0 +1,38 @@
import { Injectable } from '@nestjs/common';
import Refund from './refund.entity';
@Injectable()
export class RefundService {
async findAll(): Promise<{rows: Refund[], count: number}> {
return Refund.findAndCountAll();
}
findByPk(id: number): Promise<Refund> {
return Refund.findByPk(id)
}
filter(refund: Refund) : Promise<Refund[]> {
return Refund.findAll({where: refund as any})
}
findOne(refund: Refund): Promise<Refund> {
return Refund.findOne({where: refund as any})
}
async remove(id: number): Promise<number> {
return Refund.destroy({where: {id: id}});
}
async upsert(refund: Refund, insertIfNotFound: boolean): Promise<Refund | [affectedCount: number]> {
if(refund.id) {
const existingUser = await this.findByPk(refund.id);
if(existingUser) {
return Refund.update(refund, {where: {id: refund.id}});
}
}
if(insertIfNotFound) {
return Refund.create(refund as any)
}
}
}

Some files were not shown because too many files have changed in this diff Show More