fix lint.

This commit is contained in:
Simon Larsen 2022-05-25 19:24:43 +01:00
parent e20ab8f709
commit caf6788c59
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
29 changed files with 358 additions and 212 deletions

View File

@ -3,7 +3,6 @@ import App from 'CommonServer/Utils/StartServer';
export const APP_NAME: string = 'accounts';
const app = App(APP_NAME);
import path from 'path';
import {
ExpressRequest,

View File

@ -9,7 +9,6 @@ import App from 'CommonServer/Utils/StartServer';
export const APP_NAME: string = 'admin';
const app = App(APP_NAME);
app.use(ExpressStatic(path.join(__dirname, 'build')));
app.use(`/${APP_NAME}`, ExpressStatic(path.join(__dirname, 'build')));
app.use(

View File

@ -1,8 +1,5 @@
import { ExpressRequest, ExpressResponse } from 'CommonServer/utils/Express';
import App from 'CommonServer/utils/StartServer';
export const APP_NAME: string = 'application';
const app = App(APP_NAME);

View File

@ -25,7 +25,6 @@ import AccessControl from '../Types/Database/AccessControls/AccessControl';
import Dictionary from '../Types/Dictionary';
export default class BaseModel extends BaseEntity {
@TableColumn({ title: 'ID' })
@PrimaryGeneratedColumn('uuid')
public _id?: string = undefined;
@ -609,7 +608,10 @@ export default class BaseModel extends BaseEntity {
}
}
private static _fromJSON<T extends BaseModel>(json: JSONObject, type: { new(): T ;} ): T {
private static _fromJSON<T extends BaseModel>(
json: JSONObject,
type: { new (): T }
): T {
const baseModel: T = new type();
for (const key of Object.keys(json)) {
@ -619,15 +621,18 @@ export default class BaseModel extends BaseEntity {
return baseModel as T;
}
public static fromJSON<T extends BaseModel>(json: JSONObject | JSONArray, type: { new(): T ;} ): T | Array<T> {
public static fromJSON<T extends BaseModel>(
json: JSONObject | JSONArray,
type: { new (): T }
): T | Array<T> {
if (Array.isArray(json)) {
let arr: Array<T> = [];
const arr: Array<T> = [];
for (const item of json) {
arr.push(this._fromJSON<T>(item, type))
arr.push(this._fromJSON<T>(item, type));
}
return arr;
return arr;
}
return this._fromJSON<T>(json, type);
@ -636,7 +641,7 @@ export default class BaseModel extends BaseEntity {
private static keepColumns<T extends BaseModel>(
data: T,
columnsToKeep: Columns,
type: { new(): T ;}
type: { new (): T }
): T {
const baseModel: T = new type();
@ -658,24 +663,32 @@ export default class BaseModel extends BaseEntity {
}
public static asPublicCreateable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
}
if (!data.canPublicCreateRecord) {
// throw new BadRequestException(
// 'A user of role public cannot create this record.'
// );
/*
* throw new BadRequestException(
* 'A user of role public cannot create this record.'
* );
*/
}
data = this.keepColumns<T>(data as T, data.getPublicCreateableColumns(), type);
data = this.keepColumns<T>(
data as T,
data.getPublicCreateableColumns(),
type
);
return data;
}
public static asPublicUpdateable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -691,7 +704,8 @@ export default class BaseModel extends BaseEntity {
}
public static asPublicReadableItem<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -703,11 +717,16 @@ export default class BaseModel extends BaseEntity {
);
}
return this.keepColumns(data, data.getPublicReadableAsItemColumns(), type);
return this.keepColumns(
data,
data.getPublicReadableAsItemColumns(),
type
);
}
public static asPublicReadableList<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -719,11 +738,16 @@ export default class BaseModel extends BaseEntity {
);
}
return this.keepColumns(data, data.getPublicReadableAsListColumns(), type);
return this.keepColumns(
data,
data.getPublicReadableAsListColumns(),
type
);
}
public static asPublicDeleteable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -739,7 +763,8 @@ export default class BaseModel extends BaseEntity {
}
public static asOwnerCreateable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -755,7 +780,8 @@ export default class BaseModel extends BaseEntity {
}
public static asOwnerUpdateable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -771,7 +797,8 @@ export default class BaseModel extends BaseEntity {
}
public static asOwnerReadableItem<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -783,11 +810,16 @@ export default class BaseModel extends BaseEntity {
);
}
return this.keepColumns(data, data.getOwnerReadableAsItemColumns(), type);
return this.keepColumns(
data,
data.getOwnerReadableAsItemColumns(),
type
);
}
public static asOwnerReadableList<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -799,11 +831,16 @@ export default class BaseModel extends BaseEntity {
);
}
return this.keepColumns(data, data.getOwnerReadableAsListColumns(), type);
return this.keepColumns(
data,
data.getOwnerReadableAsListColumns(),
type
);
}
public static asOwnerDeleteable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -819,7 +856,8 @@ export default class BaseModel extends BaseEntity {
}
public static asUserCreateable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -835,7 +873,8 @@ export default class BaseModel extends BaseEntity {
}
public static asUserUpdateable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -851,7 +890,8 @@ export default class BaseModel extends BaseEntity {
}
public static asUserReadableItem<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -863,11 +903,16 @@ export default class BaseModel extends BaseEntity {
);
}
return this.keepColumns(data, data.getUserReadableAsItemColumns(), type);
return this.keepColumns(
data,
data.getUserReadableAsItemColumns(),
type
);
}
public static asUserReadableList<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -879,11 +924,16 @@ export default class BaseModel extends BaseEntity {
);
}
return this.keepColumns(data, data.getUserReadableAsListColumns(), type);
return this.keepColumns(
data,
data.getUserReadableAsListColumns(),
type
);
}
public static asUserDeleteable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -899,7 +949,8 @@ export default class BaseModel extends BaseEntity {
}
public static asViewerCreateable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -915,7 +966,8 @@ export default class BaseModel extends BaseEntity {
}
public static asViewerUpdateable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -931,7 +983,8 @@ export default class BaseModel extends BaseEntity {
}
public static asViewerReadableItem<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -943,11 +996,16 @@ export default class BaseModel extends BaseEntity {
);
}
return this.keepColumns(data, data.getViewerReadableAsItemColumns(), type);
return this.keepColumns(
data,
data.getViewerReadableAsItemColumns(),
type
);
}
public static asViewerReadableList<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -959,11 +1017,16 @@ export default class BaseModel extends BaseEntity {
);
}
return this.keepColumns(data, data.getViewerReadableAsListColumns(), type);
return this.keepColumns(
data,
data.getViewerReadableAsListColumns(),
type
);
}
public static asViewerDeleteable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -979,7 +1042,8 @@ export default class BaseModel extends BaseEntity {
}
public static asMemberCreateable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -995,7 +1059,8 @@ export default class BaseModel extends BaseEntity {
}
public static asMemberUpdateable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -1011,7 +1076,8 @@ export default class BaseModel extends BaseEntity {
}
public static asMemberReadableItem<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -1023,11 +1089,16 @@ export default class BaseModel extends BaseEntity {
);
}
return this.keepColumns(data, data.getMemberReadableAsItemColumns(), type);
return this.keepColumns(
data,
data.getMemberReadableAsItemColumns(),
type
);
}
public static asMemberReadableList<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -1039,11 +1110,16 @@ export default class BaseModel extends BaseEntity {
);
}
return this.keepColumns(data, data.getMemberReadableAsListColumns(), type);
return this.keepColumns(
data,
data.getMemberReadableAsListColumns(),
type
);
}
public static asMemberDeleteable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -1059,7 +1135,8 @@ export default class BaseModel extends BaseEntity {
}
public static asAdminCreateable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -1075,7 +1152,8 @@ export default class BaseModel extends BaseEntity {
}
public static asAdminUpdateable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -1091,7 +1169,8 @@ export default class BaseModel extends BaseEntity {
}
public static asAdminReadableList<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -1103,11 +1182,16 @@ export default class BaseModel extends BaseEntity {
);
}
return this.keepColumns(data, data.getAdminReadableAsListColumns(), type);
return this.keepColumns(
data,
data.getAdminReadableAsListColumns(),
type
);
}
public static asAdminReadableItem<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);
@ -1119,11 +1203,16 @@ export default class BaseModel extends BaseEntity {
);
}
return this.keepColumns(data, data.getAdminReadableAsItemColumns(), type);
return this.keepColumns(
data,
data.getAdminReadableAsItemColumns(),
type
);
}
public static asAdminDeleteable<T extends BaseModel>(
data: JSONObject | T, type: { new(): T ;}
data: JSONObject | T,
type: { new (): T }
): T {
if (!(data instanceof BaseModel)) {
data = this._fromJSON<T>(data, type);

View File

@ -1,5 +1,3 @@
import { JSONObject } from "../JSON";
import { JSONObject } from '../JSON';
export default interface EmptyResponseData extends JSONObject {
}
export default interface EmptyResponseData extends JSONObject {}

View File

@ -1,7 +1,9 @@
import BaseModel from "../../Models/BaseModel";
import { JSONObjectOrArray } from "../JSON";
import BaseModel from '../../Models/BaseModel';
import { JSONObjectOrArray } from '../JSON';
export default class HTTPResponse<T extends JSONObjectOrArray | BaseModel | Array<BaseModel>> {
export default class HTTPResponse<
T extends JSONObjectOrArray | BaseModel | Array<BaseModel>
> {
private _statusCode: number = -1;
public get statusCode(): number {
return this._statusCode;
@ -18,21 +20,19 @@ export default class HTTPResponse<T extends JSONObjectOrArray | BaseModel | Arra
this._jsonData = v;
}
private _data! : T;
public get data() : T {
private _data!: T;
public get data(): T {
return this._data;
}
public set data(v : T) {
public set data(v: T) {
this._data = v;
}
public constructor(statusCode: number, data: JSONObjectOrArray) {
this.statusCode = statusCode;
this.jsonData = data;
this.jsonData = data;
let obj!: T;
let obj!: T;
if (obj instanceof BaseModel) {
// this.data = BaseModel.fromJSON(data) as T;
@ -40,6 +40,5 @@ export default class HTTPResponse<T extends JSONObjectOrArray | BaseModel | Arra
} else {
this.data = data as T;
}
}
}

View File

@ -19,7 +19,7 @@ export default class Route {
}
}
public addRoute(route: Route): Route{
public addRoute(route: Route): Route {
this.route += route.toString();
return this;
}

View File

@ -1,6 +1,6 @@
import Email from "./Email";
import ObjectID from "./ObjectID";
import UserRole from "./UserRole";
import Email from './Email';
import ObjectID from './ObjectID';
import UserRole from './UserRole';
export default interface JSONWebTokenData {
userId: ObjectID;
@ -8,4 +8,3 @@ export default interface JSONWebTokenData {
roles: Array<UserRole>;
isMasterAdmin: boolean;
}

View File

@ -12,7 +12,6 @@ import Route from '../Types/API/Route';
import BaseModel from '../Models/BaseModel';
export default class API {
private _protocol: Protocol = Protocol.HTTPS;
public get protocol(): Protocol {
return this._protocol;
@ -29,71 +28,96 @@ export default class API {
this._hostname = v;
}
private _baseRoute! : Route;
public get baseRoute() : Route {
private _baseRoute!: Route;
public get baseRoute(): Route {
return this._baseRoute;
}
public set baseRoute(v : Route) {
public set baseRoute(v: Route) {
this._baseRoute = v;
}
public constructor(protocol: Protocol, hostname: Hostname, baseRoute?: Route) {
public constructor(
protocol: Protocol,
hostname: Hostname,
baseRoute?: Route
) {
this.protocol = protocol;
this.hostname = hostname;
if (baseRoute) {
this.baseRoute = baseRoute;
} else {
this.baseRoute = new Route("/");
this.baseRoute = new Route('/');
}
}
public async get<T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>>(
public async get<
T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>
>(
path: Route,
data?: JSONObject | JSONArray,
headers?: Headers
): Promise<HTTPResponse<T>> {
return await API.get<T>(
new URL(this.protocol, this.hostname, this.baseRoute.addRoute(path)),
new URL(
this.protocol,
this.hostname,
this.baseRoute.addRoute(path)
),
data,
headers
);
}
public async delete<T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>>(
public async delete<
T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>
>(
path: Route,
data?: JSONObject | JSONArray,
headers?: Headers
): Promise<HTTPResponse<T>> {
return await API.delete<T>(
new URL(this.protocol, this.hostname, this.baseRoute.addRoute(path)),
new URL(
this.protocol,
this.hostname,
this.baseRoute.addRoute(path)
),
data,
headers
);
}
public async put<T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>>(
public async put<
T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>
>(
path: Route,
data?: JSONObject | JSONArray,
headers?: Headers
): Promise<HTTPResponse<T>> {
return await API.put<T>(
new URL(this.protocol, this.hostname, this.baseRoute.addRoute(path)),
new URL(
this.protocol,
this.hostname,
this.baseRoute.addRoute(path)
),
data,
headers
);
}
public async post<T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>>(
public async post<
T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>
>(
path: Route,
data?: JSONObject | JSONArray,
headers?: Headers
): Promise<HTTPResponse<T>> {
return await API.post<T>(
new URL(this.protocol, this.hostname, this.baseRoute.addRoute(path)),
new URL(
this.protocol,
this.hostname,
this.baseRoute.addRoute(path)
),
data,
headers
);
@ -128,7 +152,9 @@ export default class API {
return defaultHeaders;
}
public static async get<T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>>(
public static async get<
T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>
>(
url: URL,
data?: JSONObject | JSONArray,
headers?: Headers
@ -136,7 +162,9 @@ export default class API {
return await this.fetch<T>(HTTPMethod.GET, url, data, headers);
}
public static async delete<T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>>(
public static async delete<
T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>
>(
url: URL,
data?: JSONObject | JSONArray,
headers?: Headers
@ -144,7 +172,9 @@ export default class API {
return await this.fetch(HTTPMethod.DELETE, url, data, headers);
}
public static async put<T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>>(
public static async put<
T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>
>(
url: URL,
data?: JSONObject | JSONArray,
headers?: Headers
@ -152,7 +182,9 @@ export default class API {
return await this.fetch(HTTPMethod.PUT, url, data, headers);
}
public static async post<T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>>(
public static async post<
T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>
>(
url: URL,
data?: JSONObject | JSONArray,
headers?: Headers
@ -160,7 +192,9 @@ export default class API {
return await this.fetch(HTTPMethod.POST, url, data, headers);
}
private static async fetch<T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>>(
private static async fetch<
T extends JSONObject | JSONArray | BaseModel | Array<BaseModel>
>(
method: HTTPMethod,
url: URL,
data?: JSONObject | JSONArray,
@ -169,7 +203,6 @@ export default class API {
const apiHeaders: Headers = this.getHeaders(headers);
try {
const result: {
data: JSONObject | JSONArray;
status: number;

View File

@ -145,7 +145,8 @@ export default class BaseAPI<
const body: JSONObject = req.body;
const item: TBaseModel = BaseModel.fromJSON<TBaseModel>(
body['data'] as JSONObject, this.entityType
body['data'] as JSONObject,
this.entityType
) as TBaseModel;
await this.service.updateByRole(oneuptimeRequest.role, {
@ -166,7 +167,8 @@ export default class BaseAPI<
const body: JSONObject = req.body;
const item: TBaseModel = BaseModel.fromJSON<TBaseModel>(
body['data'] as JSONObject, this.entityType
body['data'] as JSONObject,
this.entityType
) as TBaseModel;
const savedItem: BaseModel = await this.service.createByRole(

View File

@ -7,6 +7,4 @@ const app: ExpressApplication = Express.getExpressApp();
export default (appName: string) => {
app.use([`/${appName}`, '/'], version);
app.use([`/${appName}`, '/'], status);
}
};

View File

@ -8,7 +8,7 @@ import LocalCache from '../Infrastructure/LocalCache';
const router: ExpressRouter = Express.getRouter();
router.get('/', (_req: ExpressRequest, res: ExpressResponse) => {
res.send({ app: LocalCache.getString("app", "name") });
res.send({ app: LocalCache.getString('app', 'name') });
});
// General status

View File

@ -3,9 +3,9 @@ import ObjectID from 'Common/Types/ObjectID';
import Port from 'Common/Types/Port';
import Hostname from 'Common/Types/API/Hostname';
export const DisableSignup: boolean = process.env['DISABLE_SIGNUP'] === "true";
export const DisableSignup: boolean = process.env['DISABLE_SIGNUP'] === 'true';
export const IsSaaSService: boolean = process.env['IS_SAAS_SERVICE'] === "true";
export const IsSaaSService: boolean = process.env['IS_SAAS_SERVICE'] === 'true';
export const DatabaseHost: Hostname = new Hostname(
process.env['DATABASE_HOST'] || ''

View File

@ -63,12 +63,13 @@ export default class Database {
const PostgresDataSource: DataSource = new DataSource(
dataSourceOptions
);
const dataSource: DataSource = await PostgresDataSource.initialize();
logger.info("Posgres Database Connected");
const dataSource: DataSource =
await PostgresDataSource.initialize();
logger.info('Posgres Database Connected');
this.dataSource = dataSource;
return dataSource;
} catch (err) {
logger.error("Posgres Database Connection Failed");
logger.error('Posgres Database Connection Failed');
logger.error(err);
throw err;
}

View File

@ -31,13 +31,13 @@ import Role from 'Common/Types/Role';
class DatabaseService<TBaseModel extends BaseModel> {
private postgresDatabase!: PostgresDatabase;
private entityType!: { new(): TBaseModel };
private entityType!: { new (): TBaseModel };
public constructor(
type: { new (): TBaseModel },
postgresDatabase?: PostgresDatabase
) {
this.entityType = type;
this.entityType = type;
if (postgresDatabase) {
this.postgresDatabase = postgresDatabase;
}
@ -380,31 +380,46 @@ class DatabaseService<TBaseModel extends BaseModel> {
): Promise<TBaseModel> {
if (role === Role.Administrator) {
return await this.create({
data: BaseModel.asAdminCreateable<TBaseModel>(createBy.data, this.entityType),
data: BaseModel.asAdminCreateable<TBaseModel>(
createBy.data,
this.entityType
),
});
}
if (role === Role.Member) {
return await this.create({
data: BaseModel.asMemberCreateable<TBaseModel>(createBy.data, this.entityType),
data: BaseModel.asMemberCreateable<TBaseModel>(
createBy.data,
this.entityType
),
});
}
if (role === Role.Public) {
return await this.create({
data: BaseModel.asPublicCreateable<TBaseModel>(createBy.data, this.entityType),
data: BaseModel.asPublicCreateable<TBaseModel>(
createBy.data,
this.entityType
),
});
}
if (role === Role.Viewer) {
return await this.create({
data: BaseModel.asViewerCreateable<TBaseModel>(createBy.data, this.entityType),
data: BaseModel.asViewerCreateable<TBaseModel>(
createBy.data,
this.entityType
),
});
}
if (role === Role.Owner) {
return await this.create({
data: BaseModel.asOwnerCreateable<TBaseModel>(createBy.data, this.entityType),
data: BaseModel.asOwnerCreateable<TBaseModel>(
createBy.data,
this.entityType
),
});
}

View File

@ -61,13 +61,14 @@ class Express {
return this.app;
}
public static async launchApplication(appName: string): Promise<express.Application> {
public static async launchApplication(
appName: string
): Promise<express.Application> {
return new Promise((resolve) => {
if (!this.app) {
this.setupExpress();
}
this.app.listen(this.app.get('port'), () => {
// eslint-disable-next-line
logger.info(`${appName} server started on port: ${this.app.get('port')}`);

View File

@ -63,8 +63,6 @@ const setDefaultHeaders: RequestHandler = (
app.use(cors());
app.use(setDefaultHeaders);
/*
* Add limit of 10 MB to avoid "Request Entity too large error"
* https://stackoverflow.com/questions/19917401/error-request-entity-too-large
@ -73,31 +71,35 @@ app.use(setDefaultHeaders);
app.use(ExpressJson({ limit: '10mb' }));
app.use(ExpressUrlEncoded({ limit: '10mb' }));
// Error Handler.
app.use(
(
err: Error,
_req: ExpressRequest,
res: ExpressResponse,
next: NextFunction
) => {
logger.error(err);
// Error Handler.
app.use((err: Error, _req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
logger.error(err);
if (res.headersSent) {
return next(err);
}
if (res.headersSent) {
return next(err)
if (err instanceof Exception) {
res.status((err as Exception).code);
res.send({ error: (err as Exception).message });
} else {
res.status(500);
res.send({ error: err });
}
}
if (err instanceof Exception) {
res.status((err as Exception).code)
res.send({ error: (err as Exception).message })
} else {
res.status(500)
res.send({ error: err });
}
});
);
app.use(logRequest);
export default async (appName: string) => {
await Express.launchApplication(appName);
LocalCache.setString("app", "name", appName);
LocalCache.setString('app', 'name', appName);
CommonAPI(appName);
return app;
};

View File

@ -2,13 +2,15 @@ import Hostname from 'Common/Types/API/Hostname';
import Protocol from 'Common/Types/API/Protocol';
import Route from 'Common/Types/API/Route';
import Version from 'Common/Types/Version';
import URL from 'Common/Types/API/URL'
import URL from 'Common/Types/API/URL';
export const env: Function = (key: string): string => {
return process.env[key] || '';
};
export const HTTP_PROTOCOL: Protocol = window.location.protocol.includes('https')
export const HTTP_PROTOCOL: Protocol = window.location.protocol.includes(
'https'
)
? Protocol.HTTPS
: Protocol.HTTP;
@ -16,40 +18,23 @@ export const IS_SAAS_SERVICE: boolean = env('IS_SAAS_SERVICE') === 'true';
export const DISABLE_SIGNUP: boolean = env('DISABLE_SIGNUP') === 'true';
export const VERSION: Version = new Version(env('VERSION') || '1.0.0');
export const DASHBOARD_API_ROUTE: Route = new Route(
env('DASHBOARD_API_Route')
);
export const DASHBOARD_API_ROUTE: Route = new Route(env('DASHBOARD_API_Route'));
export const IDENTITY_ROUTE: Route = new Route(
env('IDENTITY_ROUTE')
);
export const IDENTITY_ROUTE: Route = new Route(env('IDENTITY_ROUTE'));
export const DASHBOARD_ROUTE: Route = new Route(
env('DASHBOARD_ROUTE')
);
export const DASHBOARD_ROUTE: Route = new Route(env('DASHBOARD_ROUTE'));
export const INTEGRATION_ROUTE: Route = new Route(
env('INTEGRATION_ROUTE')
);
export const INTEGRATION_ROUTE: Route = new Route(env('INTEGRATION_ROUTE'));
export const HELM_ROUTE: Route = new Route(
env('HELMCHART_ROUTE')
);
export const HELM_ROUTE: Route = new Route(env('HELMCHART_ROUTE'));
export const API_DOCS_ROUTE: Route = new Route(
env('APIDOCS_ROUTE')
);
export const API_DOCS_ROUTE: Route = new Route(env('APIDOCS_ROUTE'));
export const ADMIN_DASHBOARD_ROUTE: Route = new Route(
env('ADMINDASHBOARD_ROUTE')
);
export const ACCOUNTS_ROUTE: Route = new Route(
env('ACCOUNTS_ROUTE')
);
export const HOME_ROUTE: Route = new Route(
env('HOME_ROUTE')
);
export const ACCOUNTS_ROUTE: Route = new Route(env('ACCOUNTS_ROUTE'));
export const HOME_ROUTE: Route = new Route(env('HOME_ROUTE'));
export const DASHBOARD_API_HOSTNAME: Hostname = new Hostname(
window.location.hostname
@ -67,9 +52,7 @@ export const INTEGRATION_HOSTNAME: Hostname = new Hostname(
window.location.hostname
);
export const HELM_HOSTNAME: Hostname = new Hostname(
window.location.hostname
);
export const HELM_HOSTNAME: Hostname = new Hostname(window.location.hostname);
export const API_DOCS_HOSTNAME: Hostname = new Hostname(
window.location.hostname
@ -81,41 +64,48 @@ export const ADMIN_DASHBOARD_HOSTNAME: Hostname = new Hostname(
export const ACCOUNTS_HOSTNAME: Hostname = new Hostname(
window.location.hostname
);
export const HOME_HOSTNAME: Hostname = new Hostname(
window.location.hostname
);
export const HOME_HOSTNAME: Hostname = new Hostname(window.location.hostname);
export const DASHBOARD_API_URL: URL = new URL(
HTTP_PROTOCOL, INTEGRATION_HOSTNAME, INTEGRATION_ROUTE
HTTP_PROTOCOL,
INTEGRATION_HOSTNAME,
INTEGRATION_ROUTE
);
export const IDENTITY_URL: URL = new URL(
HTTP_PROTOCOL, IDENTITY_HOSTNAME, IDENTITY_ROUTE
HTTP_PROTOCOL,
IDENTITY_HOSTNAME,
IDENTITY_ROUTE
);
export const DASHBOARD_URL: URL = new URL(
HTTP_PROTOCOL, DASHBOARD_HOSTNAME, DASHBOARD_ROUTE
HTTP_PROTOCOL,
DASHBOARD_HOSTNAME,
DASHBOARD_ROUTE
);
export const INTEGRATION_URL: URL = new URL(
HTTP_PROTOCOL, INTEGRATION_HOSTNAME, INTEGRATION_ROUTE
HTTP_PROTOCOL,
INTEGRATION_HOSTNAME,
INTEGRATION_ROUTE
);
export const HELM_URL: URL = new URL(
HTTP_PROTOCOL, HELM_HOSTNAME, HELM_ROUTE
);
export const HELM_URL: URL = new URL(HTTP_PROTOCOL, HELM_HOSTNAME, HELM_ROUTE);
export const API_DOCS_URL: URL = new URL(
HTTP_PROTOCOL, API_DOCS_HOSTNAME, API_DOCS_ROUTE
HTTP_PROTOCOL,
API_DOCS_HOSTNAME,
API_DOCS_ROUTE
);
export const ADMIN_DASHBOARD_URL: URL = new URL(
HTTP_PROTOCOL, ADMIN_DASHBOARD_HOSTNAME, ADMIN_DASHBOARD_ROUTE
HTTP_PROTOCOL,
ADMIN_DASHBOARD_HOSTNAME,
ADMIN_DASHBOARD_ROUTE
);
export const ACCOUNTS_URL: URL = new URL(
HTTP_PROTOCOL, ACCOUNTS_HOSTNAME, ACCOUNTS_ROUTE
HTTP_PROTOCOL,
ACCOUNTS_HOSTNAME,
ACCOUNTS_ROUTE
);
export const HOME_URL: URL = new URL(
HTTP_PROTOCOL, HOME_HOSTNAME, HOME_ROUTE
);
export const HOME_URL: URL = new URL(HTTP_PROTOCOL, HOME_HOSTNAME, HOME_ROUTE);

View File

@ -1,4 +1,8 @@
import { DASHBOARD_API_HOSTNAME, HTTP_PROTOCOL, DASHBOARD_API_ROUTE } from '../../Config';
import {
DASHBOARD_API_HOSTNAME,
HTTP_PROTOCOL,
DASHBOARD_API_ROUTE,
} from '../../Config';
import BaseAPI from './BaseAPI';
class BackendAPI extends BaseAPI {

View File

@ -7,7 +7,6 @@ import cron from 'node-cron';
export const APP_NAME: string = 'container';
const app = App(APP_NAME);
const cronContainerSecurityStartTime: $TSFixMe = Math.floor(Math.random() * 50);
//Run this cron every 5 minute.

View File

@ -9,7 +9,6 @@ import {
export const APP_NAME: string = 'dashboard';
const app = App(APP_NAME);
app.use(ExpressStatic(path.join(__dirname, 'build')));
app.use(

View File

@ -168,7 +168,10 @@ app.use(
IncidentPriorityAPI
);
app.use(['/incidentSettings', `${APP_NAME}/incidentSettings`], IncidentSettingsAPI);
app.use(
['/incidentSettings', `${APP_NAME}/incidentSettings`],
IncidentSettingsAPI
);
app.use(['/reports', `${APP_NAME}/reports`], ReportAPI);
@ -196,7 +199,10 @@ app.use(['/stripe', `${APP_NAME}/stripe`], StripeAPI);
app.use(['/subscriber', `${APP_NAME}/subscriber`], SubscriberAPI);
app.use(['/subscriberAlert', `${APP_NAME}/subscriberAlert`], SubscriberAlertAPI);
app.use(
['/subscriberAlert', `${APP_NAME}/subscriberAlert`],
SubscriberAlertAPI
);
app.use(['/emailTemplate', `${APP_NAME}/emailTemplate`], EmailTemplateAPI);
@ -206,14 +212,20 @@ app.use(['/smsTemplate', `${APP_NAME}/smsTemplate`], SmsTemplateAPI);
app.use(['/smsSmtp', `${APP_NAME}/smsSmtp`], SmsSmtpAPI);
app.use(['/resourceCategory', `${APP_NAME}/resourceCategory`], ResourceCategoryAPI);
app.use(
['/resourceCategory', `${APP_NAME}/resourceCategory`],
ResourceCategoryAPI
);
app.use(
['/statusPageCategory', `${APP_NAME}/statusPageCategory`],
StatusPageCategoryAPI
);
app.use(['/monitorCriteria', `${APP_NAME}/monitorCriteria`], MonitorCriteriaAPI);
app.use(
['/monitorCriteria', `${APP_NAME}/monitorCriteria`],
MonitorCriteriaAPI
);
app.use(['/scheduledEvent', `${APP_NAME}/scheduledEvent`], ScheduledEventAPI);
@ -233,7 +245,10 @@ app.use(['/email-logs', `${APP_NAME}/email-logs`], EmailLogsAPI);
app.use(['/call-logs', `${APP_NAME}/call-logs`], CallLogsAPI);
app.use(['/automated-scripts', `${APP_NAME}/automated-scripts`], AutomatedScriptAPI);
app.use(
['/automated-scripts', `${APP_NAME}/automated-scripts`],
AutomatedScriptAPI
);
app.use(['/sms-logs', `${APP_NAME}/sms-logs`], SMSLogAPI);
@ -262,11 +277,17 @@ app.use(['/securityLog', `${APP_NAME}/securityLog`], ContainerSecurityLogAPI);
app.use(['/error-tracker', `${APP_NAME}/error-tracker`], ErrorTrackerAPI);
app.use(['/incidentSla', `${APP_NAME}/incidentSla`], IncidentCommunicationSlaAPI);
app.use(
['/incidentSla', `${APP_NAME}/incidentSla`],
IncidentCommunicationSlaAPI
);
app.use(['/monitorSla', `${APP_NAME}/monitorSla`], MonitorSlaAPI);
app.use(['/incoming-request', `${APP_NAME}/incoming-request`], IncomingHTTPRequestAPI);
app.use(
['/incoming-request', `${APP_NAME}/incoming-request`],
IncomingHTTPRequestAPI
);
app.use(['/ScriptRunner', `${APP_NAME}/ScriptRunner`], ScriptRunnerAPI);

View File

@ -5,8 +5,6 @@ import path from 'path';
export const APP_NAME: string = 'chart';
const app = App(APP_NAME);
// Set the view engine to ejs
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

View File

@ -13,7 +13,6 @@ import productCompare, { Product } from './config/product-compare';
import builder from 'xmlbuilder2';
import { XMLBuilder } from 'xmlbuilder2/lib/interfaces';
export const APP_NAME: string = 'home';
const app = App(APP_NAME);

View File

@ -12,11 +12,9 @@ import HTTPTestServerResponse from './types/HttpTestServerResponse';
import ResponseType from 'Common/Types/api/ResponseType';
import Headers from 'Common/Types/API/Headers';
export const APP_NAME: string = 'home';
const app = App(APP_NAME);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(ExpressStatic('public'));

View File

@ -33,16 +33,21 @@ const router: ExpressRouter = Express.getRouter();
router.post(
'/signup',
async (req: ExpressRequest, res: ExpressResponse, next: NextFunction): Promise<void> => {
async (
req: ExpressRequest,
res: ExpressResponse,
next: NextFunction
): Promise<void> => {
try {
if (DisableSignup) {
throw new BadRequestException('Sign up is disabled.');
}
const data: JSONObject = req.body;
const user: User = User.asPublicCreateable<User>(
data['user'] as JSONObject, User
data['user'] as JSONObject,
User
);
if (IsSaaSService) {
@ -75,7 +80,7 @@ router.post(
emailVerificationToken &&
user &&
alreadySavedUser?.id?.toString() ===
emailVerificationToken?.userId?.toString()
emailVerificationToken?.userId?.toString()
) {
user.isEmailVerified = true;
}

View File

@ -15,12 +15,13 @@ const init = async () => {
// init the app
await App(APP_NAME);
// connect to the database.
await PostgresAppInstance.connect(PostgresAppInstance.getDatasourceOptions());
await PostgresAppInstance.connect(
PostgresAppInstance.getDatasourceOptions()
);
} catch (err) {
logger.error("App Init Failed:")
logger.error('App Init Failed:');
logger.error(err);
}
};
init();

View File

@ -1,6 +1,7 @@
import App from 'CommonServer/Utils/StartServer';
export const APP_NAME: string = 'integration';
const app = App(APP_NAME);
export default app;

View File

@ -10,7 +10,6 @@ import cron from 'node-cron';
export const APP_NAME: string = 'licensing';
const app = App(APP_NAME);
const cronMinuteStartTime: $TSFixMe = Math.floor(Math.random() * 50);
//App Version