Skip to content

Commit

Permalink
chore: extend root eslint config in twenty-server (twentyhq#5101)
Browse files Browse the repository at this point in the history
Reopening @thaisguigon work from
twentyhq#4781

---------

Co-authored-by: Thaïs Guigon <guigon.thais@gmail.com>
  • Loading branch information
Weiko and thaisguigon authored Apr 22, 2024
1 parent b9a7eb5 commit fa4670b
Show file tree
Hide file tree
Showing 66 changed files with 646 additions and 629 deletions.
91 changes: 91 additions & 0 deletions packages/twenty-server/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
module.exports = {
plugins: ['@stylistic'],
extends: ['../../.eslintrc.cjs'],
ignorePatterns: ['src/engine/workspace-manager/demo-objects-prefill-data/**'],
overrides: [
{
files: ['*.ts'],
parserOptions: {
project: ['packages/twenty-server/tsconfig.json'],
},
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['**../'],
message: 'Relative imports are not allowed.',
},
],
},
],

'@stylistic/linebreak-style': ['error', 'unix'],
'@stylistic/lines-between-class-members': [
'error',
{
enforce: [{ blankLine: 'always', prev: 'method', next: 'method' }],
},
],
'@stylistic/padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' },
{ blankLine: 'always', prev: ['const', 'let', 'var'], next: '*' },
{
blankLine: 'any',
prev: ['const', 'let', 'var'],
next: ['const', 'let', 'var'],
},
{ blankLine: 'always', prev: '*', next: ['interface', 'type'] },
],

'import/order': [
'error',
{
'newlines-between': 'always',
groups: [
'builtin',
'external',
'internal',
'type',
'parent',
'sibling',
'object',
'index',
],
pathGroups: [
{
pattern: '@nestjs/**',
group: 'builtin',
position: 'before',
},
{
pattern: '**/interfaces/**',
group: 'type',
position: 'before',
},
{
pattern: 'src/**',
group: 'parent',
position: 'before',
},
{
pattern: './*',
group: 'sibling',
position: 'before',
},
],
distinctGroup: true,
warnOnUnassignedImports: true,
pathGroupsExcludedImportTypes: ['@nestjs/**'],
},
],
'simple-import-sort/imports': 'off',
'unicorn/filename-case': 'off',
'prefer-arrow/prefer-arrow-functions': 'off',
'@nx/workspace-max-consts-per-file': 'off',
},
},
],
};
92 changes: 0 additions & 92 deletions packages/twenty-server/.eslintrc.js

This file was deleted.

15 changes: 10 additions & 5 deletions packages/twenty-server/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"cwd": "packages/twenty-server",
"commands": ["rimraf dist", "nest build --path ./tsconfig.build.json"]
}
},
},
"build:packageJson": {
"executor": "@nx/js:tsc",
"options": {
Expand Down Expand Up @@ -81,10 +81,15 @@
}
},
"lint": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/twenty-server",
"command": "eslint \"src/**/*.ts\" --fix"
"executor": "@nx/eslint:lint",
"options": {
"eslintConfig": "{projectRoot}/.eslintrc.cjs",
"ignorePath": "{workspaceRoot}/.gitignore",
"lintFilePatterns": ["{projectRoot}/src/**/*.{ts,json}"]
},
"configurations": {
"ci": { "lintFilePatterns": ["{projectRoot}/**/*.{ts,json}"] },
"fix": { "fix": true }
}
},
"test:unit": {
Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-server/src/command/command-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class CommandLogger {
async writeLog(
fileName: string,
data: unknown,
append: boolean = false,
append = false,
): Promise<void> {
const path = `./logs/${kebabCase(this.className)}`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
console.error(error);
}

try {
} catch (error) {
console.error(error);
}

await this.typeORMService.disconnectFromDataSource(dataSourceMetadata.id);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const seedUsers = async (
'$2b$10$66d.6DuQExxnrfI9rMqOg.U1XIYpagr6Lv05uoWLYbYmtK0HDIvS6', // Applecar2025
defaultWorkspaceId: workspaceId,
},
,
{
id: DEMO_SEED_USER_IDS.JULIA,
firstName: 'Julia',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('FindDuplicatesQueryFactory', () => {
});

expect(query.trim()).toEqual(`query {
personCollection(filter: {or:[{nameFirstName:{eq:\"John\"},nameLastName:{eq:\"Doe\"}}]}) {
personCollection(filter: {or:[{nameFirstName:{eq:"John"},nameLastName:{eq:"Doe"}}]}) {
fieldsString
}
}`);
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('FindDuplicatesQueryFactory', () => {
);

expect(query.trim()).toEqual(`query {
personCollection(filter: {id:{neq:\"uuid\"},or:[{nameFirstName:{eq:\"Peter\"},nameLastName:{eq:\"Parker\"}}]}) {
personCollection(filter: {id:{neq:"uuid"},or:[{nameFirstName:{eq:"Peter"},nameLastName:{eq:"Parker"}}]}) {
fieldsString
}
}`);
Expand All @@ -189,7 +189,7 @@ describe('FindDuplicatesQueryFactory', () => {
});

expect(query.trim()).toEqual(`query {
personCollection(filter: { id: { eq: \"uuid\" }}){
personCollection(filter: { id: { eq: "uuid" }}){
edges {
node {
__typename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ObjectMetadataInterface } from 'src/engine/metadata-modules/field-metad
import { computeObjectTargetTable } from 'src/engine/utils/compute-object-target-table.util';
import { stringifyWithoutKeyQuote } from 'src/engine/api/graphql/workspace-query-builder/utils/stringify-without-key-quote.util';
import { ArgsAliasFactory } from 'src/engine/api/graphql/workspace-query-builder/factories/args-alias.factory';
import { duplicateCriteriaCollection } from 'src/engine/api/graphql/workspace-resolver-builder/constants/duplicate-criteria.constants';
import { DUPLICATE_CRITERIA_COLLECTION } from 'src/engine/api/graphql/workspace-resolver-builder/constants/duplicate-criteria.constants';
import { settings } from 'src/engine/constants/settings';

import { FieldsStringFactory } from './fields-string.factory';
Expand Down Expand Up @@ -145,7 +145,7 @@ export class FindDuplicatesQueryFactory {
private getApplicableDuplicateCriteriaCollection(
objectMetadataItem: ObjectMetadataInterface,
) {
return duplicateCriteriaCollection.filter(
return DUPLICATE_CRITERIA_COLLECTION.filter(
(duplicateCriteria) =>
duplicateCriteria.objectName === objectMetadataItem.nameSingular,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const parseResult = (obj: any): any => {
const result: any = {};

for (const key in obj) {
// eslint-disable-next-line no-prototype-builtins
if (obj.hasOwnProperty(key)) {
if (typeof obj[key] === 'object' && obj[key] !== null) {
result[key] = parseResult(obj[key]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RecordDuplicateCriteria } from 'src/engine/api/graphql/workspace-query-
* So if we need to reference a custom field, we should directly add the column name like `_customColumn`.
* If we need to terence a composite field, we should add all children of the composite like `nameFirstName` and `nameLastName`
*/
export const duplicateCriteriaCollection: RecordDuplicateCriteria[] = [
export const DUPLICATE_CRITERIA_COLLECTION: RecordDuplicateCriteria[] = [
{
objectName: 'company',
columnNames: ['domainName'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class ArgsFactory {
const fieldConfigMap: GraphQLFieldConfigArgumentMap = {};

for (const key in args) {
// eslint-disable-next-line no-prototype-builtins
if (!args.hasOwnProperty(key)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export * from './big-float-filter.input-type';
export * from './big-int-filter.input-type';
export * from './boolean-filter.input-type';
export * from './date-filter.input-type';
export * from './date-time-filter.input-type';
export * from './float-filter.input-type';
export * from './int-filter.input-type';
export * from './raw-json-filter.input-type';
export * from './string-filter.input-type';
export * from './time-filter.input-type';
export * from './uuid-filter.input-type';
export * from './boolean-filter.input-type';
export * from './raw-json-filter.input-type';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';

import { Request } from 'express';
Expand All @@ -12,6 +12,8 @@ import { CreateAnalyticsInput } from './dto/create-analytics.input';

@Injectable()
export class AnalyticsService {
private readonly logger = new Logger(AnalyticsService.name);

constructor(
private readonly environmentService: EnvironmentService,
private readonly httpService: HttpService,
Expand Down Expand Up @@ -53,7 +55,11 @@ export class AnalyticsService {

try {
await this.httpService.axiosRef.post('/v1', data);
} catch {}
} catch {
this.logger.error('Failed to send analytics event');

return { success: false };
}

return { success: true };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ export class GoogleAPIsOauthGuard extends AuthGuard('google-apis') {
}

async canActivate(context: ExecutionContext) {
try {
const request = context.switchToHttp().getRequest();
const transientToken = request.query.transientToken;
const request = context.switchToHttp().getRequest();
const transientToken = request.query.transientToken;

if (transientToken && typeof transientToken === 'string') {
request.params.transientToken = transientToken;
}
const activate = (await super.canActivate(context)) as boolean;

return activate;
} catch (ex) {
throw ex;
if (transientToken && typeof transientToken === 'string') {
request.params.transientToken = transientToken;
}
const activate = (await super.canActivate(context)) as boolean;

return activate;
}
}
Loading

0 comments on commit fa4670b

Please sign in to comment.