45 lines
1.8 KiB
TypeScript
45 lines
1.8 KiB
TypeScript
import { Body, Controller, Middlewares, Post, Response, Route, SuccessResponse } from "tsoa";
|
|
|
|
import { ApiValidationError } from "../../../Models/Server.Error.model";
|
|
import { ApiVoidResult } from "../../../Models/Api.VoidResult.type";
|
|
import { sysAdminAuthMiddleware } from "../../../middleware/sysadminAuth";
|
|
import { IPlan, SysAdminUpdatePlanParams } from "../../../Models/Plans/Plans.interface";
|
|
import { SysAdminPlansService } from "./SysAdminPlans.Service";
|
|
|
|
@Route("sysadmin/plans")
|
|
@Middlewares(sysAdminAuthMiddleware)
|
|
export class SysAdminPlansController extends Controller {
|
|
@Response<ApiValidationError>(500, "Ha ocurrido un error")
|
|
@SuccessResponse(200, "Done")
|
|
@Post("list")
|
|
public async listPlans(): Promise<IPlan[] | ApiValidationError> {
|
|
try {
|
|
const plans = await new SysAdminPlansService().listPlans();
|
|
this.setStatus(200);
|
|
return plans;
|
|
} catch (e) {
|
|
const errorOccurred: Error = e as Error;
|
|
this.setStatus(500);
|
|
return new ApiValidationError(500, errorOccurred.message);
|
|
}
|
|
}
|
|
|
|
@Response<ApiValidationError>(500, "Ha ocurrido un error")
|
|
@SuccessResponse(200, "El plan fue modificado con éxito")
|
|
@Post("update")
|
|
public async updatePlan(@Body() requestBody: SysAdminUpdatePlanParams): Promise<ApiVoidResult | ApiValidationError> {
|
|
try {
|
|
await new SysAdminPlansService().updatePlan(requestBody);
|
|
this.setStatus(200);
|
|
return {
|
|
success: true,
|
|
message: "Done",
|
|
};
|
|
} catch (e) {
|
|
const errorOccurred: Error = e as Error;
|
|
this.setStatus(500);
|
|
return new ApiValidationError(500, errorOccurred.message);
|
|
}
|
|
}
|
|
}
|