## Description 1. Move everything related to client from app folder to client folder (`.yarn`, `yarn.lock`, package.json, .gitignore) 2. Move `ast` and `rst` to client packages 3. Fix running scripts in packages 4. Add running unit tests in packages in CI TODO: It is necessary to consider enabling the `nmHoistingLimits: workspaces` option, since now all packages are hoisted to the root, there may be issues with dependencies in workspaces. Also, there is a possibility of implicit use of packages. https://yarnpkg.com/configuration/yarnrc#nmHoistingLimits #### PR fixes following issue(s) Fixes #23333 #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing #### How Has This Been Tested? - [x] Manual - [x] Jest - [x] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag Co-authored-by: Valera Melnikov <melnikov.vv@greendatasoft.ru>
76 lines
1.7 KiB
TypeScript
76 lines
1.7 KiB
TypeScript
import type { Response } from "express";
|
|
import type { ValidationError } from "express-validator";
|
|
import { StatusCodes } from "http-status-codes";
|
|
import type { 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,
|
|
result?: unknown,
|
|
message?: string,
|
|
code: number = StatusCodes.OK,
|
|
): Response<ResponseData> {
|
|
return response.status(code).json({
|
|
success: true,
|
|
message,
|
|
data: result,
|
|
});
|
|
}
|
|
|
|
sendEntityResponse(
|
|
response: Response,
|
|
result?: unknown,
|
|
success?: boolean,
|
|
code: number = StatusCodes.OK,
|
|
): Response<ResponseData> {
|
|
return response.status(code).json({
|
|
success,
|
|
data: result,
|
|
});
|
|
}
|
|
|
|
sendError(
|
|
response: Response,
|
|
error: string,
|
|
errorMessage,
|
|
code: number = StatusCodes.BAD_REQUEST,
|
|
): Response<ErrorBag> {
|
|
const 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);
|
|
}
|
|
}
|