diff --git a/Accounts/src/Pages/Register.tsx b/Accounts/src/Pages/Register.tsx index 2168ec2b7f..d6f9f49f91 100644 --- a/Accounts/src/Pages/Register.tsx +++ b/Accounts/src/Pages/Register.tsx @@ -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 + ); }} /> diff --git a/Accounts/src/Utils/ApiPaths.ts b/Accounts/src/Utils/ApiPaths.ts index d57d414a17..11d5fcb251 100644 --- a/Accounts/src/Utils/ApiPaths.ts +++ b/Accounts/src/Utils/ApiPaths.ts @@ -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")); \ No newline at end of file +export const SIGNUP_API_URL: URL = IDENTITY_URL.addRoute(new Route('/signup')); diff --git a/Common/Models/BaseModel.ts b/Common/Models/BaseModel.ts index 391b15ebda..d2eeda7c26 100644 --- a/Common/Models/BaseModel.ts +++ b/Common/Models/BaseModel.ts @@ -440,7 +440,7 @@ export default class BaseModel extends BaseEntity { } public getPublicCreateableColumns(type: { - new(): T; + new (): T; }): Columns { const obj: T = new type(); const accessControl: Dictionary = @@ -655,18 +655,34 @@ export default class BaseModel extends BaseEntity { private static _fromJSON( 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( json: JSONObject | JSONArray, - type: { new(): T } + type: { new (): T } ): T | Array { if (Array.isArray(json)) { const arr: Array = []; @@ -696,7 +712,7 @@ export default class BaseModel extends BaseEntity { private static keepColumns( 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( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -741,7 +757,7 @@ export default class BaseModel extends BaseEntity { public static asPublicUpdateable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -758,7 +774,7 @@ export default class BaseModel extends BaseEntity { public static asPublicReadableItem( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -779,7 +795,7 @@ export default class BaseModel extends BaseEntity { public static asPublicReadableList( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -800,7 +816,7 @@ export default class BaseModel extends BaseEntity { public static asPublicDeleteable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -817,7 +833,7 @@ export default class BaseModel extends BaseEntity { public static asOwnerCreateable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -834,7 +850,7 @@ export default class BaseModel extends BaseEntity { public static asOwnerUpdateable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -851,7 +867,7 @@ export default class BaseModel extends BaseEntity { public static asOwnerReadableItem( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -872,7 +888,7 @@ export default class BaseModel extends BaseEntity { public static asOwnerReadableList( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -893,7 +909,7 @@ export default class BaseModel extends BaseEntity { public static asOwnerDeleteable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -910,7 +926,7 @@ export default class BaseModel extends BaseEntity { public static asUserCreateable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -927,7 +943,7 @@ export default class BaseModel extends BaseEntity { public static asUserUpdateable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -944,7 +960,7 @@ export default class BaseModel extends BaseEntity { public static asUserReadableItem( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -965,7 +981,7 @@ export default class BaseModel extends BaseEntity { public static asUserReadableList( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -986,7 +1002,7 @@ export default class BaseModel extends BaseEntity { public static asUserDeleteable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1003,7 +1019,7 @@ export default class BaseModel extends BaseEntity { public static asViewerCreateable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1020,7 +1036,7 @@ export default class BaseModel extends BaseEntity { public static asViewerUpdateable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1037,7 +1053,7 @@ export default class BaseModel extends BaseEntity { public static asViewerReadableItem( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1058,7 +1074,7 @@ export default class BaseModel extends BaseEntity { public static asViewerReadableList( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1079,7 +1095,7 @@ export default class BaseModel extends BaseEntity { public static asViewerDeleteable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1096,7 +1112,7 @@ export default class BaseModel extends BaseEntity { public static asMemberCreateable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1113,7 +1129,7 @@ export default class BaseModel extends BaseEntity { public static asMemberUpdateable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1130,7 +1146,7 @@ export default class BaseModel extends BaseEntity { public static asMemberReadableItem( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1151,7 +1167,7 @@ export default class BaseModel extends BaseEntity { public static asMemberReadableList( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1172,7 +1188,7 @@ export default class BaseModel extends BaseEntity { public static asMemberDeleteable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1189,7 +1205,7 @@ export default class BaseModel extends BaseEntity { public static asAdminCreateable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1206,7 +1222,7 @@ export default class BaseModel extends BaseEntity { public static asAdminUpdateable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1223,7 +1239,7 @@ export default class BaseModel extends BaseEntity { public static asAdminReadableList( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1244,7 +1260,7 @@ export default class BaseModel extends BaseEntity { public static asAdminReadableItem( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(data, type); @@ -1265,7 +1281,7 @@ export default class BaseModel extends BaseEntity { public static asAdminDeleteable( data: JSONObject | T, - type: { new(): T } + type: { new (): T } ): T { if (!(data instanceof BaseModel)) { data = this._fromJSON(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]; diff --git a/Common/Models/EmailVerificationToken.ts b/Common/Models/EmailVerificationToken.ts index 717da64b72..f58df13eac 100755 --- a/Common/Models/EmailVerificationToken.ts +++ b/Common/Models/EmailVerificationToken.ts @@ -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, diff --git a/Common/Models/Probe.ts b/Common/Models/Probe.ts index cc387755e5..9622fcbe75 100755 --- a/Common/Models/Probe.ts +++ b/Common/Models/Probe.ts @@ -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, diff --git a/Common/Models/Project.ts b/Common/Models/Project.ts index c58dc8ea87..7d5522e1a2 100644 --- a/Common/Models/Project.ts +++ b/Common/Models/Project.ts @@ -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, diff --git a/Common/Models/User.ts b/Common/Models/User.ts index 6778ec5bc2..4e49117761 100644 --- a/Common/Models/User.ts +++ b/Common/Models/User.ts @@ -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 = 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, diff --git a/Common/Types/API/HTTPResponse.ts b/Common/Types/API/HTTPResponse.ts index 4922bc002d..9fead5a85c 100644 --- a/Common/Types/API/HTTPResponse.ts +++ b/Common/Types/API/HTTPResponse.ts @@ -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 { diff --git a/Common/Types/API/URL.ts b/Common/Types/API/URL.ts index 8a191662d0..036d28faea 100644 --- a/Common/Types/API/URL.ts +++ b/Common/Types/API/URL.ts @@ -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); diff --git a/Common/Types/Database/CrudApiEndpoint.ts b/Common/Types/Database/CrudApiEndpoint.ts index e8191aa7fb..ae456809b8 100644 --- a/Common/Types/Database/CrudApiEndpoint.ts +++ b/Common/Types/Database/CrudApiEndpoint.ts @@ -1,4 +1,4 @@ -import Route from "../API/Route"; +import Route from '../API/Route'; export default (apiPath: Route) => { return (ctr: Function) => { diff --git a/Common/Types/Database/TableColumn.ts b/Common/Types/Database/TableColumn.ts index 8ba35b753f..eb50d4510a 100644 --- a/Common/Types/Database/TableColumn.ts +++ b/Common/Types/Database/TableColumn.ts @@ -16,7 +16,7 @@ export interface TableColumnMetadata { hashed?: boolean; encrypted?: boolean; manyToOneRelationColumn?: string; - type: TableColumnType + type: TableColumnType; } export default (props: TableColumnMetadata): ReflectionMetadataType => { diff --git a/Common/Utils/API.ts b/Common/Utils/API.ts index 15ea218fe6..9ee6cb74ac 100644 --- a/Common/Utils/API.ts +++ b/Common/Utils/API.ts @@ -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); diff --git a/CommonServer/Utils/Logger.ts b/CommonServer/Utils/Logger.ts index 4a14be4169..ce9e15fc9f 100644 --- a/CommonServer/Utils/Logger.ts +++ b/CommonServer/Utils/Logger.ts @@ -7,7 +7,7 @@ const logger: Logger = createLogger({ errors({ stack: true }), // <-- use errors format timestamp(), prettyPrint() - ), + ), transports: [new transports.Console()], }); diff --git a/CommonServer/Utils/Response.ts b/CommonServer/Utils/Response.ts index 56cbf86917..b42a678ebe 100644 --- a/CommonServer/Utils/Response.ts +++ b/CommonServer/Utils/Response.ts @@ -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, - 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') { diff --git a/CommonServer/Utils/StartServer.ts b/CommonServer/Utils/StartServer.ts index 680bee53cc..5865f09816 100644 --- a/CommonServer/Utils/StartServer.ts +++ b/CommonServer/Utils/StartServer.ts @@ -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 => { 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 => { res: ExpressResponse, next: NextFunction ) => { - logger.error(err); if (res.headersSent) { @@ -108,7 +109,7 @@ const init: Function = async (appName: string): Promise => { res.send({ error: (err as Exception).message }); } else { res.status(500); - res.send({ error: "Server Error" }); + res.send({ error: 'Server Error' }); } } ); diff --git a/CommonUI/src/Components/Alerts/Alert.tsx b/CommonUI/src/Components/Alerts/Alert.tsx index ddb18f1a91..1e9f82454e 100644 --- a/CommonUI/src/Components/Alerts/Alert.tsx +++ b/CommonUI/src/Components/Alerts/Alert.tsx @@ -63,10 +63,18 @@ const Alert: FunctionComponent = ( )} {AlertType.DANGER === type && ( - + )} {AlertType.WARNING === type && ( - + )} {AlertType.SUCCESS === type && ( = ( /> )} {AlertType.INFO === type && ( - + )}    diff --git a/CommonUI/src/Components/Button/Button.tsx b/CommonUI/src/Components/Button/Button.tsx index 62a1a8ed92..44d497fca9 100644 --- a/CommonUI/src/Components/Button/Button.tsx +++ b/CommonUI/src/Components/Button/Button.tsx @@ -165,7 +165,15 @@ const Button: FunctionComponent = ({ )} - {isLoading &&
} + {isLoading && ( +
+ +
+ )} ); }; diff --git a/CommonUI/src/Components/Forms/BasicForm.tsx b/CommonUI/src/Components/Forms/BasicForm.tsx index bd5f07701d..c5506297ad 100644 --- a/CommonUI/src/Components/Forms/BasicForm.tsx +++ b/CommonUI/src/Components/Forms/BasicForm.tsx @@ -33,7 +33,7 @@ export interface ComponentProps { 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 = ( props: ComponentProps ): ReactElement => { - - const getFormField: Function = ( field: DataField, index: number, @@ -70,7 +68,7 @@ const BasicForm: Function = ( 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 = ( placeholder={field.placeholder} type={fieldType} tabIndex={index + 1} - name={ - fieldName - } + name={fieldName} disabled={isDisabled} /> ( 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 = ( 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 = ( values: FormValues ) => void | object | Promise>>) & Function = (values: FormValues): FormikErrors> => { + 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 - >; - }; + return { ...errors, ...customValidateResult } as FormikErrors< + FormValues + >; + }; return (
@@ -266,7 +263,6 @@ const BasicForm: Function = ( setSubmitting(false); }} > -

{props.title}

@@ -274,26 +270,37 @@ const BasicForm: Function = (

{props.description}

)} - {props.error && } + {props.error && ( + + )}
1 + className={`col-lg-${ + 12 / (props.showAsColumns || 1) + } ${ + (props.showAsColumns || 1) > 1 ? 'pr-10' : '' - }`} + }`} > {props.fields && props.fields.map( (field: DataField, i: number) => { if ( i % - (props.showAsColumns || - 1) === + (props.showAsColumns || + 1) === 0 ) { - return getFormField(field, i, props.isLoading); + return getFormField( + field, + i, + props.isLoading + ); } return
; } @@ -301,11 +308,13 @@ const BasicForm: Function = (
{(props.showAsColumns || 1) > 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 = ( ) => { if ( i % - (props.showAsColumns || - 1) !== + (props.showAsColumns || + 1) !== 0 ) { return getFormField( @@ -349,7 +358,6 @@ const BasicForm: Function = ( title={props.submitButtonText || 'Submit'} type={ButtonTypes.Submit} id={`${props.id}-submit-button`} - isLoading={props.isLoading || false} buttonStyle={ButtonStyleType.PRIMARY} style={{ diff --git a/CommonUI/src/Components/Forms/BasicModelForm.tsx b/CommonUI/src/Components/Forms/BasicModelForm.tsx index 1b23d8d577..96a835fe65 100644 --- a/CommonUI/src/Components/Forms/BasicModelForm.tsx +++ b/CommonUI/src/Components/Forms/BasicModelForm.tsx @@ -22,7 +22,7 @@ export interface ComponentProps { onCancel?: () => void; cancelButtonText?: string; maxPrimaryButtonWidth?: boolean; - error: string | null + error: string | null; } const BasicModelForm: Function = ( @@ -37,7 +37,8 @@ const BasicModelForm: Function = ( 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 = ( 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 diff --git a/CommonUI/src/Components/Forms/ModelForm.tsx b/CommonUI/src/Components/Forms/ModelForm.tsx index 55ffd9312b..186a6daea3 100644 --- a/CommonUI/src/Components/Forms/ModelForm.tsx +++ b/CommonUI/src/Components/Forms/ModelForm.tsx @@ -15,7 +15,7 @@ import { DASHBOARD_API_URL } from '../../Config'; export enum FormType { Create, - Update + Update, } export interface ComponentProps { @@ -31,11 +31,13 @@ export interface ComponentProps { showAsColumns?: number; footer: ReactElement; onCancel?: () => void; - onSuccess?: (data: TBaseModel | JSONObjectOrArray | Array) => void; + onSuccess?: ( + data: TBaseModel | JSONObjectOrArray | Array + ) => void; cancelButtonText?: string; maxPrimaryButtonWidth?: boolean; - apiUrl?: URL, - formType: FormType + apiUrl?: URL; + formType: FormType; } const CreateModelForm: Function = ( @@ -44,28 +46,34 @@ const CreateModelForm: Function = ( const [isLoading, setLoading] = useState(false); const [error, setError] = useState(''); - const onSubmit = async (values: any) => { + const onSubmit: Function = async (values: JSONObject): Promise => { // 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> = - await API.fetch< - JSONObject | - JSONArray | - TBaseModel | - Array>(props.formType === FormType.Create ? HTTPMethod.POST : HTTPMethod.PUT, apiUrl, values); + const result: HTTPResponse< + JSONObject | JSONArray | TBaseModel | Array + > = await API.fetch< + JSONObject | JSONArray | TBaseModel | Array + >( + props.formType === FormType.Create + ? HTTPMethod.POST + : HTTPMethod.PUT, + apiUrl, + values + ); setLoading(false); @@ -74,7 +82,7 @@ const CreateModelForm: Function = ( props.onSuccess(result.data); } } else { - setError((result.data as JSONObject)["error"] as string) + setError((result.data as JSONObject)['error'] as string); } }; diff --git a/CommonUI/src/Components/Loader/Loader.tsx b/CommonUI/src/Components/Loader/Loader.tsx index 3d380f2136..73f426db83 100644 --- a/CommonUI/src/Components/Loader/Loader.tsx +++ b/CommonUI/src/Components/Loader/Loader.tsx @@ -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 = ({ color = new Color('#000000'), loaderType = LoaderType.Bar, }: ComponentProps) => { - if (loaderType === LoaderType.Bar) { return ; } diff --git a/CommonUI/src/Utils/API/API.ts b/CommonUI/src/Utils/API/API.ts index 4ae53e4308..8fa24c12f0 100644 --- a/CommonUI/src/Utils/API/API.ts +++ b/CommonUI/src/Utils/API/API.ts @@ -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; diff --git a/Identity/API/AuthenticationAPI.ts b/Identity/API/AuthenticationAPI.ts index 7b3a92cdf5..9320ee06e6 100644 --- a/Identity/API/AuthenticationAPI.ts +++ b/Identity/API/AuthenticationAPI.ts @@ -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');