mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 14:49:07 +00:00
fix lint.
This commit is contained in:
parent
90c6eb4cac
commit
a95201e803
@ -7,16 +7,15 @@ import FormFieldSchemaType from 'CommonUI/src/Components/Forms/Types/FormFieldSc
|
||||
import OneUptimeLogo from 'CommonUI/src/Images/logos/OneUptimePNG/7.png';
|
||||
import { DASHBOARD_URL } from 'CommonUI/src/Config';
|
||||
import { JSONObject } from 'Common/Types/JSON';
|
||||
import UserUtil from "CommonUI/src/Utils/User";
|
||||
import UserUtil from 'CommonUI/src/Utils/User';
|
||||
import Navigation from 'CommonUI/src/Utils/Navigation';
|
||||
import Email from 'Common/Types/Email';
|
||||
import ObjectID from 'Common/Types/ObjectID';
|
||||
import Name from 'Common/Types/Name';
|
||||
import URL from 'Common/Types/API/URL';
|
||||
import { SIGNUP_API_URL } from "../Utils/ApiPaths";
|
||||
import { SIGNUP_API_URL } from '../Utils/ApiPaths';
|
||||
|
||||
const RegisterPage: FunctionComponent = () => {
|
||||
|
||||
const user: User = new User();
|
||||
const apiUrl: URL = SIGNUP_API_URL;
|
||||
|
||||
@ -56,16 +55,14 @@ const RegisterPage: FunctionComponent = () => {
|
||||
id="register-form"
|
||||
showAsColumns={2}
|
||||
maxPrimaryButtonWidth={true}
|
||||
initialValues= {
|
||||
{
|
||||
email: '',
|
||||
name: '',
|
||||
companyName: '',
|
||||
companyPhoneNumber: '',
|
||||
password: '',
|
||||
confirmPassword: ''
|
||||
}
|
||||
}
|
||||
initialValues={{
|
||||
email: '',
|
||||
name: '',
|
||||
companyName: '',
|
||||
companyPhoneNumber: '',
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
}}
|
||||
fields={[
|
||||
{
|
||||
field: {
|
||||
@ -106,7 +103,8 @@ const RegisterPage: FunctionComponent = () => {
|
||||
fieldType:
|
||||
FormFieldSchemaType.Text,
|
||||
required: true,
|
||||
placeholder: '+1-123-456-7890',
|
||||
placeholder:
|
||||
'+1-123-456-7890',
|
||||
title: 'Phone Number',
|
||||
},
|
||||
{
|
||||
@ -145,17 +143,32 @@ const RegisterPage: FunctionComponent = () => {
|
||||
formType={FormType.Create}
|
||||
submitButtonText={'Sign Up'}
|
||||
onSuccess={(value: JSONObject) => {
|
||||
const user: User = User.fromJSON(value["user"] as JSONObject, User) as User;
|
||||
const token: string = value["token"] as string;
|
||||
const user: User =
|
||||
User.fromJSON(
|
||||
value[
|
||||
'user'
|
||||
] as JSONObject,
|
||||
User
|
||||
) as User;
|
||||
const token: string = value[
|
||||
'token'
|
||||
] as string;
|
||||
|
||||
UserUtil.setAccessToken(token);
|
||||
UserUtil.setEmail(user.email as Email);
|
||||
UserUtil.setUserId(user.id as ObjectID);
|
||||
UserUtil.setName(user.name as Name);
|
||||
|
||||
// go to dashboard, user should be logged in.
|
||||
Navigation.navigate(DASHBOARD_URL);
|
||||
UserUtil.setEmail(
|
||||
user.email as Email
|
||||
);
|
||||
UserUtil.setUserId(
|
||||
user.id as ObjectID
|
||||
);
|
||||
UserUtil.setName(
|
||||
user.name as Name
|
||||
);
|
||||
|
||||
// go to dashboard, user should be logged in.
|
||||
Navigation.navigate(
|
||||
DASHBOARD_URL
|
||||
);
|
||||
}}
|
||||
/>
|
||||
|
||||
|
@ -2,4 +2,4 @@ import Route from 'Common/Types/API/Route';
|
||||
import URL from 'Common/Types/API/URL';
|
||||
import { IDENTITY_URL } from 'CommonUI/src/Config';
|
||||
|
||||
export const SIGNUP_API_URL: URL = IDENTITY_URL.addRoute(new Route("/signup"));
|
||||
export const SIGNUP_API_URL: URL = IDENTITY_URL.addRoute(new Route('/signup'));
|
||||
|
@ -440,7 +440,7 @@ export default class BaseModel extends BaseEntity {
|
||||
}
|
||||
|
||||
public getPublicCreateableColumns<T extends BaseModel>(type: {
|
||||
new(): T;
|
||||
new (): T;
|
||||
}): Columns {
|
||||
const obj: T = new type();
|
||||
const accessControl: Dictionary<AccessControl> =
|
||||
@ -655,18 +655,34 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
private static _fromJSON<T extends BaseModel>(
|
||||
json: JSONObject,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
const baseModel: T = new type();
|
||||
|
||||
for (const key of Object.keys(json)) {
|
||||
if (baseModel.getTableColumnMetadata(key) && baseModel.getTableColumnMetadata(key).type === TableColumnType.HashedString) {
|
||||
if (
|
||||
baseModel.getTableColumnMetadata(key) &&
|
||||
baseModel.getTableColumnMetadata(key).type ===
|
||||
TableColumnType.HashedString
|
||||
) {
|
||||
(baseModel as any)[key] = new HashedString(json[key] as string);
|
||||
} else if (baseModel.getTableColumnMetadata(key) && baseModel.getTableColumnMetadata(key).type === TableColumnType.Name) {
|
||||
} else if (
|
||||
baseModel.getTableColumnMetadata(key) &&
|
||||
baseModel.getTableColumnMetadata(key).type ===
|
||||
TableColumnType.Name
|
||||
) {
|
||||
(baseModel as any)[key] = new Name(json[key] as string);
|
||||
} else if (baseModel.getTableColumnMetadata(key) && baseModel.getTableColumnMetadata(key).type === TableColumnType.Email) {
|
||||
} else if (
|
||||
baseModel.getTableColumnMetadata(key) &&
|
||||
baseModel.getTableColumnMetadata(key).type ===
|
||||
TableColumnType.Email
|
||||
) {
|
||||
(baseModel as any)[key] = new Email(json[key] as string);
|
||||
} else if (baseModel.getTableColumnMetadata(key) && baseModel.getTableColumnMetadata(key).type === TableColumnType.ObjectID) {
|
||||
} else if (
|
||||
baseModel.getTableColumnMetadata(key) &&
|
||||
baseModel.getTableColumnMetadata(key).type ===
|
||||
TableColumnType.ObjectID
|
||||
) {
|
||||
(baseModel as any)[key] = new ObjectID(json[key] as string);
|
||||
} else {
|
||||
(baseModel as any)[key] = json[key];
|
||||
@ -678,7 +694,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static fromJSON<T extends BaseModel>(
|
||||
json: JSONObject | JSONArray,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T | Array<T> {
|
||||
if (Array.isArray(json)) {
|
||||
const arr: Array<T> = [];
|
||||
@ -696,7 +712,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();
|
||||
|
||||
@ -719,7 +735,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asPublicCreateable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -741,7 +757,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asPublicUpdateable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -758,7 +774,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asPublicReadableItem<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -779,7 +795,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asPublicReadableList<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -800,7 +816,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asPublicDeleteable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -817,7 +833,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asOwnerCreateable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -834,7 +850,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asOwnerUpdateable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -851,7 +867,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asOwnerReadableItem<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -872,7 +888,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asOwnerReadableList<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -893,7 +909,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asOwnerDeleteable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -910,7 +926,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asUserCreateable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -927,7 +943,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asUserUpdateable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -944,7 +960,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asUserReadableItem<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -965,7 +981,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asUserReadableList<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -986,7 +1002,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asUserDeleteable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1003,7 +1019,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asViewerCreateable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1020,7 +1036,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asViewerUpdateable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1037,7 +1053,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asViewerReadableItem<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1058,7 +1074,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asViewerReadableList<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1079,7 +1095,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asViewerDeleteable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1096,7 +1112,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asMemberCreateable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1113,7 +1129,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asMemberUpdateable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1130,7 +1146,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asMemberReadableItem<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1151,7 +1167,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asMemberReadableList<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1172,7 +1188,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asMemberDeleteable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1189,7 +1205,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asAdminCreateable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1206,7 +1222,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asAdminUpdateable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1223,7 +1239,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asAdminReadableList<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1244,7 +1260,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asAdminReadableItem<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1265,7 +1281,7 @@ export default class BaseModel extends BaseEntity {
|
||||
|
||||
public static asAdminDeleteable<T extends BaseModel>(
|
||||
data: JSONObject | T,
|
||||
type: { new(): T }
|
||||
type: { new (): T }
|
||||
): T {
|
||||
if (!(data instanceof BaseModel)) {
|
||||
data = this._fromJSON<T>(data, type);
|
||||
@ -1288,13 +1304,29 @@ export default class BaseModel extends BaseEntity {
|
||||
const json: JSONObject = {};
|
||||
for (const key of this.getTableColumns().columns) {
|
||||
if ((this as any)[key]) {
|
||||
if (this.getTableColumnMetadata(key) && this.getTableColumnMetadata(key).type === TableColumnType.HashedString) {
|
||||
if (
|
||||
this.getTableColumnMetadata(key) &&
|
||||
this.getTableColumnMetadata(key).type ===
|
||||
TableColumnType.HashedString
|
||||
) {
|
||||
json[key] = ((this as any)[key] as HashedString).toString();
|
||||
} else if (this.getTableColumnMetadata(key) && this.getTableColumnMetadata(key).type === TableColumnType.Name) {
|
||||
} else if (
|
||||
this.getTableColumnMetadata(key) &&
|
||||
this.getTableColumnMetadata(key).type ===
|
||||
TableColumnType.Name
|
||||
) {
|
||||
json[key] = ((this as any)[key] as Name).toString();
|
||||
} else if (this.getTableColumnMetadata(key) && this.getTableColumnMetadata(key).type === TableColumnType.Email) {
|
||||
} else if (
|
||||
this.getTableColumnMetadata(key) &&
|
||||
this.getTableColumnMetadata(key).type ===
|
||||
TableColumnType.Email
|
||||
) {
|
||||
json[key] = ((this as any)[key] as Email).toString();
|
||||
} else if (this.getTableColumnMetadata(key) && this.getTableColumnMetadata(key).type === TableColumnType.ObjectID) {
|
||||
} else if (
|
||||
this.getTableColumnMetadata(key) &&
|
||||
this.getTableColumnMetadata(key).type ===
|
||||
TableColumnType.ObjectID
|
||||
) {
|
||||
json[key] = ((this as any)[key] as ObjectID).toString();
|
||||
} else {
|
||||
json[key] = (this as any)[key];
|
||||
|
@ -10,12 +10,16 @@ import CrudApiEndpoint from '../Types/Database/CrudApiEndpoint';
|
||||
import Route from '../Types/API/Route';
|
||||
import TableColumnType from '../Types/Database/TableColumnType';
|
||||
|
||||
@CrudApiEndpoint(new Route("/email-verification-token"))
|
||||
@CrudApiEndpoint(new Route('/email-verification-token'))
|
||||
@Entity({
|
||||
name: 'EmailVerificationToken',
|
||||
})
|
||||
export default class EmailVerificationToken extends BaseModel {
|
||||
@TableColumn({ manyToOneRelationColumn: 'userId', required: true, type: TableColumnType.Entity })
|
||||
@TableColumn({
|
||||
manyToOneRelationColumn: 'userId',
|
||||
required: true,
|
||||
type: TableColumnType.Entity,
|
||||
})
|
||||
@ManyToOne(
|
||||
(_type: string) => {
|
||||
return User;
|
||||
@ -30,7 +34,7 @@ export default class EmailVerificationToken extends BaseModel {
|
||||
@JoinColumn({ name: 'userId' })
|
||||
public user?: User;
|
||||
|
||||
@TableColumn({type: TableColumnType.ObjectID})
|
||||
@TableColumn({ type: TableColumnType.ObjectID })
|
||||
@Column({
|
||||
type: ColumnType.ObjectID,
|
||||
nullable: false,
|
||||
@ -38,7 +42,7 @@ export default class EmailVerificationToken extends BaseModel {
|
||||
})
|
||||
public userId?: ObjectID;
|
||||
|
||||
@TableColumn({type: TableColumnType.Email})
|
||||
@TableColumn({ type: TableColumnType.Email })
|
||||
@Column({
|
||||
type: ColumnType.Email,
|
||||
length: ColumnLength.Email,
|
||||
@ -48,7 +52,11 @@ export default class EmailVerificationToken extends BaseModel {
|
||||
public email?: Email = undefined;
|
||||
|
||||
@Index()
|
||||
@TableColumn({ required: true, unique: true, type: TableColumnType.ObjectID })
|
||||
@TableColumn({
|
||||
required: true,
|
||||
unique: true,
|
||||
type: TableColumnType.ObjectID,
|
||||
})
|
||||
@Column({
|
||||
type: ColumnType.ObjectID,
|
||||
nullable: false,
|
||||
|
@ -13,13 +13,17 @@ import CrudApiEndpoint from '../Types/Database/CrudApiEndpoint';
|
||||
import Route from '../Types/API/Route';
|
||||
import TableColumnType from '../Types/Database/TableColumnType';
|
||||
|
||||
@CrudApiEndpoint(new Route("/probe"))
|
||||
@CrudApiEndpoint(new Route('/probe'))
|
||||
@SlugifyColumn('name', 'slug')
|
||||
@Entity({
|
||||
name: 'Probe',
|
||||
})
|
||||
export default class Probe extends BaseModel {
|
||||
@TableColumn({ required: true, unique: true, type: TableColumnType.ObjectID })
|
||||
@TableColumn({
|
||||
required: true,
|
||||
unique: true,
|
||||
type: TableColumnType.ObjectID,
|
||||
})
|
||||
@Column({
|
||||
type: ColumnType.ObjectID,
|
||||
nullable: false,
|
||||
@ -54,7 +58,11 @@ export default class Probe extends BaseModel {
|
||||
})
|
||||
public probeVersion?: Version;
|
||||
|
||||
@TableColumn({ isDefaultValueColumn: true, required: true, type: TableColumnType.Date })
|
||||
@TableColumn({
|
||||
isDefaultValueColumn: true,
|
||||
required: true,
|
||||
type: TableColumnType.Date,
|
||||
})
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: () => {
|
||||
@ -64,7 +72,7 @@ export default class Probe extends BaseModel {
|
||||
})
|
||||
public lastAlive?: Date = undefined;
|
||||
|
||||
@TableColumn({ type: TableColumnType.ShortURL})
|
||||
@TableColumn({ type: TableColumnType.ShortURL })
|
||||
@Column({
|
||||
type: ColumnType.ShortURL,
|
||||
nullable: true,
|
||||
@ -74,7 +82,7 @@ export default class Probe extends BaseModel {
|
||||
public iconUrl?: URL;
|
||||
|
||||
// If this probe is custom to the project and only monitoring reosurces in this project.
|
||||
@TableColumn({type: TableColumnType.Entity})
|
||||
@TableColumn({ type: TableColumnType.Entity })
|
||||
@ManyToOne(
|
||||
(_type: string) => {
|
||||
return Project;
|
||||
@ -90,7 +98,7 @@ export default class Probe extends BaseModel {
|
||||
@JoinColumn({ name: 'projectId' })
|
||||
public project?: Project;
|
||||
|
||||
@TableColumn({type: TableColumnType.ObjectID})
|
||||
@TableColumn({ type: TableColumnType.ObjectID })
|
||||
@Column({
|
||||
type: ColumnType.ObjectID,
|
||||
nullable: true,
|
||||
@ -98,7 +106,7 @@ export default class Probe extends BaseModel {
|
||||
})
|
||||
public projectId?: ObjectID;
|
||||
|
||||
@TableColumn({type: TableColumnType.Entity})
|
||||
@TableColumn({ type: TableColumnType.Entity })
|
||||
@ManyToOne(
|
||||
(_type: string) => {
|
||||
return User;
|
||||
@ -114,7 +122,7 @@ export default class Probe extends BaseModel {
|
||||
@JoinColumn({ name: 'deletedByUserId' })
|
||||
public deletedByUser?: User;
|
||||
|
||||
@TableColumn({type: TableColumnType.ObjectID})
|
||||
@TableColumn({ type: TableColumnType.ObjectID })
|
||||
@Column({
|
||||
type: ColumnType.ObjectID,
|
||||
nullable: true,
|
||||
@ -122,7 +130,7 @@ export default class Probe extends BaseModel {
|
||||
})
|
||||
public deletedByUserId?: ObjectID;
|
||||
|
||||
@TableColumn({type: TableColumnType.ObjectID})
|
||||
@TableColumn({ type: TableColumnType.ObjectID })
|
||||
@ManyToOne(
|
||||
(_type: string) => {
|
||||
return User;
|
||||
@ -137,7 +145,7 @@ export default class Probe extends BaseModel {
|
||||
@JoinColumn({ name: 'createdByUserId' })
|
||||
public createdByUser?: User;
|
||||
|
||||
@TableColumn({type: TableColumnType.ObjectID})
|
||||
@TableColumn({ type: TableColumnType.ObjectID })
|
||||
@Column({
|
||||
type: ColumnType.ObjectID,
|
||||
nullable: true,
|
||||
|
@ -10,7 +10,7 @@ import CrudApiEndpoint from '../Types/Database/CrudApiEndpoint';
|
||||
import Route from '../Types/API/Route';
|
||||
import TableColumnType from '../Types/Database/TableColumnType';
|
||||
|
||||
@CrudApiEndpoint(new Route("/project"))
|
||||
@CrudApiEndpoint(new Route('/project'))
|
||||
@Entity({
|
||||
name: 'Project',
|
||||
})
|
||||
@ -31,7 +31,7 @@ export default class Model extends BaseModel {
|
||||
})
|
||||
public slug?: string = undefined;
|
||||
|
||||
@TableColumn({type: TableColumnType.ShortText})
|
||||
@TableColumn({ type: TableColumnType.ShortText })
|
||||
@Column({
|
||||
type: ColumnType.ShortText,
|
||||
length: ColumnLength.ShortText,
|
||||
@ -40,7 +40,7 @@ export default class Model extends BaseModel {
|
||||
})
|
||||
public paymentProviderPlanId?: string = undefined;
|
||||
|
||||
@TableColumn({type: TableColumnType.ShortText})
|
||||
@TableColumn({ type: TableColumnType.ShortText })
|
||||
@Column({
|
||||
type: ColumnType.ShortText,
|
||||
length: ColumnLength.ShortText,
|
||||
@ -49,7 +49,7 @@ export default class Model extends BaseModel {
|
||||
})
|
||||
public paymentProviderSubscriptionId?: string = undefined;
|
||||
|
||||
@TableColumn({type: TableColumnType.SmallPositiveNumber})
|
||||
@TableColumn({ type: TableColumnType.SmallPositiveNumber })
|
||||
@Column({
|
||||
type: ColumnType.SmallPositiveNumber,
|
||||
nullable: false,
|
||||
@ -58,7 +58,10 @@ export default class Model extends BaseModel {
|
||||
})
|
||||
public numberOfLicensesIssued?: PositiveNumber;
|
||||
|
||||
@TableColumn({ manyToOneRelationColumn: 'createdByUserId', type: TableColumnType.Entity })
|
||||
@TableColumn({
|
||||
manyToOneRelationColumn: 'createdByUserId',
|
||||
type: TableColumnType.Entity,
|
||||
})
|
||||
@ManyToOne(
|
||||
(_type: string) => {
|
||||
return User;
|
||||
@ -73,7 +76,7 @@ export default class Model extends BaseModel {
|
||||
@JoinColumn({ name: 'createdByUserId' })
|
||||
public createdByUser?: User;
|
||||
|
||||
@TableColumn({type: TableColumnType.ObjectID})
|
||||
@TableColumn({ type: TableColumnType.ObjectID })
|
||||
@Column({
|
||||
type: ColumnType.ObjectID,
|
||||
nullable: true,
|
||||
@ -81,7 +84,10 @@ export default class Model extends BaseModel {
|
||||
})
|
||||
public createdByUserId?: ObjectID;
|
||||
|
||||
@TableColumn({ manyToOneRelationColumn: 'deletedByUserId', type: TableColumnType.ObjectID })
|
||||
@TableColumn({
|
||||
manyToOneRelationColumn: 'deletedByUserId',
|
||||
type: TableColumnType.ObjectID,
|
||||
})
|
||||
@ManyToOne(
|
||||
(_type: string) => {
|
||||
return User;
|
||||
@ -97,7 +103,7 @@ export default class Model extends BaseModel {
|
||||
@JoinColumn({ name: 'deletedByUserId' })
|
||||
public deletedByUser?: User;
|
||||
|
||||
@TableColumn({type: TableColumnType.ObjectID})
|
||||
@TableColumn({ type: TableColumnType.ObjectID })
|
||||
@Column({
|
||||
type: ColumnType.ObjectID,
|
||||
nullable: false,
|
||||
@ -106,7 +112,7 @@ export default class Model extends BaseModel {
|
||||
})
|
||||
public apiKey?: ObjectID;
|
||||
|
||||
@TableColumn({ required: true,type: TableColumnType.Boolean })
|
||||
@TableColumn({ required: true, type: TableColumnType.Boolean })
|
||||
@Column({
|
||||
type: ColumnType.Boolean,
|
||||
nullable: false,
|
||||
@ -115,7 +121,7 @@ export default class Model extends BaseModel {
|
||||
})
|
||||
public alertsEnabled?: boolean = undefined;
|
||||
|
||||
@TableColumn({ required: true,type: TableColumnType.SmallPositiveNumber })
|
||||
@TableColumn({ required: true, type: TableColumnType.SmallPositiveNumber })
|
||||
@Column({
|
||||
type: ColumnType.SmallPositiveNumber,
|
||||
nullable: false,
|
||||
@ -133,7 +139,7 @@ export default class Model extends BaseModel {
|
||||
})
|
||||
public isBlocked?: boolean = undefined;
|
||||
|
||||
@TableColumn({ type: TableColumnType.SmallPositiveNumber})
|
||||
@TableColumn({ type: TableColumnType.SmallPositiveNumber })
|
||||
@Column({
|
||||
type: ColumnType.SmallPositiveNumber,
|
||||
nullable: true,
|
||||
@ -141,7 +147,7 @@ export default class Model extends BaseModel {
|
||||
})
|
||||
public unpaidSubscriptionNotificationCount?: PositiveNumber;
|
||||
|
||||
@TableColumn({ type: TableColumnType.Date})
|
||||
@TableColumn({ type: TableColumnType.Date })
|
||||
@Column({
|
||||
type: ColumnType.Date,
|
||||
nullable: true,
|
||||
@ -149,7 +155,7 @@ export default class Model extends BaseModel {
|
||||
})
|
||||
public paymentFailedDate?: Date = undefined;
|
||||
|
||||
@TableColumn({ type: TableColumnType.Date})
|
||||
@TableColumn({ type: TableColumnType.Date })
|
||||
@Column({
|
||||
type: ColumnType.Date,
|
||||
nullable: true,
|
||||
|
@ -18,7 +18,7 @@ import CrudApiEndpoint from '../Types/Database/CrudApiEndpoint';
|
||||
import Route from '../Types/API/Route';
|
||||
import TableColumnType from '../Types/Database/TableColumnType';
|
||||
|
||||
@CrudApiEndpoint(new Route("/user"))
|
||||
@CrudApiEndpoint(new Route('/user'))
|
||||
@PublicRecordPermissions({
|
||||
create: true,
|
||||
readAsList: false,
|
||||
@ -54,7 +54,12 @@ class User extends BaseModel {
|
||||
update: false,
|
||||
delete: false,
|
||||
})
|
||||
@TableColumn({ title: 'Email', required: true, unique: true, type: TableColumnType.Email })
|
||||
@TableColumn({
|
||||
title: 'Email',
|
||||
required: true,
|
||||
unique: true,
|
||||
type: TableColumnType.Email,
|
||||
})
|
||||
@Column({
|
||||
type: ColumnType.Email,
|
||||
length: ColumnLength.Email,
|
||||
@ -63,7 +68,7 @@ class User extends BaseModel {
|
||||
})
|
||||
public email?: Email = undefined;
|
||||
|
||||
@TableColumn({type: TableColumnType.Email})
|
||||
@TableColumn({ type: TableColumnType.Email })
|
||||
@Column({
|
||||
type: ColumnType.Email,
|
||||
length: ColumnLength.Email,
|
||||
@ -79,7 +84,11 @@ class User extends BaseModel {
|
||||
update: false,
|
||||
delete: false,
|
||||
})
|
||||
@TableColumn({ title: 'Password', hashed: true, type: TableColumnType.HashedString })
|
||||
@TableColumn({
|
||||
title: 'Password',
|
||||
hashed: true,
|
||||
type: TableColumnType.HashedString,
|
||||
})
|
||||
@Column({
|
||||
type: ColumnType.HashedString,
|
||||
length: ColumnLength.HashedString,
|
||||
@ -89,7 +98,7 @@ class User extends BaseModel {
|
||||
})
|
||||
public password?: HashedString = undefined;
|
||||
|
||||
@TableColumn({ isDefaultValueColumn: true, type: TableColumnType.Boolean })
|
||||
@TableColumn({ isDefaultValueColumn: true, type: TableColumnType.Boolean })
|
||||
@Column({
|
||||
type: ColumnType.Boolean,
|
||||
default: false,
|
||||
@ -103,7 +112,7 @@ class User extends BaseModel {
|
||||
update: false,
|
||||
delete: false,
|
||||
})
|
||||
@TableColumn({type: TableColumnType.Name})
|
||||
@TableColumn({ type: TableColumnType.Name })
|
||||
@Column({
|
||||
type: ColumnType.Name,
|
||||
length: ColumnLength.Name,
|
||||
@ -119,7 +128,7 @@ class User extends BaseModel {
|
||||
update: false,
|
||||
delete: false,
|
||||
})
|
||||
@TableColumn({ type: TableColumnType.ShortText})
|
||||
@TableColumn({ type: TableColumnType.ShortText })
|
||||
@Column({
|
||||
type: ColumnType.ShortText,
|
||||
length: ColumnLength.ShortText,
|
||||
@ -135,7 +144,7 @@ class User extends BaseModel {
|
||||
update: false,
|
||||
delete: false,
|
||||
})
|
||||
@TableColumn({ type: TableColumnType.ShortText})
|
||||
@TableColumn({ type: TableColumnType.ShortText })
|
||||
@Column({
|
||||
type: ColumnType.ShortText,
|
||||
length: ColumnLength.ShortText,
|
||||
@ -151,7 +160,7 @@ class User extends BaseModel {
|
||||
update: false,
|
||||
delete: false,
|
||||
})
|
||||
@TableColumn({ type: TableColumnType.ShortText})
|
||||
@TableColumn({ type: TableColumnType.ShortText })
|
||||
@Column({
|
||||
type: ColumnType.ShortText,
|
||||
length: ColumnLength.ShortText,
|
||||
@ -167,7 +176,7 @@ class User extends BaseModel {
|
||||
update: false,
|
||||
delete: false,
|
||||
})
|
||||
@TableColumn({ type: TableColumnType.Phone})
|
||||
@TableColumn({ type: TableColumnType.Phone })
|
||||
@Column({
|
||||
type: ColumnType.Phone,
|
||||
length: ColumnLength.Phone,
|
||||
@ -177,7 +186,7 @@ class User extends BaseModel {
|
||||
})
|
||||
public companyPhoneNumber?: Phone = undefined;
|
||||
|
||||
@TableColumn({ type: TableColumnType.ShortURL})
|
||||
@TableColumn({ type: TableColumnType.ShortURL })
|
||||
@Column({
|
||||
type: ColumnType.ShortURL,
|
||||
length: ColumnLength.ShortURL,
|
||||
@ -187,7 +196,11 @@ class User extends BaseModel {
|
||||
})
|
||||
public profilePicImageUrl?: URL = undefined;
|
||||
|
||||
@TableColumn({ isDefaultValueColumn: true, required: true, type: TableColumnType.Boolean })
|
||||
@TableColumn({
|
||||
isDefaultValueColumn: true,
|
||||
required: true,
|
||||
type: TableColumnType.Boolean,
|
||||
})
|
||||
@Column({
|
||||
type: ColumnType.Boolean,
|
||||
default: false,
|
||||
@ -196,7 +209,7 @@ class User extends BaseModel {
|
||||
})
|
||||
public twoFactorAuthEnabled?: boolean = undefined;
|
||||
|
||||
@TableColumn({type: TableColumnType.ShortText})
|
||||
@TableColumn({ type: TableColumnType.ShortText })
|
||||
@Column({
|
||||
type: ColumnType.ShortText,
|
||||
length: ColumnLength.ShortText,
|
||||
@ -205,7 +218,7 @@ class User extends BaseModel {
|
||||
})
|
||||
public twoFactorSecretCode?: string = undefined;
|
||||
|
||||
@TableColumn({ type: TableColumnType.ShortURL})
|
||||
@TableColumn({ type: TableColumnType.ShortURL })
|
||||
@Column({
|
||||
type: ColumnType.ShortURL,
|
||||
length: ColumnLength.ShortURL,
|
||||
@ -215,7 +228,7 @@ class User extends BaseModel {
|
||||
})
|
||||
public twoFactorAuthUrl?: URL;
|
||||
|
||||
@TableColumn({type: TableColumnType.Array})
|
||||
@TableColumn({ type: TableColumnType.Array })
|
||||
@Column({
|
||||
type: ColumnType.Array,
|
||||
nullable: true,
|
||||
@ -223,7 +236,7 @@ class User extends BaseModel {
|
||||
})
|
||||
public backupCodes?: Array<string> = undefined;
|
||||
|
||||
@TableColumn({type: TableColumnType.ShortText})
|
||||
@TableColumn({ type: TableColumnType.ShortText })
|
||||
@Column({
|
||||
type: ColumnType.ShortText,
|
||||
length: ColumnLength.ShortText,
|
||||
@ -232,7 +245,7 @@ class User extends BaseModel {
|
||||
})
|
||||
public jwtRefreshToken?: string = undefined;
|
||||
|
||||
@TableColumn({type: TableColumnType.ShortText})
|
||||
@TableColumn({ type: TableColumnType.ShortText })
|
||||
@Column({
|
||||
type: ColumnType.ShortText,
|
||||
length: ColumnLength.ShortText,
|
||||
@ -241,7 +254,7 @@ class User extends BaseModel {
|
||||
})
|
||||
public paymentProviderCustomerId?: string = undefined;
|
||||
|
||||
@TableColumn({type: TableColumnType.ShortText})
|
||||
@TableColumn({ type: TableColumnType.ShortText })
|
||||
@Column({
|
||||
type: ColumnType.ShortText,
|
||||
length: ColumnLength.ShortText,
|
||||
@ -250,7 +263,7 @@ class User extends BaseModel {
|
||||
})
|
||||
public resetPasswordToken?: string = undefined;
|
||||
|
||||
@TableColumn({type: TableColumnType.Date})
|
||||
@TableColumn({ type: TableColumnType.Date })
|
||||
@Column({
|
||||
type: ColumnType.Date,
|
||||
nullable: true,
|
||||
@ -291,7 +304,11 @@ class User extends BaseModel {
|
||||
})
|
||||
public promotionName?: string = undefined;
|
||||
|
||||
@TableColumn({ isDefaultValueColumn: true, required: true, type: TableColumnType.Boolean })
|
||||
@TableColumn({
|
||||
isDefaultValueColumn: true,
|
||||
required: true,
|
||||
type: TableColumnType.Boolean,
|
||||
})
|
||||
@Column({
|
||||
type: ColumnType.Boolean,
|
||||
nullable: false,
|
||||
@ -308,7 +325,11 @@ class User extends BaseModel {
|
||||
})
|
||||
public paymentFailedDate?: Date = undefined;
|
||||
|
||||
@TableColumn({ isDefaultValueColumn: true, required: true, type: TableColumnType.Boolean })
|
||||
@TableColumn({
|
||||
isDefaultValueColumn: true,
|
||||
required: true,
|
||||
type: TableColumnType.Boolean,
|
||||
})
|
||||
@Column({
|
||||
type: ColumnType.Boolean,
|
||||
nullable: false,
|
||||
@ -317,7 +338,11 @@ class User extends BaseModel {
|
||||
})
|
||||
public isMasterAdmin?: boolean = undefined;
|
||||
|
||||
@TableColumn({ isDefaultValueColumn: true, required: true, type: TableColumnType.Boolean })
|
||||
@TableColumn({
|
||||
isDefaultValueColumn: true,
|
||||
required: true,
|
||||
type: TableColumnType.Boolean,
|
||||
})
|
||||
@Column({
|
||||
type: ColumnType.Boolean,
|
||||
nullable: false,
|
||||
@ -326,7 +351,7 @@ class User extends BaseModel {
|
||||
})
|
||||
public isBlocked?: boolean = undefined;
|
||||
|
||||
@TableColumn({type: TableColumnType.Phone})
|
||||
@TableColumn({ type: TableColumnType.Phone })
|
||||
@Column({
|
||||
type: ColumnType.Phone,
|
||||
length: ColumnLength.Phone,
|
||||
|
@ -31,7 +31,7 @@ export default class HTTPResponse<
|
||||
public constructor(statusCode: number, data: JSONObjectOrArray) {
|
||||
this.statusCode = statusCode;
|
||||
this.jsonData = data;
|
||||
this.data = data as T;
|
||||
this.data = data as T;
|
||||
}
|
||||
|
||||
public isSuccess(): boolean {
|
||||
|
@ -104,7 +104,7 @@ export default class URL extends DatabaseProperty {
|
||||
}
|
||||
|
||||
public addRoute(route: Route | string): URL {
|
||||
if (typeof route === "string") {
|
||||
if (typeof route === 'string') {
|
||||
this.route.addRoute(new Route(route));
|
||||
} else {
|
||||
this.route.addRoute(route);
|
||||
@ -123,8 +123,6 @@ export default class URL extends DatabaseProperty {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected static override fromDatabase(_value: string): URL | null {
|
||||
if (_value) {
|
||||
return URL.fromString(_value);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Route from "../API/Route";
|
||||
import Route from '../API/Route';
|
||||
|
||||
export default (apiPath: Route) => {
|
||||
return (ctr: Function) => {
|
||||
|
@ -16,7 +16,7 @@ export interface TableColumnMetadata {
|
||||
hashed?: boolean;
|
||||
encrypted?: boolean;
|
||||
manyToOneRelationColumn?: string;
|
||||
type: TableColumnType
|
||||
type: TableColumnType;
|
||||
}
|
||||
|
||||
export default (props: TableColumnMetadata): ReflectionMetadataType => {
|
||||
|
@ -226,7 +226,7 @@ export default class API {
|
||||
// Do whatever you want with native error
|
||||
errorResponse = this.getErrorResponse(error);
|
||||
} else {
|
||||
throw new APIException(error.message)
|
||||
throw new APIException(error.message);
|
||||
}
|
||||
|
||||
this.handleError(errorResponse);
|
||||
|
@ -7,7 +7,7 @@ const logger: Logger = createLogger({
|
||||
errors({ stack: true }), // <-- use errors format
|
||||
timestamp(),
|
||||
prettyPrint()
|
||||
),
|
||||
),
|
||||
transports: [new transports.Console()],
|
||||
});
|
||||
|
||||
|
@ -44,9 +44,9 @@ export default class Response {
|
||||
}`;
|
||||
|
||||
if (oneUptimeResponse.statusCode > 299) {
|
||||
logger.error(header_info + "\n "+body_info);
|
||||
logger.error(header_info + '\n ' + body_info);
|
||||
} else {
|
||||
logger.info(header_info + "\n "+body_info);
|
||||
logger.info(header_info + '\n ' + body_info);
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ export default class Response {
|
||||
req: ExpressRequest,
|
||||
res: ExpressResponse,
|
||||
list: Array<BaseModel | JSONObject>,
|
||||
count: PositiveNumber,
|
||||
count: PositiveNumber
|
||||
): void {
|
||||
const oneUptimeRequest: OneUptimeRequest = req as OneUptimeRequest;
|
||||
const oneUptimeResponse: OneUptimeResponse = res as OneUptimeResponse;
|
||||
@ -186,7 +186,7 @@ export default class Response {
|
||||
public static sendItemResponse(
|
||||
req: ExpressRequest,
|
||||
res: ExpressResponse,
|
||||
item: JSONObject | BaseModel,
|
||||
item: JSONObject | BaseModel
|
||||
): void {
|
||||
if (item instanceof BaseModel) {
|
||||
item = item.toJSON();
|
||||
@ -199,7 +199,7 @@ export default class Response {
|
||||
'ExpressRequest-Id',
|
||||
oneUptimeRequest.id.toString()
|
||||
);
|
||||
|
||||
|
||||
oneUptimeResponse.set('Pod-Id', process.env['POD_NAME']);
|
||||
|
||||
if (oneUptimeRequest.query['output-type'] === 'csv') {
|
||||
|
@ -26,7 +26,6 @@ const app: ExpressApplication = Express.getExpressApp();
|
||||
|
||||
app.set('port', process.env['PORT']);
|
||||
|
||||
|
||||
const logRequest: RequestHandler = (
|
||||
req: ExpressRequest,
|
||||
_res: ExpressResponse,
|
||||
@ -38,15 +37,19 @@ const logRequest: RequestHandler = (
|
||||
const method: string = req.method;
|
||||
const url: string = req.url;
|
||||
|
||||
const header_info: string = `Request ID: ${(req as OneUptimeRequest).id
|
||||
} -- POD NAME: ${process.env['POD_NAME'] || 'NONE'
|
||||
} -- METHOD: ${method} -- URL: ${url.toString()}`;
|
||||
const header_info: string = `Request ID: ${
|
||||
(req as OneUptimeRequest).id
|
||||
} -- POD NAME: ${
|
||||
process.env['POD_NAME'] || 'NONE'
|
||||
} -- METHOD: ${method} -- URL: ${url.toString()}`;
|
||||
|
||||
const body_info: string = `Request ID: ${(req as OneUptimeRequest).id
|
||||
} -- Request Body: ${req.body ? JSON.stringify(req.body, null, 2) : 'EMPTY'
|
||||
}`;
|
||||
const body_info: string = `Request ID: ${
|
||||
(req as OneUptimeRequest).id
|
||||
} -- Request Body: ${
|
||||
req.body ? JSON.stringify(req.body, null, 2) : 'EMPTY'
|
||||
}`;
|
||||
|
||||
logger.info(header_info + "\n " + body_info);
|
||||
logger.info(header_info + '\n ' + body_info);
|
||||
next();
|
||||
};
|
||||
|
||||
@ -82,13 +85,12 @@ app.use(ExpressUrlEncoded({ limit: '10mb' }));
|
||||
|
||||
app.use(logRequest);
|
||||
|
||||
|
||||
const init: Function = async (appName: string): Promise<ExpressApplication> => {
|
||||
await Express.launchApplication(appName);
|
||||
LocalCache.setString('app', 'name', appName);
|
||||
CommonAPI(appName);
|
||||
|
||||
// Attach Error Handler.
|
||||
// Attach Error Handler.
|
||||
app.use(
|
||||
(
|
||||
err: Error | Exception,
|
||||
@ -96,7 +98,6 @@ const init: Function = async (appName: string): Promise<ExpressApplication> => {
|
||||
res: ExpressResponse,
|
||||
next: NextFunction
|
||||
) => {
|
||||
|
||||
logger.error(err);
|
||||
|
||||
if (res.headersSent) {
|
||||
@ -108,7 +109,7 @@ const init: Function = async (appName: string): Promise<ExpressApplication> => {
|
||||
res.send({ error: (err as Exception).message });
|
||||
} else {
|
||||
res.status(500);
|
||||
res.send({ error: "Server Error" });
|
||||
res.send({ error: 'Server Error' });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -63,10 +63,18 @@ const Alert: FunctionComponent<ComponentProps> = (
|
||||
)}
|
||||
<span style={{ marginLeft: '-45px' }}>
|
||||
{AlertType.DANGER === type && (
|
||||
<Icon thick={ThickProp.LessThick} icon={IconProp.Error} size={SizeProp.Large} />
|
||||
<Icon
|
||||
thick={ThickProp.LessThick}
|
||||
icon={IconProp.Error}
|
||||
size={SizeProp.Large}
|
||||
/>
|
||||
)}
|
||||
{AlertType.WARNING === type && (
|
||||
<Icon thick={ThickProp.LessThick} icon={IconProp.Alert} size={SizeProp.Large} />
|
||||
<Icon
|
||||
thick={ThickProp.LessThick}
|
||||
icon={IconProp.Alert}
|
||||
size={SizeProp.Large}
|
||||
/>
|
||||
)}
|
||||
{AlertType.SUCCESS === type && (
|
||||
<Icon
|
||||
@ -76,7 +84,11 @@ const Alert: FunctionComponent<ComponentProps> = (
|
||||
/>
|
||||
)}
|
||||
{AlertType.INFO === type && (
|
||||
<Icon thick={ThickProp.LessThick} icon={IconProp.Info} size={SizeProp.Large} />
|
||||
<Icon
|
||||
thick={ThickProp.LessThick}
|
||||
icon={IconProp.Info}
|
||||
size={SizeProp.Large}
|
||||
/>
|
||||
)}
|
||||
|
||||
</span>
|
||||
|
@ -165,7 +165,15 @@ const Button: FunctionComponent<ComponentProps> = ({
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{isLoading && <div><Loader loaderType={LoaderType.Beats} color={White} size={10} /></div>}
|
||||
{isLoading && (
|
||||
<div>
|
||||
<Loader
|
||||
loaderType={LoaderType.Beats}
|
||||
color={White}
|
||||
size={10}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
@ -33,7 +33,7 @@ export interface ComponentProps<T extends Object> {
|
||||
onCancel?: (() => void) | null;
|
||||
cancelButtonText?: string | null;
|
||||
maxPrimaryButtonWidth?: boolean;
|
||||
error: string | null
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
function getFieldType(fieldType: FormFieldSchemaType): string {
|
||||
@ -52,8 +52,6 @@ function getFieldType(fieldType: FormFieldSchemaType): string {
|
||||
const BasicForm: Function = <T extends Object>(
|
||||
props: ComponentProps<T>
|
||||
): ReactElement => {
|
||||
|
||||
|
||||
const getFormField: Function = (
|
||||
field: DataField<T>,
|
||||
index: number,
|
||||
@ -70,7 +68,7 @@ const BasicForm: Function = <T extends Object>(
|
||||
if (props.showAsColumns && props.showAsColumns > 2) {
|
||||
throw new BadDataException(
|
||||
'showAsCOlumns should be <= 2. It is currently ' +
|
||||
props.showAsColumns
|
||||
props.showAsColumns
|
||||
);
|
||||
}
|
||||
|
||||
@ -102,9 +100,7 @@ const BasicForm: Function = <T extends Object>(
|
||||
placeholder={field.placeholder}
|
||||
type={fieldType}
|
||||
tabIndex={index + 1}
|
||||
name={
|
||||
fieldName
|
||||
}
|
||||
name={fieldName}
|
||||
disabled={isDisabled}
|
||||
/>
|
||||
<ErrorMessage
|
||||
@ -127,15 +123,17 @@ const BasicForm: Function = <T extends Object>(
|
||||
if (field.validation) {
|
||||
if (field.validation.minLength) {
|
||||
if (content.trim().length < field.validation?.minLength) {
|
||||
return `${field.title || name} cannot be less than ${field.validation.minLength
|
||||
} characters.`;
|
||||
return `${field.title || name} cannot be less than ${
|
||||
field.validation.minLength
|
||||
} characters.`;
|
||||
}
|
||||
}
|
||||
|
||||
if (field.validation.maxLength) {
|
||||
if (content.trim().length > field.validation?.maxLength) {
|
||||
return `${field.title || name} cannot be more than ${field.validation.maxLength
|
||||
} characters.`;
|
||||
return `${field.title || name} cannot be more than ${
|
||||
field.validation.maxLength
|
||||
} characters.`;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -162,7 +160,7 @@ const BasicForm: Function = <T extends Object>(
|
||||
field.validation?.toMatchField &&
|
||||
entity[field.validation?.toMatchField] &&
|
||||
(entity[field.validation?.toMatchField] as string).trim() !==
|
||||
content.trim()
|
||||
content.trim()
|
||||
) {
|
||||
return `${field.title} should match ${field.validation?.toMatchField}`;
|
||||
}
|
||||
@ -185,70 +183,69 @@ const BasicForm: Function = <T extends Object>(
|
||||
values: FormValues<T>
|
||||
) => void | object | Promise<FormikErrors<FormValues<T>>>) &
|
||||
Function = (values: FormValues<T>): FormikErrors<FormValues<T>> => {
|
||||
const errors: JSONObject = {};
|
||||
const entries: JSONObject = { ...values } as JSONObject;
|
||||
|
||||
const errors: JSONObject = {};
|
||||
const entries: JSONObject = { ...values } as JSONObject;
|
||||
for (const field of props.fields) {
|
||||
const name: string = field.overideFieldKey
|
||||
? field.overideFieldKey
|
||||
: (Object.keys(field.field)[0] as string);
|
||||
if (name in values) {
|
||||
const content: string | undefined = entries[name]?.toString();
|
||||
|
||||
for (const field of props.fields) {
|
||||
const name: string = field.overideFieldKey
|
||||
? field.overideFieldKey
|
||||
: (Object.keys(field.field)[0] as string);
|
||||
if (name in values) {
|
||||
const content: string | undefined = entries[name]?.toString();
|
||||
|
||||
if (content) {
|
||||
// Check Required fields.
|
||||
const resultRequired: string | null = validateRequired(
|
||||
content,
|
||||
field
|
||||
);
|
||||
if (resultRequired) {
|
||||
errors[name] = resultRequired;
|
||||
}
|
||||
|
||||
// Check for valid email data.
|
||||
const resultValidateData: string | null = validateData(
|
||||
content,
|
||||
field
|
||||
);
|
||||
if (resultValidateData) {
|
||||
errors[name] = resultValidateData;
|
||||
}
|
||||
|
||||
const resultMatch: string | null = validateMatchField(
|
||||
content,
|
||||
field,
|
||||
entries
|
||||
);
|
||||
|
||||
if (resultMatch) {
|
||||
errors[name] = resultMatch;
|
||||
}
|
||||
|
||||
// check for length of content
|
||||
const result: string | null = validateLength(
|
||||
content,
|
||||
field
|
||||
);
|
||||
if (result) {
|
||||
errors[name] = result;
|
||||
}
|
||||
if (content) {
|
||||
// Check Required fields.
|
||||
const resultRequired: string | null = validateRequired(
|
||||
content,
|
||||
field
|
||||
);
|
||||
if (resultRequired) {
|
||||
errors[name] = resultRequired;
|
||||
}
|
||||
|
||||
// Check for valid email data.
|
||||
const resultValidateData: string | null = validateData(
|
||||
content,
|
||||
field
|
||||
);
|
||||
if (resultValidateData) {
|
||||
errors[name] = resultValidateData;
|
||||
}
|
||||
|
||||
const resultMatch: string | null = validateMatchField(
|
||||
content,
|
||||
field,
|
||||
entries
|
||||
);
|
||||
|
||||
if (resultMatch) {
|
||||
errors[name] = resultMatch;
|
||||
}
|
||||
|
||||
// check for length of content
|
||||
const result: string | null = validateLength(
|
||||
content,
|
||||
field
|
||||
);
|
||||
if (result) {
|
||||
errors[name] = result;
|
||||
}
|
||||
} else if (field.required) {
|
||||
errors[name] = `${field.title || name} is required.`;
|
||||
}
|
||||
} else if (field.required) {
|
||||
errors[name] = `${field.title || name} is required.`;
|
||||
}
|
||||
}
|
||||
|
||||
let customValidateResult: JSONObject = {};
|
||||
let customValidateResult: JSONObject = {};
|
||||
|
||||
if (props.onValidate) {
|
||||
customValidateResult = props.onValidate(values);
|
||||
}
|
||||
if (props.onValidate) {
|
||||
customValidateResult = props.onValidate(values);
|
||||
}
|
||||
|
||||
return { ...errors, ...customValidateResult } as FormikErrors<
|
||||
FormValues<T>
|
||||
>;
|
||||
};
|
||||
return { ...errors, ...customValidateResult } as FormikErrors<
|
||||
FormValues<T>
|
||||
>;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="row">
|
||||
@ -266,7 +263,6 @@ const BasicForm: Function = <T extends Object>(
|
||||
setSubmitting(false);
|
||||
}}
|
||||
>
|
||||
|
||||
<Form autoComplete="off">
|
||||
<h1>{props.title}</h1>
|
||||
|
||||
@ -274,26 +270,37 @@ const BasicForm: Function = <T extends Object>(
|
||||
<p className="description">{props.description}</p>
|
||||
)}
|
||||
|
||||
{props.error && <Alert title={props.error} type={AlertType.DANGER} />}
|
||||
{props.error && (
|
||||
<Alert
|
||||
title={props.error}
|
||||
type={AlertType.DANGER}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className={`col-lg-12 flex`}>
|
||||
<div
|
||||
className={`col-lg-${12 / (props.showAsColumns || 1)
|
||||
} ${(props.showAsColumns || 1) > 1
|
||||
className={`col-lg-${
|
||||
12 / (props.showAsColumns || 1)
|
||||
} ${
|
||||
(props.showAsColumns || 1) > 1
|
||||
? 'pr-10'
|
||||
: ''
|
||||
}`}
|
||||
}`}
|
||||
>
|
||||
{props.fields &&
|
||||
props.fields.map(
|
||||
(field: DataField<T>, i: number) => {
|
||||
if (
|
||||
i %
|
||||
(props.showAsColumns ||
|
||||
1) ===
|
||||
(props.showAsColumns ||
|
||||
1) ===
|
||||
0
|
||||
) {
|
||||
return getFormField(field, i, props.isLoading);
|
||||
return getFormField(
|
||||
field,
|
||||
i,
|
||||
props.isLoading
|
||||
);
|
||||
}
|
||||
return <div key={i}></div>;
|
||||
}
|
||||
@ -301,11 +308,13 @@ const BasicForm: Function = <T extends Object>(
|
||||
</div>
|
||||
{(props.showAsColumns || 1) > 1 && (
|
||||
<div
|
||||
className={`col-lg-${12 / (props.showAsColumns || 1)
|
||||
} ${(props.showAsColumns || 1) > 1
|
||||
className={`col-lg-${
|
||||
12 / (props.showAsColumns || 1)
|
||||
} ${
|
||||
(props.showAsColumns || 1) > 1
|
||||
? 'pl-10'
|
||||
: ''
|
||||
}`}
|
||||
}`}
|
||||
>
|
||||
{props.fields &&
|
||||
props.fields.map(
|
||||
@ -315,8 +324,8 @@ const BasicForm: Function = <T extends Object>(
|
||||
) => {
|
||||
if (
|
||||
i %
|
||||
(props.showAsColumns ||
|
||||
1) !==
|
||||
(props.showAsColumns ||
|
||||
1) !==
|
||||
0
|
||||
) {
|
||||
return getFormField(
|
||||
@ -349,7 +358,6 @@ const BasicForm: Function = <T extends Object>(
|
||||
title={props.submitButtonText || 'Submit'}
|
||||
type={ButtonTypes.Submit}
|
||||
id={`${props.id}-submit-button`}
|
||||
|
||||
isLoading={props.isLoading || false}
|
||||
buttonStyle={ButtonStyleType.PRIMARY}
|
||||
style={{
|
||||
|
@ -22,7 +22,7 @@ export interface ComponentProps<TBaseModel extends BaseModel> {
|
||||
onCancel?: () => void;
|
||||
cancelButtonText?: string;
|
||||
maxPrimaryButtonWidth?: boolean;
|
||||
error: string | null
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
const BasicModelForm: Function = <TBaseModel extends BaseModel>(
|
||||
@ -37,7 +37,8 @@ const BasicModelForm: Function = <TBaseModel extends BaseModel>(
|
||||
if (
|
||||
props.model.getDisplayColumnTitleAs(
|
||||
Object.keys(field.field)[0] as string
|
||||
) && !field.title
|
||||
) &&
|
||||
!field.title
|
||||
) {
|
||||
field.title = props.model.getDisplayColumnTitleAs(
|
||||
Object.keys(field.field)[0] as string
|
||||
@ -47,7 +48,8 @@ const BasicModelForm: Function = <TBaseModel extends BaseModel>(
|
||||
if (
|
||||
props.model.getDisplayColumnDescriptionAs(
|
||||
Object.keys(field.field)[0] as string
|
||||
) && !field.description
|
||||
) &&
|
||||
!field.description
|
||||
) {
|
||||
field.description = props.model.getDisplayColumnDescriptionAs(
|
||||
Object.keys(field.field)[0] as string
|
||||
|
@ -15,7 +15,7 @@ import { DASHBOARD_API_URL } from '../../Config';
|
||||
|
||||
export enum FormType {
|
||||
Create,
|
||||
Update
|
||||
Update,
|
||||
}
|
||||
|
||||
export interface ComponentProps<TBaseModel extends BaseModel> {
|
||||
@ -31,11 +31,13 @@ export interface ComponentProps<TBaseModel extends BaseModel> {
|
||||
showAsColumns?: number;
|
||||
footer: ReactElement;
|
||||
onCancel?: () => void;
|
||||
onSuccess?: (data: TBaseModel | JSONObjectOrArray | Array<TBaseModel>) => void;
|
||||
onSuccess?: (
|
||||
data: TBaseModel | JSONObjectOrArray | Array<TBaseModel>
|
||||
) => void;
|
||||
cancelButtonText?: string;
|
||||
maxPrimaryButtonWidth?: boolean;
|
||||
apiUrl?: URL,
|
||||
formType: FormType
|
||||
apiUrl?: URL;
|
||||
formType: FormType;
|
||||
}
|
||||
|
||||
const CreateModelForm: Function = <TBaseModel extends BaseModel>(
|
||||
@ -44,28 +46,34 @@ const CreateModelForm: Function = <TBaseModel extends BaseModel>(
|
||||
const [isLoading, setLoading] = useState<boolean>(false);
|
||||
const [error, setError] = useState<string>('');
|
||||
|
||||
const onSubmit = async (values: any) => {
|
||||
const onSubmit: Function = async (values: JSONObject): Promise<void> => {
|
||||
// Ping an API here.
|
||||
setError('');
|
||||
setLoading(true);
|
||||
let apiUrl = props.apiUrl;
|
||||
let apiUrl: URL | null = props.apiUrl || null;
|
||||
|
||||
if (!apiUrl) {
|
||||
const apiPath: Route | null = props.model.getCrudApiPath();
|
||||
if (!apiPath) {
|
||||
throw new BadDataException("This model does not support CRUD operations.");
|
||||
throw new BadDataException(
|
||||
'This model does not support CRUD operations.'
|
||||
);
|
||||
}
|
||||
|
||||
apiUrl = DASHBOARD_API_URL.addRoute(apiPath);
|
||||
}
|
||||
|
||||
const result: HTTPResponse<JSONObject | JSONArray | TBaseModel | Array<TBaseModel>> =
|
||||
await API.fetch<
|
||||
JSONObject |
|
||||
JSONArray |
|
||||
TBaseModel |
|
||||
Array<TBaseModel
|
||||
>>(props.formType === FormType.Create ? HTTPMethod.POST : HTTPMethod.PUT, apiUrl, values);
|
||||
const result: HTTPResponse<
|
||||
JSONObject | JSONArray | TBaseModel | Array<TBaseModel>
|
||||
> = await API.fetch<
|
||||
JSONObject | JSONArray | TBaseModel | Array<TBaseModel>
|
||||
>(
|
||||
props.formType === FormType.Create
|
||||
? HTTPMethod.POST
|
||||
: HTTPMethod.PUT,
|
||||
apiUrl,
|
||||
values
|
||||
);
|
||||
|
||||
setLoading(false);
|
||||
|
||||
@ -74,7 +82,7 @@ const CreateModelForm: Function = <TBaseModel extends BaseModel>(
|
||||
props.onSuccess(result.data);
|
||||
}
|
||||
} else {
|
||||
setError((result.data as JSONObject)["error"] as string)
|
||||
setError((result.data as JSONObject)['error'] as string);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -5,7 +5,7 @@ import Color from 'Common/Types/Color';
|
||||
|
||||
export enum LoaderType {
|
||||
Bar,
|
||||
Beats
|
||||
Beats,
|
||||
}
|
||||
|
||||
export interface ComponentProps {
|
||||
@ -19,7 +19,6 @@ const Loader: FunctionComponent<ComponentProps> = ({
|
||||
color = new Color('#000000'),
|
||||
loaderType = LoaderType.Bar,
|
||||
}: ComponentProps) => {
|
||||
|
||||
if (loaderType === LoaderType.Bar) {
|
||||
return <BarLoader height={4} width={size} color={color.toString()} />;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class BaseAPI extends API {
|
||||
super(protocol, hostname, route);
|
||||
}
|
||||
|
||||
public static fromURL(url: URL) {
|
||||
public static fromURL(url: URL): BaseAPI {
|
||||
return new BaseAPI(url.protocol, url.hostname, url.route);
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ class BaseAPI extends API {
|
||||
cookies.remove('admin-data', { path: '/' });
|
||||
cookies.remove('data', { path: '/' });
|
||||
User.clear();
|
||||
Navigation.navigate(new Route("/accounts/login"));
|
||||
Navigation.navigate(new Route('/accounts/login'));
|
||||
}
|
||||
|
||||
return error;
|
||||
|
@ -148,7 +148,10 @@ router.post(
|
||||
OneUptimeDate.getSecondsInDays(new PositiveNumber(30))
|
||||
);
|
||||
|
||||
return Response.sendItemResponse(req, res, { token: token, user: savedUser.toJSON() });
|
||||
return Response.sendItemResponse(req, res, {
|
||||
token: token,
|
||||
user: savedUser.toJSON(),
|
||||
});
|
||||
}
|
||||
|
||||
throw new BadRequestException('Failed to create a user');
|
||||
|
Loading…
Reference in New Issue
Block a user