import * as express from "express"; import App from "./app"; import { FileOptions } from "./file.response"; import RenderResponse from "./render.response"; import RedirectResponse from "./redirect.response"; import SkipResponse from "./skip.response"; import UnauthorizedResponse from "./unauthorized.response"; import FileResponse from "./file.response"; import Request from "./request"; import { LynxControllerMetadata } from "./decorators"; import Media from "./entities/media.entity"; import StatusError from "./status-error"; import Logger from "./logger"; export declare enum FlashType { primary = 0, secondary = 1, success = 2, danger = 3, warning = 4, info = 5, light = 6, dark = 7 } export interface FlashMessage { type: FlashType; message: string; } /** * This class defines the basic class for any controllers. It implements a lot * of utility methods in order to correctly generate any response. */ export declare class BaseController { app: App; private _metadata; logger: Logger; readonly metadata: LynxControllerMetadata; constructor(app: App); /** * This method is called only when the constructed has been completed. * Since this method is async, it can be used to perform some initialization * that needed the use of the await keyword. */ postConstructor(): Promise; /** * Add a value to the current request context. * Any variable added with this method will available in the template context * thought the @method render method. * @param req the current Request * @param key the key of the value to add * @param value the value to add */ addToContext(req: Request, key: string, value: any): void; /** * Utility method to generate an error with a status code. * This method should be used instead of the usual throw new Error(msg). * In this way, a proper HTTP status code can be used (for example, 404 or 500), * instead of the default 400. * @param status the http status code to return * @param message the error message * @return a new @type StatusError object */ error(status: number, message: string): StatusError; /** * This method generate an url to a route starting from the route name and * optionally its parameters. * If a parameter not is used to generate the route url, it will be appended * as a query parameter. * @param name the name of the route * @param parameters a plain object containing the paramters for the route. */ route(name: string, parameters?: any): string; /** * Generate a web page starting from a template and using a generated context. * @param view the name of the view * @param req the request object * @param context a plain object containing any necessary data needed by the view */ render(view: string, req: Request, context?: any): RenderResponse; /** * Redirect the current route to another * @param routeName the new of the target route * @param routeParams a plain object containing the paramters for the route. */ redirect(routeName: string, routeParams?: any): RedirectResponse; /** * Add a flash message in the current request. * @param msg the FlashMessage to be included * @param req the request */ addFlashMessage(msg: FlashMessage, req: Request): void; /** * Add a success flash message in the current request. * @param msg the string (can be localized) of the message * @param req the request */ addSuccessMessagge(msg: string, req: Request): void; /** * Add an error flash message in the current request. * @param msg the string (can be localized) of the message * @param req the request */ addErrorMessage(msg: string, req: Request): void; /** * Generate a response suitable to file download. This method can also be * used to generate images of specific dimensions. * @param path the string path of the file, or a Media object to be downloaded * @param options options to correctly generate the output file */ download(path: string | Media, options?: FileOptions): FileResponse; /** * Generate an unauthorized response. */ unauthorized(): UnauthorizedResponse; /** * Generate a skip resopnse. In this particuar case, the original Express `next()` * will be executed, causing the controller chain to continue its execution. */ next(): SkipResponse; /** * Utility method to send an email from a controller. This method is async, * so use the await keyword (or eventually a promise) to correctly read the * return value. * This method uses the template engine to compile the email. * @param req the current request * @param dest the email destination (can also be an array of addresses) * @param subjectTemplateString the subject of the email, that can also be a string template * @param textTemplate the text version of the email, referencing a path in the view folders * @param htmlTemplate the html version of the email, referencing a path in the view folders * @param context a plain object containing any necessary data needed by the view */ sendMail(req: express.Request, dest: string | string[], subjectTemplateString: string, textTemplate: string, htmlTemplate: string, context: any): Promise; /** * Utility method to obtain a translated string. * @param str the string key to be transalted * @param req the original request */ tr(str: string, req: Request): string; }