From ef593086bfad3aec1b6e0126b4b1107ec3b52d87 Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Wed, 15 Jan 2025 23:17:25 -0600 Subject: [PATCH] Add Terms and Conditions Module --- libs/common/src/constants/controller-route.ts | 9 ++++ .../src/constants/terms-and-conditions.html | 44 ++++++++++++++++ libs/common/src/constants/terms-conditions.ts | 29 +++++++++++ src/app.module.ts | 2 + src/terms-conditions/controllers/index.ts | 1 + .../terms-conditions.controller.ts | 32 ++++++++++++ src/terms-conditions/services/index.ts | 1 + .../services/terms-conditions.service.ts | 51 +++++++++++++++++++ .../terms-conditions.module.ts | 12 +++++ 9 files changed, 181 insertions(+) create mode 100644 libs/common/src/constants/terms-and-conditions.html create mode 100644 libs/common/src/constants/terms-conditions.ts create mode 100644 src/terms-conditions/controllers/index.ts create mode 100644 src/terms-conditions/controllers/terms-conditions.controller.ts create mode 100644 src/terms-conditions/services/index.ts create mode 100644 src/terms-conditions/services/terms-conditions.service.ts create mode 100644 src/terms-conditions/terms-conditions.module.ts diff --git a/libs/common/src/constants/controller-route.ts b/libs/common/src/constants/controller-route.ts index 4012c1a..f257e2a 100644 --- a/libs/common/src/constants/controller-route.ts +++ b/libs/common/src/constants/controller-route.ts @@ -404,6 +404,15 @@ export class ControllerRoute { 'This endpoint adds a new user role to the system based on the provided role data.'; }; }; + static TERMS_AND_CONDITIONS = class { + public static readonly ROUTE = 'terms'; + + static ACTIONS = class { + public static readonly FETCH_TERMS_SUMMARY = 'Fetch Terms and Conditions'; + public static readonly FETCH_TERMS_DESCRIPTION = + 'This endpoint retrieves the terms and conditions for the application.'; + }; + }; static GROUP = class { public static readonly ROUTE = 'group'; diff --git a/libs/common/src/constants/terms-and-conditions.html b/libs/common/src/constants/terms-and-conditions.html new file mode 100644 index 0000000..80bac71 --- /dev/null +++ b/libs/common/src/constants/terms-and-conditions.html @@ -0,0 +1,44 @@ +
+

User Agreement

+

Terms and Conditions

+

Last updated: {{lastUpdated}}

+

+ Please read these Terms and Conditions ("Terms", "Terms and Conditions") + carefully before using the + {{websiteUrl}} website and the {{mobileApp}} + mobile application (the "Service") operated by {{companyName}}. +

+

+ Your access to and use of the Service is conditioned on your acceptance of + and compliance with these Terms. These Terms apply to all visitors, users, + and others who access or use the Service. +

+

Content

+

+ Our Service allows you to post, link, store, share and otherwise make + available certain information, text, graphics, videos, or other material + ("Content"). You are responsible for the Content you post. +

+

Links To Other Websites

+

+ Our Service may contain links to third-party websites or services that are + not owned or controlled by {{companyName}}. +

+

+ {{companyName}} has no control over, and assumes no responsibility for, the + content, privacy policies, or practices of any third-party websites or + services. +

+

Changes

+

+ We reserve the right, at our sole discretion, to modify or replace these + Terms at any time. If a revision is material, we will try to provide at + least 30 days' notice prior to any new terms taking effect. What constitutes + a material change will be determined at our sole discretion. +

+

Contact Us

+

+ If you have any questions about these Terms, please + contact us. +

+
diff --git a/libs/common/src/constants/terms-conditions.ts b/libs/common/src/constants/terms-conditions.ts new file mode 100644 index 0000000..6b52f99 --- /dev/null +++ b/libs/common/src/constants/terms-conditions.ts @@ -0,0 +1,29 @@ +export const TERMS_AND_CONDITIONS = { + title: 'User Agreement', + content: ` + +
+

User Agreement

+

Terms and Conditions

+

Last updated: 25/01/2025

+

Please read these Terms and Conditions ("Terms", "Terms and Conditions") carefully before using the + http://www.mywebsite.com website and the My Mobile App + (change this) mobile application (the "Service") operated by My Company (change this) ("us", "we", or "our"). +

+

Your access to and use of the Service is conditioned on your acceptance of and compliance with these Terms. + These Terms apply to all visitors, users and others who access or use the Service. +

+

By accessing or using the Service you agree to be bound by these Terms. If you disagree with any part of the terms then you may not access the Service.

+

Content

+

Our Service allows you to post, link, store, share and otherwise make available certain information, text, graphics, videos, or other material ("Content"). You are responsible for the Content you post.

+

Links To Other Websites

+

Our Service may contain links to third-party websites or services that are not owned or controlled by My Company (change this).

+

My Company (change this) has no control over, and assumes no responsibility for, the content, privacy policies, or practices of any third-party websites or services. You further acknowledge and agree that My Company (change this) shall not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods, or services available on or through any such websites or services.

+

Changes

+

We reserve the right, at our sole discretion, to modify or replace these Terms at any time. If a revision is material, we will try to provide at least 30 (change this) days' notice prior to any new terms taking effect. What constitutes a material change will be determined at our sole discretion.

+

Contact Us

+

If you have any questions about these Terms, please contact us.

+
+ +`, +}; diff --git a/src/app.module.ts b/src/app.module.ts index fe656ff..d61ac4c 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -26,6 +26,7 @@ import { SpaceModelModule } from './space-model'; import { InviteUserModule } from './invite-user/invite-user.module'; import { PermissionModule } from './permission/permission.module'; import { RoleModule } from './role/role.module'; +import { TermsConditionsModule } from './terms-conditions/terms-conditions.module'; @Module({ imports: [ ConfigModule.forRoot({ @@ -55,6 +56,7 @@ import { RoleModule } from './role/role.module'; ProjectModule, PermissionModule, RoleModule, + TermsConditionsModule, ], providers: [ { diff --git a/src/terms-conditions/controllers/index.ts b/src/terms-conditions/controllers/index.ts new file mode 100644 index 0000000..6d48cce --- /dev/null +++ b/src/terms-conditions/controllers/index.ts @@ -0,0 +1 @@ +export * from './terms-conditions.controller'; diff --git a/src/terms-conditions/controllers/terms-conditions.controller.ts b/src/terms-conditions/controllers/terms-conditions.controller.ts new file mode 100644 index 0000000..52849ae --- /dev/null +++ b/src/terms-conditions/controllers/terms-conditions.controller.ts @@ -0,0 +1,32 @@ +import { Controller, Get, HttpStatus } from '@nestjs/common'; +import { ApiOperation, ApiTags } from '@nestjs/swagger'; +import { EnableDisableStatusEnum } from '@app/common/constants/days.enum'; +import { ControllerRoute } from '@app/common/constants/controller-route'; // Assuming this is where the routes are defined +import { TermsAndConditionsService } from '../services'; + +@ApiTags('Terms & Conditions Module') +@Controller({ + version: EnableDisableStatusEnum.ENABLED, + path: ControllerRoute.TERMS_AND_CONDITIONS.ROUTE, // use the static route constant +}) +export class TermsConditionsController { + constructor( + private readonly termsAndConditionsService: TermsAndConditionsService, + ) {} + + @Get() + @ApiOperation({ + summary: ControllerRoute.TERMS_AND_CONDITIONS.ACTIONS.FETCH_TERMS_SUMMARY, + description: + ControllerRoute.TERMS_AND_CONDITIONS.ACTIONS.FETCH_TERMS_DESCRIPTION, + }) + async fetchTermsAndConditions() { + const htmlContent = + await this.termsAndConditionsService.fetchTermsAndConditions(); + return { + statusCode: HttpStatus.OK, + message: 'Terms and conditions fetched successfully', + data: htmlContent, + }; + } +} diff --git a/src/terms-conditions/services/index.ts b/src/terms-conditions/services/index.ts new file mode 100644 index 0000000..09d3783 --- /dev/null +++ b/src/terms-conditions/services/index.ts @@ -0,0 +1 @@ +export * from './terms-conditions.service'; diff --git a/src/terms-conditions/services/terms-conditions.service.ts b/src/terms-conditions/services/terms-conditions.service.ts new file mode 100644 index 0000000..14d98d6 --- /dev/null +++ b/src/terms-conditions/services/terms-conditions.service.ts @@ -0,0 +1,51 @@ +import { Injectable } from '@nestjs/common'; +import * as fs from 'fs'; +import * as path from 'path'; + +@Injectable() +export class TermsAndConditionsService { + async fetchTermsAndConditions(): Promise { + // Use process.cwd() to get the current working directory (project root) + const projectRoot = process.cwd(); + + // Dynamically build the path to the terms-and-conditions.html file from the root + const filePath = path.join( + projectRoot, + 'libs', + 'common', + 'src', + 'constants', + 'terms-and-conditions.html', + ); + + // Ensure the file exists + if (!fs.existsSync(filePath)) { + throw new Error(`File not found: ${filePath}`); + } + + // Read the HTML content from the file + let htmlContent = fs.readFileSync(filePath, 'utf-8'); + + // Optionally, remove newlines or excess white spaces using a regular expression + htmlContent = htmlContent.replace(/(\r\n|\n|\r)/gm, ''); // Removes newlines + + // Define dynamic values + const dynamicValues = { + lastUpdated: '25/01/2025', + websiteUrl: 'http://www.mywebsite.com', + mobileApp: 'My Mobile App', + companyName: 'My Company', + contactEmail: 'contact@mycompany.com', + }; + + // Replace placeholders in the HTML with dynamic values + htmlContent = htmlContent + .replace(/{{lastUpdated}}/g, dynamicValues.lastUpdated) + .replace(/{{websiteUrl}}/g, dynamicValues.websiteUrl) + .replace(/{{mobileApp}}/g, dynamicValues.mobileApp) + .replace(/{{companyName}}/g, dynamicValues.companyName) + .replace(/{{contactEmail}}/g, dynamicValues.contactEmail); + + return htmlContent; + } +} diff --git a/src/terms-conditions/terms-conditions.module.ts b/src/terms-conditions/terms-conditions.module.ts new file mode 100644 index 0000000..6dbf974 --- /dev/null +++ b/src/terms-conditions/terms-conditions.module.ts @@ -0,0 +1,12 @@ +import { DeviceRepositoryModule } from '@app/common/modules/device'; +import { Module } from '@nestjs/common'; +import { ConfigModule } from '@nestjs/config'; +import { TermsConditionsController } from './controllers'; +import { TermsAndConditionsService } from './services'; + +@Module({ + imports: [ConfigModule, DeviceRepositoryModule], + controllers: [TermsConditionsController], + providers: [TermsAndConditionsService], +}) +export class TermsConditionsModule {}