143 lines
5.2 KiB
TypeScript
143 lines
5.2 KiB
TypeScript
import { Body, Controller, Middlewares, Post, Response, Route, SuccessResponse } from "tsoa";
|
|
import { authenticateMiddleware } from "../../middleware/authentication";
|
|
import { ApiValidationError } from "../../Models/Server.Error.model";
|
|
import {
|
|
ArcaCredentialView,
|
|
ArcaWsfeDiagnosticsParams,
|
|
ArcaWsfeDiagnosticsResult,
|
|
ArcaWsfeLastVoucherParams,
|
|
ArcaWsfeLastVoucherResult,
|
|
ArcaWsaaLoginTestResult,
|
|
FindArcaCredentialsParams,
|
|
GenerateArcaCredentialCsrParams,
|
|
TestArcaWsaaLoginParams,
|
|
UploadArcaCredentialCertificateParams,
|
|
} from "../../Models/ArcaCredentials/ArcaCredentials.Interface";
|
|
import { ArcaCredentialsService } from "./ArcaCredentials.Service";
|
|
|
|
@Route("arca-credentials/generate-csr")
|
|
@Middlewares(authenticateMiddleware)
|
|
export class ArcaCredentialsGenerateCsrController extends Controller {
|
|
@SuccessResponse(200, "Done")
|
|
@Response<ApiValidationError>(500, "Ha ocurrido un error")
|
|
@Post()
|
|
public async generateCsr(
|
|
@Body() requestBody: GenerateArcaCredentialCsrParams
|
|
): Promise<ArcaCredentialView | ApiValidationError> {
|
|
try {
|
|
const credential = await new ArcaCredentialsService().generateCsr(requestBody);
|
|
this.setStatus(200);
|
|
return credential;
|
|
} catch (e) {
|
|
const errorOccurred: Error = e as Error;
|
|
this.setStatus(500);
|
|
return new ApiValidationError(500, errorOccurred.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Route("arca-credentials/upload-certificate")
|
|
@Middlewares(authenticateMiddleware)
|
|
export class ArcaCredentialsUploadCertificateController extends Controller {
|
|
@SuccessResponse(200, "Done")
|
|
@Response<ApiValidationError>(500, "Ha ocurrido un error")
|
|
@Post()
|
|
public async uploadCertificate(
|
|
@Body() requestBody: UploadArcaCredentialCertificateParams
|
|
): Promise<ArcaCredentialView | ApiValidationError> {
|
|
try {
|
|
const credential = await new ArcaCredentialsService().uploadCertificate(requestBody);
|
|
this.setStatus(200);
|
|
return credential;
|
|
} catch (e) {
|
|
const errorOccurred: Error = e as Error;
|
|
this.setStatus(500);
|
|
return new ApiValidationError(500, errorOccurred.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Route("arca-credentials/test-wsaa-login")
|
|
@Middlewares(authenticateMiddleware)
|
|
export class ArcaCredentialsTestWsaaLoginController extends Controller {
|
|
@SuccessResponse(200, "Done")
|
|
@Response<ApiValidationError>(500, "Ha ocurrido un error")
|
|
@Post()
|
|
public async testWsaaLogin(
|
|
@Body() requestBody: TestArcaWsaaLoginParams
|
|
): Promise<ArcaWsaaLoginTestResult | ApiValidationError> {
|
|
try {
|
|
const result = await new ArcaCredentialsService().testWsaaLogin(requestBody);
|
|
this.setStatus(200);
|
|
return result;
|
|
} catch (e) {
|
|
const errorOccurred: Error = e as Error;
|
|
this.setStatus(500);
|
|
return new ApiValidationError(500, errorOccurred.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Route("arca-credentials/wsfe-last-voucher")
|
|
@Middlewares(authenticateMiddleware)
|
|
export class ArcaCredentialsWsfeLastVoucherController extends Controller {
|
|
@SuccessResponse(200, "Done")
|
|
@Response<ApiValidationError>(500, "Ha ocurrido un error")
|
|
@Post()
|
|
public async getWsfeLastVoucher(
|
|
@Body() requestBody: ArcaWsfeLastVoucherParams
|
|
): Promise<ArcaWsfeLastVoucherResult | ApiValidationError> {
|
|
try {
|
|
const result = await new ArcaCredentialsService().getWsfeLastVoucher(requestBody);
|
|
this.setStatus(200);
|
|
return result;
|
|
} catch (e) {
|
|
const errorOccurred: Error = e as Error;
|
|
this.setStatus(500);
|
|
return new ApiValidationError(500, errorOccurred.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Route("arca-credentials/wsfe-diagnostics")
|
|
@Middlewares(authenticateMiddleware)
|
|
export class ArcaCredentialsWsfeDiagnosticsController extends Controller {
|
|
@SuccessResponse(200, "Done")
|
|
@Response<ApiValidationError>(500, "Ha ocurrido un error")
|
|
@Post()
|
|
public async getWsfeDiagnostics(
|
|
@Body() requestBody: ArcaWsfeDiagnosticsParams
|
|
): Promise<ArcaWsfeDiagnosticsResult | ApiValidationError> {
|
|
try {
|
|
const result = await new ArcaCredentialsService().getWsfeDiagnostics(requestBody);
|
|
this.setStatus(200);
|
|
return result;
|
|
} catch (e) {
|
|
const errorOccurred: Error = e as Error;
|
|
this.setStatus(500);
|
|
return new ApiValidationError(500, errorOccurred.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Route("arca-credentials/find")
|
|
@Middlewares(authenticateMiddleware)
|
|
export class ArcaCredentialsFindController extends Controller {
|
|
@SuccessResponse(200, "Done")
|
|
@Response<ApiValidationError>(500, "Ha ocurrido un error")
|
|
@Post()
|
|
public async find(
|
|
@Body() requestBody: FindArcaCredentialsParams
|
|
): Promise<ArcaCredentialView[] | ApiValidationError> {
|
|
try {
|
|
const credentials = await new ArcaCredentialsService().find(requestBody);
|
|
this.setStatus(200);
|
|
return credentials;
|
|
} catch (e) {
|
|
const errorOccurred: Error = e as Error;
|
|
this.setStatus(500);
|
|
return new ApiValidationError(500, errorOccurred.message);
|
|
}
|
|
}
|
|
}
|