Add Terms and Conditions Module

This commit is contained in:
faris Aljohari
2025-01-15 23:17:25 -06:00
parent 7956de7f56
commit ef593086bf
9 changed files with 181 additions and 0 deletions

View File

@ -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: [
{

View File

@ -0,0 +1 @@
export * from './terms-conditions.controller';

View File

@ -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,
};
}
}

View File

@ -0,0 +1 @@
export * from './terms-conditions.service';

View File

@ -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<string> {
// 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;
}
}

View File

@ -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 {}