PromucFlow_constructor/app/rts/src/controllers/BaseController.ts

64 lines
1.5 KiB
TypeScript
Raw Normal View History

import { Response } from "express";
import { ValidationError } from "express-validator";
import { StatusCodes } from "http-status-codes";
import { IdentifierInfo } from "@shared/ast";
type ErrorData = {
error: string | string[];
validationErrors?: ValidationError[];
};
type ErrorBag = {
success: boolean;
message: string;
data?: ErrorData;
};
type ResponseData = {
success: boolean;
message?: string;
data: IdentifierInfo;
};
export default class BaseController {
serverErrorMessaage = "Something went wrong";
sendResponse(
response: Response,
fix: Modified on page load actions calculation using AST (#17074) * Changes to on page load logic and consumption for update layout * Slight clean up, tests and stuff * - Added evaluationVersion logic based on application configuration - Added configuration for slim and fat container rts availability - Added backup logic of string comparison for slim containers - Added tests for both paths * Changes to on page load logic and consumption for update layout * Slight clean up, tests and stuff * Cleaned up comments all over * Why isn't there even a setting to disable auto re-formats * update rts logic to use updated shared AST logic * Make changes to naming conventions * Some temp stuff to check if update layout API changes will work out * Added health check endpoint in RTS * Added types for AST request * update: type for save page request object * update: return type for getEditorConfigs func - Added applicationId to the type. - Fetching from the redux store -> applications -> currentApplication -> id * update: url generation func for update page API - added applicationId as query param for the call * Fixed test failures * Fixed merge from release with on page load failure messages * Fixed tests failing after merge * Review comments, more tests, and fix for array index ref directly after .data path * Test fix * Addressed review comments * Updated comment * Fixed rts temporarily, added handling for data as function name, left with tests * fix: failing rts server * Tests for all types of actions and references * Changes to test * Modified type to set * Test fixes * Trying to make a test pass * Added app id in cypress test update dsl * Added app id in cypress test update dsl * Added app id in cypress test update dsl * Removed dep tree temp file * Resolving compile issues after merging from release * updated tests for applicationId * corrected a typo * fixed some more tests * updated test * Updated test * DSL load AppId fix * appId removal * AgHelper LocalStorageCache() * AgHelper LocalStorageCache() - commit 2 * AgHelper LocalStorageCache() - commit 3 * AgHelper LocalStorageCache() - commit 4 * AllWidgets_Reset_spec - Dsl fix * Json_spec fix * S3_2 spec fix * fixes * LocalStorageCache fixes * fixes * fixes * fix * OnLoadActions spec fix * Promises spec fix * S3_2 spec fix * 16702 spec update * OnLoadActions spec trial fix * RTS fix Co-authored-by: Nidhi Nair <cataclysm@Nidhis-MacBook-Pro.local> Co-authored-by: Ayangade Adeoluwa <adeoluayangade@yahoo.com> Co-authored-by: Ayush Pahwa <ayush@appsmith.com> Co-authored-by: Aman Agarwal <aman@appsmith.com> Co-authored-by: Apple <nandan@thinkify.io> Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
2022-10-11 05:32:44 +00:00
result?: unknown,
message?: string,
code: number = StatusCodes.OK
): Response<ResponseData> {
return response.status(code).json({
success: true,
message,
data: result,
});
}
sendError(
response: Response,
error: string,
errorMessage,
code: number = StatusCodes.BAD_REQUEST
): Response<ErrorBag> {
let errorBag: ErrorBag = { success: false, message: error };
if (errorMessage.constructor.name === "Result") {
const validationError = errorMessage.array();
errorBag.data = {
error: [validationError[0].msg],
validationErrors: validationError,
};
// errorBag.message = validationError[0].msg;
} else {
if (errorMessage.length > 1) {
errorBag.data = { error: errorMessage };
} else {
errorBag.data = { error };
}
}
return response.status(code).json(errorBag);
}
}