Skip to content

Commit 7e7b5c0

Browse files
committed
Lint
1 parent d996b9a commit 7e7b5c0

16 files changed

+124
-104
lines changed

src/directives/defaultValue.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {defaultFieldResolver, GraphQLSchema} from "graphql";
2-
import {mapSchema, MapperKind, getDirective} from '@graphql-tools/utils'
3-
import {UnknownGraphQLResolverResult} from "../types/graphql";
1+
import { defaultFieldResolver, GraphQLSchema } from 'graphql';
2+
import { mapSchema, MapperKind, getDirective } from '@graphql-tools/utils';
3+
import { UnknownGraphQLResolverResult } from '../types/graphql';
44

55
export default function defaultValueDirective(directiveName = 'default') {
66
return {
7-
defaultValueDirectiveTypeDefs:`
7+
defaultValueDirectiveTypeDefs: `
88
"""
99
Directive for setting field default value
1010
"""
@@ -20,6 +20,7 @@ export default function defaultValueDirective(directiveName = 'default') {
2020

2121
if (defaultValueDirective) {
2222
let { value } = defaultValueDirective as {value: string};
23+
2324
try {
2425
value = JSON.parse(value);
2526
} catch (_) {
@@ -38,8 +39,9 @@ export default function defaultValueDirective(directiveName = 'default') {
3839
return result;
3940
};
4041
}
42+
4143
return fieldConfig;
42-
}
43-
})
44-
}
44+
},
45+
}),
46+
};
4547
}

src/directives/renameFrom.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {defaultFieldResolver, GraphQLSchema} from "graphql";
2-
import {mapSchema, MapperKind, getDirective} from '@graphql-tools/utils'
1+
import { defaultFieldResolver, GraphQLSchema } from 'graphql';
2+
import { mapSchema, MapperKind, getDirective } from '@graphql-tools/utils';
33

44
export default function renameFromDirective(directiveName = 'renameFrom') {
55
return {
6-
renameFromDirectiveTypeDefs:`
6+
renameFromDirectiveTypeDefs: `
77
"""
88
Directive for field renaming
99
"""
@@ -21,14 +21,16 @@ export default function renameFromDirective(directiveName = 'renameFrom') {
2121
const { name } = renameFromDirective as {name: string};
2222

2323
const { resolve = defaultFieldResolver } = fieldConfig;
24+
2425
fieldConfig.resolve = (parent, args, context, info) => {
2526
parent[fieldName] = parent[name];
2627

2728
return resolve(parent, args, context, info);
28-
}
29+
};
2930
}
31+
3032
return fieldConfig;
31-
}
32-
})
33-
}
33+
},
34+
}),
35+
};
3436
}

src/directives/requireAdmin.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {defaultFieldResolver, GraphQLSchema} from "graphql";
2-
import {mapSchema, MapperKind, getDirective} from '@graphql-tools/utils'
3-
import {ResolverContextWithUser, UnknownGraphQLResolverResult} from "../types/graphql";
4-
import {ForbiddenError, UserInputError} from "apollo-server-express";
5-
import WorkspaceModel from "../models/workspace";
1+
import { defaultFieldResolver, GraphQLSchema } from 'graphql';
2+
import { mapSchema, MapperKind, getDirective } from '@graphql-tools/utils';
3+
import { ResolverContextWithUser, UnknownGraphQLResolverResult } from '../types/graphql';
4+
import { ForbiddenError, UserInputError } from 'apollo-server-express';
5+
import WorkspaceModel from '../models/workspace';
66

77
/**
88
* Check is user admin via workspace id
@@ -87,8 +87,9 @@ export default function requireAdminDirective(directiveName = 'requireAdmin') {
8787
return resolve(...resolverArgs);
8888
};
8989
}
90+
9091
return fieldConfig;
91-
}
92-
})
93-
}
92+
},
93+
}),
94+
};
9495
}

src/directives/requireAuth.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {defaultFieldResolver, GraphQLSchema} from "graphql";
2-
import {mapSchema, MapperKind, getDirective} from '@graphql-tools/utils'
3-
import {ResolverContextBase, UnknownGraphQLResolverResult} from "../types/graphql";
4-
import {AccessTokenExpiredError} from "../errors";
5-
import {AuthenticationError} from "apollo-server-express";
1+
import { defaultFieldResolver, GraphQLSchema } from 'graphql';
2+
import { mapSchema, MapperKind, getDirective } from '@graphql-tools/utils';
3+
import { ResolverContextBase, UnknownGraphQLResolverResult } from '../types/graphql';
4+
import { AccessTokenExpiredError } from '../errors';
5+
import { AuthenticationError } from 'apollo-server-express';
66

77
/**
88
* Authorizes the user or throws an error if the data is incorrect
@@ -20,7 +20,6 @@ function checkUser(context: ResolverContextBase): void {
2020
}
2121
}
2222

23-
2423
export default function requireAuthDirective(directiveName = 'requireAuth') {
2524
return {
2625
requireAuthDirectiveTypeDefs: `
@@ -51,8 +50,9 @@ export default function requireAuthDirective(directiveName = 'requireAuth') {
5150
return resolve.apply(this, resolverArgs);
5251
};
5352
}
53+
5454
return fieldConfig;
55-
}
56-
})
57-
}
55+
},
56+
}),
57+
};
5858
}

src/directives/requireUserInWorkspace.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {defaultFieldResolver, GraphQLSchema} from "graphql";
2-
import {mapSchema, MapperKind, getDirective} from '@graphql-tools/utils'
3-
import {ResolverContextBase, UnknownGraphQLResolverResult} from "../types/graphql";
4-
import {ForbiddenError} from "apollo-server-express";
1+
import { defaultFieldResolver, GraphQLSchema } from 'graphql';
2+
import { mapSchema, MapperKind, getDirective } from '@graphql-tools/utils';
3+
import { ResolverContextBase, UnknownGraphQLResolverResult } from '../types/graphql';
4+
import { ForbiddenError } from 'apollo-server-express';
55

66
/**
77
* Throw error from sync function
@@ -59,10 +59,9 @@ async function checkUserInWorkspaceByProjectId(context: ResolverContextBase, pro
5959
}
6060
}
6161

62-
6362
export default function requireUserInWorkspaceDirective(directiveName = 'requireUserInWorkspace') {
6463
return {
65-
requireUserInWorkspaceDirectiveTypeDefs:`
64+
requireUserInWorkspaceDirectiveTypeDefs: `
6665
"""
6766
Directive for checking user in workspace
6867
"""
@@ -97,8 +96,9 @@ export default function requireUserInWorkspaceDirective(directiveName = 'require
9796
return resolve.apply(this, resolverArgs);
9897
};
9998
}
99+
100100
return fieldConfig;
101-
}
102-
})
103-
}
101+
},
102+
}),
103+
};
104104
}
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import {defaultFieldResolver, GraphQLSchema, InputValueDefinitionNode} from "graphql";
2-
import {mapSchema, MapperKind, getDirective} from '@graphql-tools/utils'
3-
import {BooleanValueNode} from "graphql/language/ast";
4-
import {save} from "../utils/files";
1+
import { defaultFieldResolver, GraphQLSchema, InputValueDefinitionNode } from 'graphql';
2+
import { mapSchema, MapperKind, getDirective } from '@graphql-tools/utils';
3+
import { save } from '../utils/files';
54

65
export default function uploadImageDirective(directiveName = 'uploadImage') {
76
return {
@@ -15,26 +14,31 @@ export default function uploadImageDirective(directiveName = 'uploadImage') {
1514
mapSchema(schema, {
1615
[MapperKind.MUTATION_ROOT_FIELD]: (fieldConfig) => {
1716
const fieldArgs = fieldConfig.astNode?.arguments;
17+
1818
if (fieldArgs) {
1919
fieldArgs.forEach(arg => {
2020
const directives = arg.directives;
21+
2122
directives?.forEach(directive => {
2223
if (directive.name.value === directiveName) {
23-
const {resolve = defaultFieldResolver} = fieldConfig;
24+
const { resolve = defaultFieldResolver } = fieldConfig;
25+
2426
fieldConfig.resolve = async (object, args, context, info) => {
2527
if (args[arg.name.value]) {
2628
const imageMeta = await (args[arg.name.value] as Promise<any>);
2729

2830
args[arg.name.value] = await save(imageMeta.file.createReadStream(), imageMeta.mimetype);
2931
}
32+
3033
return resolve(object, args, context, info);
3134
};
3235
}
33-
})
34-
})
36+
});
37+
});
3538
}
39+
3640
return fieldConfig;
37-
}
38-
})
39-
}
41+
},
42+
}),
43+
};
4044
}

src/directives/validate.ts

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {defaultFieldResolver, GraphQLSchema} from "graphql";
2-
import {mapSchema, MapperKind, getDirective, getDirectives} from '@graphql-tools/utils'
3-
import {UserInputError} from "apollo-server-express";
4-
import {BooleanValueNode} from "graphql/language/ast";
1+
import { defaultFieldResolver, GraphQLSchema } from 'graphql';
2+
import { mapSchema, MapperKind, getDirective, getDirectives } from '@graphql-tools/utils';
3+
import { UserInputError } from 'apollo-server-express';
4+
import { BooleanValueNode } from 'graphql/language/ast';
55

66
/**
77
* Validates string using regex
@@ -12,8 +12,8 @@ function checkEmail(email: string): void {
1212
const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/g;
1313

1414
if (email.match(emailRegex) === null) {
15-
throw new UserInputError('Wrong email format');
16-
}
15+
throw new UserInputError('Wrong email format');
16+
}
1717
}
1818

1919
/**
@@ -22,13 +22,21 @@ function checkEmail(email: string): void {
2222
*/
2323
function checkNotEmpty(str: string): void {
2424
if (str.replace(/\s/g, '').length == 0) {
25-
throw new UserInputError('The value must not be empty');
26-
}
25+
throw new UserInputError('The value must not be empty');
26+
}
2727
}
2828

29-
export default function validateDirective(directiveName = 'validate') {
29+
/**
30+
*
31+
* @param directiveName
32+
* @returns
33+
*/
34+
export default function validateDirective(directiveName = 'validate'): {
35+
validateDirectiveTypeDefs: string;
36+
validateDirectiveTransformer: (schema: GraphQLSchema) => GraphQLSchema;
37+
} {
3038
return {
31-
validateDirectiveTypeDefs:`
39+
validateDirectiveTypeDefs: `
3240
"""
3341
Directive for checking a field for empty space
3442
"""
@@ -38,32 +46,38 @@ export default function validateDirective(directiveName = 'validate') {
3846
mapSchema(schema, {
3947
[MapperKind.MUTATION_ROOT_FIELD]: (fieldConfig, fieldName) => {
4048
const args = fieldConfig.astNode?.arguments;
49+
4150
if (args) {
4251
args.forEach(arg => {
4352
const directives = arg.directives;
53+
4454
directives?.forEach(directive => {
4555
if (directive.name.value === directiveName) {
4656
const directiveArguments = directive.arguments;
4757
const isEmail = (directiveArguments?.find(arg => arg.name.value === 'isEmail')?.value as BooleanValueNode)?.value;
4858
const notEmpty = (directiveArguments?.find(arg => arg.name.value === 'notEmpty')?.value as BooleanValueNode)?.value;
59+
4960
if (isEmail || notEmpty) {
5061
const { resolve = defaultFieldResolver } = fieldConfig;
62+
5163
fieldConfig.resolve = async (object, args, context, info) => {
5264
if (isEmail) {
5365
checkEmail(args[arg.name.value] || '');
5466
}
5567
if (notEmpty) {
5668
checkNotEmpty(args[arg.name.value] || '');
5769
}
70+
5871
return resolve(object, args, context, info);
5972
};
6073
}
6174
}
62-
})
63-
})
75+
});
76+
});
6477
}
65-
return fieldConfig
66-
}
67-
})
68-
}
78+
79+
return fieldConfig;
80+
},
81+
}),
82+
};
6983
}

src/models/usersFactory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ export default class UsersFactory extends AbstractModelFactory<UserDBScheme, Use
8282
user.generatedPassword = generatedPassword;
8383

8484
await Analytics.logEvent({
85+
/* eslint-disable-next-line camelcase */
8586
event_type: AnalyticsEventTypes.NEW_USER_REGISTERED,
87+
/* eslint-disable-next-line camelcase */
8688
user_id: userId.toString(),
8789
time: Date.now(),
8890
});

src/models/workspacesFactory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ export default class WorkspacesFactory extends AbstractModelFactory<WorkspaceDBS
7171
await workspaceModel.changePlan((await this.getDefaultPlan())._id.toString());
7272

7373
await Analytics.logEvent({
74+
/* eslint-disable-next-line camelcase */
7475
event_type: AnalyticsEventTypes.WORKSPACE_CREATED,
76+
/* eslint-disable-next-line camelcase */
7577
user_id: ownerModel._id.toString(),
7678
time: Date.now(),
7779
});

src/resolvers/billingNew.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export default {
192192
amount = AMOUNT_FOR_CARD_VALIDATION;
193193
}
194194

195-
const operation = await factories.businessOperationsFactory.getBusinessOperationByTransactionId("foo");
195+
const operation = await factories.businessOperationsFactory.getBusinessOperationByTransactionId('foo');
196196

197197
return {
198198
recordId: operation?._id,

0 commit comments

Comments
 (0)