42 lines
1.7 KiB
TypeScript
42 lines
1.7 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);
|
|
}
|
|
}
|