API-Explorer-II/server/controllers/RequestController.ts

85 lines
2.7 KiB
TypeScript
Raw Normal View History

2024-05-14 11:41:52 +00:00
/*
* Open Bank Project - API Explorer II
* Copyright (C) 2023-2024, TESOBE GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Email: contact@tesobe.com
* TESOBE GmbH
* Osloerstrasse 16/17
* Berlin 13359, Germany
*
* This product includes software developed at
* TESOBE (http://www.tesobe.com/)
*
*/
2023-06-05 15:32:25 +00:00
import { Controller, Session, Req, Res, Get, Delete, Post, Put } from 'routing-controllers'
2023-05-03 17:17:01 +00:00
import { Request, Response } from 'express'
import OBPClientService from '../services/OBPClientService'
2025-12-01 10:07:05 +00:00
import { Service, Container } from 'typedi'
2023-05-03 17:17:01 +00:00
@Service()
@Controller()
export class OBPController {
2025-12-01 10:07:05 +00:00
private obpClientService: OBPClientService
constructor() {
// Explicitly get OBPClientService from the container to avoid injection issues
this.obpClientService = Container.get(OBPClientService)
}
2023-05-03 17:17:01 +00:00
@Get('/get')
2023-06-05 15:32:25 +00:00
async get(@Session() session: any, @Req() request: Request, @Res() response: Response): Response {
2023-05-03 17:17:01 +00:00
const path = request.query.path
2023-06-05 15:32:25 +00:00
const oauthConfig = session['clientConfig']
return response.json(await this.obpClientService.get(path, oauthConfig))
2023-05-03 17:17:01 +00:00
}
@Post('/create')
2023-06-05 15:32:25 +00:00
async create(
@Session() session: any,
@Req() request: Request,
@Res() response: Response
): Response {
2023-05-03 17:17:01 +00:00
const path = request.query.path
const data = request.body
2023-06-05 15:32:25 +00:00
const oauthConfig = session['clientConfig']
return response.json(await this.obpClientService.create(path, data, oauthConfig))
2023-05-03 17:17:01 +00:00
}
@Put('/update')
2023-06-05 15:32:25 +00:00
async update(
@Session() session: any,
@Req() request: Request,
@Res() response: Response
): Response {
2023-05-03 17:17:01 +00:00
const path = request.query.path
const data = request.body
2023-06-05 15:32:25 +00:00
const oauthConfig = session['clientConfig']
return response.json(await this.obpClientService.update(path, data, oauthConfig))
2023-05-03 17:17:01 +00:00
}
@Delete('/delete')
2023-06-05 15:32:25 +00:00
async delete(
@Session() session: any,
@Req() request: Request,
@Res() response: Response
): Response {
2023-05-03 17:17:01 +00:00
const path = request.query.path
2023-06-05 15:32:25 +00:00
const oauthConfig = session['clientConfig']
return response.json(await this.obpClientService.discard(path, oauthConfig))
2023-05-03 17:17:01 +00:00
}
}