chore: suit eslint rules
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { URLSearchParams } from 'url';
|
||||
import DiscordApi from 'discord.js';
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import App from '../../models/app';
|
||||
import Field from '../../types/field';
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { google, google as GoogleApi } from 'googleapis';
|
||||
import { google as GoogleApi } from 'googleapis';
|
||||
import App from '../../models/app';
|
||||
import Field from '../../types/field';
|
||||
|
||||
|
@@ -16,11 +16,11 @@ export default class Authentication {
|
||||
this.appData = App.findOneByKey('github');
|
||||
}
|
||||
|
||||
get oauthRedirectUrl() {
|
||||
get oauthRedirectUrl(): string {
|
||||
return this.appData.fields.find((field: Field) => field.key == 'oAuthRedirectUrl').value;
|
||||
}
|
||||
|
||||
async createAuthData() {
|
||||
async createAuthData(): { url: string } {
|
||||
const { url } = await getWebFlowAuthorizationUrl({
|
||||
clientType: "oauth-app",
|
||||
clientId: this.connectionData.consumerKey,
|
||||
@@ -33,8 +33,8 @@ export default class Authentication {
|
||||
};
|
||||
}
|
||||
|
||||
async verifyCredentials() {
|
||||
const { data, authentication } = await exchangeWebFlowCode({
|
||||
async verifyCredentials(): any {
|
||||
const { data } = await exchangeWebFlowCode({
|
||||
clientType: "oauth-app",
|
||||
clientId: this.connectionData.consumerKey,
|
||||
clientSecret: this.connectionData.consumerSecret,
|
||||
@@ -65,7 +65,7 @@ export default class Authentication {
|
||||
});
|
||||
}
|
||||
|
||||
async isStillVerified() {
|
||||
async isStillVerified(): boolean {
|
||||
try {
|
||||
await this.getTokenInfo();
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import TwitchApi, { ApiVersions } from 'twitch-js';
|
||||
import TwitchApi from 'twitch-js';
|
||||
import fetchUtil from 'twitch-js/lib/utils/fetch';
|
||||
import App from '../../models/app';
|
||||
import Field from '../../types/field';
|
||||
|
@@ -1,20 +1,18 @@
|
||||
import { GraphQLInt, GraphQLNonNull } from 'graphql';
|
||||
import App from '../../models/app';
|
||||
import Connection from '../../models/connection';
|
||||
import Step from '../../models/step';
|
||||
import stepType from '../types/step';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
|
||||
type Params = {
|
||||
id: number,
|
||||
data: object
|
||||
data: Record<string, unknown>
|
||||
}
|
||||
const executeStepResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
let step = await Step.query().findOne({
|
||||
const executeStepResolver = async (params: Params): Promise<any> => {
|
||||
const step = await Step.query().findOne({
|
||||
id: params.id
|
||||
}).throwIfNotFound();
|
||||
|
||||
let connection = await Connection.query().findOne({
|
||||
const connection = await Connection.query().findOne({
|
||||
id: step.connectionId
|
||||
}).throwIfNotFound();
|
||||
|
||||
@@ -30,7 +28,7 @@ const executeStep = {
|
||||
args: {
|
||||
id: { type: GraphQLNonNull(GraphQLInt) }
|
||||
},
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => executeStepResolver(params, req)
|
||||
resolve: (_: any, params: Params) => executeStepResolver(params)
|
||||
};
|
||||
|
||||
export default executeStep;
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import { GraphQLInt, GraphQLString, GraphQLNonNull } from 'graphql';
|
||||
import Flow from '../../models/flow';
|
||||
import Step from '../../models/step';
|
||||
import flowType from '../types/flow';
|
||||
import stepType from '../types/step';
|
||||
import availableAppsEnumType from '../types/available-apps-enum-type';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { GraphQLList, GraphQLString } from 'graphql';
|
||||
import { GraphQLList } from 'graphql';
|
||||
import Flow from '../../models/flow';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
import flowType from '../types/flow';
|
||||
|
||||
const getFlowsResolver = async (req: RequestWithCurrentUser) => {
|
||||
const getFlowsResolver = async (req: RequestWithCurrentUser): Promise<any[]> => {
|
||||
const flows = await Flow.query()
|
||||
.withGraphJoined('[steps.[connection]]')
|
||||
.where({'flows.user_id': req.currentUser.id});
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { GraphQLString, GraphQLNonNull, GraphQLBoolean } from 'graphql';
|
||||
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||
import Connection from '../../models/connection';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
import connectionType from '../types/connection'
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLInt, GraphQLBoolean } from 'graphql';
|
||||
import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLBoolean } from 'graphql';
|
||||
|
||||
const actionType = new GraphQLObjectType({
|
||||
name: 'Action',
|
||||
@@ -6,13 +6,13 @@ const actionType = new GraphQLObjectType({
|
||||
name: { type: GraphQLString },
|
||||
key: { type: GraphQLString },
|
||||
description: { type: GraphQLString },
|
||||
subSteps: {
|
||||
subSteps: {
|
||||
type: GraphQLList(
|
||||
new GraphQLObjectType({
|
||||
name: 'ActionSubStep',
|
||||
fields: {
|
||||
name: { type: GraphQLString },
|
||||
arguments: {
|
||||
arguments: {
|
||||
type: GraphQLList(
|
||||
new GraphQLObjectType({
|
||||
name: 'ActionSubStepArgument',
|
||||
|
@@ -8,6 +8,7 @@ import actionType from './action';
|
||||
const appType = new GraphQLObjectType({
|
||||
name: 'App',
|
||||
fields: () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const connectionType = require('./connection').default;
|
||||
|
||||
return {
|
||||
|
@@ -4,6 +4,7 @@ import connectionDataType from './connection-data';
|
||||
const connectionType = new GraphQLObjectType({
|
||||
name: 'Connection',
|
||||
fields: () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const appType = require('./app').default;
|
||||
|
||||
return {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { GraphQLObjectType, GraphQLString, GraphQLNonNull, GraphQLEnumType, GraphQLInt } from 'graphql';
|
||||
import { GraphQLObjectType, GraphQLString, GraphQLEnumType, GraphQLInt } from 'graphql';
|
||||
import ConnectionType from './connection';
|
||||
|
||||
const stepType = new GraphQLObjectType({
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLInt, GraphQLBoolean } from 'graphql';
|
||||
import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLBoolean } from 'graphql';
|
||||
|
||||
const triggerType = new GraphQLObjectType({
|
||||
name: 'Trigger',
|
||||
@@ -6,13 +6,13 @@ const triggerType = new GraphQLObjectType({
|
||||
name: { type: GraphQLString },
|
||||
key: { type: GraphQLString },
|
||||
description: { type: GraphQLString },
|
||||
subSteps: {
|
||||
subSteps: {
|
||||
type: GraphQLList(
|
||||
new GraphQLObjectType({
|
||||
name: 'TriggerSubStep',
|
||||
fields: {
|
||||
name: { type: GraphQLString },
|
||||
arguments: {
|
||||
arguments: {
|
||||
type: GraphQLList(
|
||||
new GraphQLObjectType({
|
||||
name: 'TriggerSubStepArgument',
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { Response, NextFunction } from 'express';
|
||||
import User from '../models/user';
|
||||
import RequestWithCurrentUser from '../types/express/request-with-current-user';
|
||||
|
||||
const authentication = async (req: RequestWithCurrentUser, _res: Response, next: NextFunction) => {
|
||||
const authentication = async (req: RequestWithCurrentUser, _res: Response, next: NextFunction): Promise<void> => {
|
||||
// We set authentication to use the sample user we created temporarily.
|
||||
req.currentUser = await User.query().findOne({
|
||||
email: 'user@automatisch.com'
|
||||
|
@@ -1,7 +1,11 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { Request, Response } from 'express';
|
||||
import logger from './logger';
|
||||
|
||||
const errorHandler = (err: any, req: Request, res: Response, _next: NextFunction) => {
|
||||
type Error = {
|
||||
message: string;
|
||||
}
|
||||
|
||||
const errorHandler = (err: Error, req: Request, res: Response): void => {
|
||||
if(err.message === 'Not Found') {
|
||||
res.status(404).end()
|
||||
} else {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { Model, snakeCaseMappers } from 'objection';
|
||||
import type { Constructor, TransactionOrKnex, QueryBuilderType, QueryContext, ModelOptions, ColumnNameMappers } from 'objection';
|
||||
import type { QueryContext, ModelOptions, ColumnNameMappers } from 'objection';
|
||||
|
||||
class Base extends Model {
|
||||
createdAt!: string;
|
||||
@@ -9,14 +9,14 @@ class Base extends Model {
|
||||
return snakeCaseMappers();
|
||||
}
|
||||
|
||||
async $beforeInsert(queryContext: QueryContext) {
|
||||
async $beforeInsert(queryContext: QueryContext): Promise<void> {
|
||||
await super.$beforeInsert(queryContext);
|
||||
|
||||
this.createdAt = new Date().toISOString();
|
||||
this.updatedAt = new Date().toISOString();
|
||||
}
|
||||
|
||||
async $beforeUpdate(opt: ModelOptions, queryContext: QueryContext) {
|
||||
async $beforeUpdate(opt: ModelOptions, queryContext: QueryContext): Promise<void> {
|
||||
await super.$beforeUpdate(opt, queryContext);
|
||||
|
||||
this.updatedAt = new Date().toISOString();
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { QueryContext, ModelOptions } from 'objection';
|
||||
import type { RelationMappings } from 'objection';
|
||||
import { AES, enc } from 'crypto-js';
|
||||
import Base from './base'
|
||||
import User from './user'
|
||||
@@ -27,7 +28,7 @@ class Connection extends Base {
|
||||
}
|
||||
}
|
||||
|
||||
static relationMappings = () => ({
|
||||
static relationMappings = (): RelationMappings => ({
|
||||
user: {
|
||||
relation: Base.BelongsToOneRelation,
|
||||
modelClass: User,
|
||||
@@ -38,33 +39,33 @@ class Connection extends Base {
|
||||
}
|
||||
})
|
||||
|
||||
encryptData() {
|
||||
encryptData(): void {
|
||||
if(!this.eligibleForEncryption()) return;
|
||||
this.data = AES.encrypt(JSON.stringify(this.data), appConfig.encryptionKey).toString();
|
||||
}
|
||||
|
||||
decryptData() {
|
||||
decryptData(): void {
|
||||
if(!this.eligibleForEncryption()) return;
|
||||
this.data = JSON.parse(AES.decrypt(this.data, appConfig.encryptionKey).toString(enc.Utf8));
|
||||
}
|
||||
|
||||
eligibleForEncryption() {
|
||||
eligibleForEncryption(): boolean {
|
||||
return this.data ? true : false
|
||||
}
|
||||
|
||||
// TODO: Make another abstraction like beforeSave instead of using
|
||||
// beforeInsert and beforeUpdate separately for the same operation.
|
||||
async $beforeInsert(queryContext: QueryContext) {
|
||||
async $beforeInsert(queryContext: QueryContext): Promise<void> {
|
||||
await super.$beforeInsert(queryContext);
|
||||
this.encryptData();
|
||||
}
|
||||
|
||||
async $beforeUpdate(opt: ModelOptions, queryContext: QueryContext) {
|
||||
async $beforeUpdate(opt: ModelOptions, queryContext: QueryContext): Promise<void> {
|
||||
await super.$beforeUpdate(opt, queryContext);
|
||||
this.encryptData();
|
||||
}
|
||||
|
||||
async $afterFind(queryContext: QueryContext) {
|
||||
async $afterFind(): Promise<void> {
|
||||
this.decryptData();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user