ticket-booking-be/src/app-config/app-config.controller.ts
2025-02-25 12:53:59 +05:30

74 lines
2.5 KiB
TypeScript

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);
}
}
/*
location /assessment {
rewrite ^/assessment/(.*)$ /$1 break;
proxy_pass http://localhost:3001;
proxy_redirect off;
proxy_set_header Host $host;
}
location /content {
rewrite ^/content/(.*)$ /$1 break;
proxy_pass http://localhost:3002;
proxy_redirect off;
proxy_set_header Host $host;
}
location /dataservice {
rewrite ^/dataservice/(.*)$ /$1 break;
proxy_pass http://localhost:3003;
proxy_redirect off;
proxy_set_header Host $host;
}
location /payments {
rewrite ^/payments/(.*)$ /$1 break;
proxy_pass http://localhost:3004;
proxy_redirect off;
proxy_set_header Host $host;
}
location /users {
rewrite ^/users/(.*)$ /$1 break;
proxy_pass http://localhost:3005;
proxy_redirect off;
proxy_set_header Host $host;
}
*/