Change to using arrow functions (#1603)
* Change to using arrow functions Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> * Add lint rule --------- Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -3,7 +3,7 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { getDMMF, getSchemaPath } = require('@prisma/internals');
|
||||
|
||||
async function generateTypes() {
|
||||
const generateTypes = async () => {
|
||||
const schemaPath = await getSchemaPath();
|
||||
const dmmf = await getDMMF({
|
||||
datamodel: fs.readFileSync(schemaPath, 'utf-8'),
|
||||
@ -24,7 +24,7 @@ async function generateTypes() {
|
||||
path.join(__dirname, '../src/utils/prisma-select/model-select-map.ts'),
|
||||
content,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
generateTypes().catch((e) => {
|
||||
console.error(e);
|
||||
|
||||
@ -117,12 +117,12 @@ const operationAbilityCheckers: Record<OperationType, OperationAbilityChecker> =
|
||||
};
|
||||
|
||||
// Check relation nested abilities
|
||||
export async function relationAbilityChecker(
|
||||
export const relationAbilityChecker = async (
|
||||
modelName: Prisma.ModelName,
|
||||
ability: AppAbility,
|
||||
prisma: PrismaClient,
|
||||
args: any,
|
||||
) {
|
||||
) => {
|
||||
// Extract models from Prisma
|
||||
const models = Prisma.dmmf.datamodel.models;
|
||||
// Find main model from options
|
||||
@ -211,7 +211,7 @@ export async function relationAbilityChecker(
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
const isWhereInput = (input: any): boolean => {
|
||||
return Object.values(input).some((value) => typeof value === 'object');
|
||||
|
||||
@ -11,7 +11,7 @@ import { FileFolder } from './interfaces/file-folder.interface';
|
||||
|
||||
type AllowedFolders = KebabCase<keyof typeof FileFolder>;
|
||||
|
||||
export function checkFilePath(filePath: string): string {
|
||||
export const checkFilePath = (filePath: string): string => {
|
||||
const allowedFolders = Object.values(FileFolder).map((value) =>
|
||||
kebabCase(value),
|
||||
);
|
||||
@ -28,9 +28,9 @@ export function checkFilePath(filePath: string): string {
|
||||
}
|
||||
|
||||
return sanitizedFilePath;
|
||||
}
|
||||
};
|
||||
|
||||
export function checkFilename(filename: string) {
|
||||
export const checkFilename = (filename: string) => {
|
||||
const sanitizedFilename = basename(filename.replace(/\0/g, ''));
|
||||
|
||||
if (
|
||||
@ -43,4 +43,4 @@ export function checkFilename(filename: string) {
|
||||
}
|
||||
|
||||
return basename(sanitizedFilename);
|
||||
}
|
||||
};
|
||||
|
||||
@ -5,12 +5,12 @@
|
||||
* @param uuid
|
||||
* @returns
|
||||
*/
|
||||
export function uuidToBase36(uuid: string): string {
|
||||
export const uuidToBase36 = (uuid: string): string => {
|
||||
const hexString = uuid.replace(/-/g, '');
|
||||
const base10Number = BigInt('0x' + hexString);
|
||||
const base36String = base10Number.toString(36);
|
||||
return base36String;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sanitizes a column name by replacing all non-alphanumeric characters with an underscore.
|
||||
@ -19,9 +19,8 @@ export function uuidToBase36(uuid: string): string {
|
||||
* @param columnName
|
||||
* @returns string
|
||||
*/
|
||||
export function sanitizeColumnName(columnName: string): string {
|
||||
return columnName.replace(/[^a-zA-Z0-9]/g, '_');
|
||||
}
|
||||
export const sanitizeColumnName = (columnName: string): string =>
|
||||
columnName.replace(/[^a-zA-Z0-9]/g, '_');
|
||||
|
||||
/**
|
||||
* Converts a field type to a postgres type. Field types are defined in the UI.
|
||||
@ -29,7 +28,7 @@ export function sanitizeColumnName(columnName: string): string {
|
||||
* @param fieldType
|
||||
* @returns string
|
||||
*/
|
||||
export function convertFieldTypeToPostgresType(fieldType: string): string {
|
||||
export const convertFieldTypeToPostgresType = (fieldType: string): string => {
|
||||
switch (fieldType) {
|
||||
case 'text':
|
||||
return 'text';
|
||||
@ -44,4 +43,4 @@ export function convertFieldTypeToPostgresType(fieldType: string): string {
|
||||
default:
|
||||
return 'text';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -44,12 +44,12 @@ import { EnvironmentService } from 'src/integrations/environment/environment.ser
|
||||
|
||||
import { UserService } from './user.service';
|
||||
|
||||
function getHMACKey(email?: string, key?: string | null) {
|
||||
const getHMACKey = (email?: string, key?: string | null) => {
|
||||
if (!email || !key) return null;
|
||||
|
||||
const hmac = crypto.createHmac('sha256', key);
|
||||
return hmac.update(email).digest('hex');
|
||||
}
|
||||
};
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Resolver(() => User)
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import { Transform } from 'class-transformer';
|
||||
|
||||
export function CastToBoolean() {
|
||||
return Transform(({ value }: { value: string }) => toBoolean(value));
|
||||
}
|
||||
export const CastToBoolean = () =>
|
||||
Transform(({ value }: { value: string }) => toBoolean(value));
|
||||
|
||||
const toBoolean = (value: any) => {
|
||||
if (typeof value === 'boolean') {
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import { Transform } from 'class-transformer';
|
||||
|
||||
export function CastToLogLevelArray() {
|
||||
return Transform(({ value }: { value: string }) => toLogLevelArray(value));
|
||||
}
|
||||
export const CastToLogLevelArray = () =>
|
||||
Transform(({ value }: { value: string }) => toLogLevelArray(value));
|
||||
|
||||
const toLogLevelArray = (value: any) => {
|
||||
if (typeof value === 'string') {
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import { Transform } from 'class-transformer';
|
||||
|
||||
export function CastToPositiveNumber() {
|
||||
return Transform(({ value }: { value: string }) => toNumber(value));
|
||||
}
|
||||
export const CastToPositiveNumber = () =>
|
||||
Transform(({ value }: { value: string }) => toNumber(value));
|
||||
|
||||
const toNumber = (value: any) => {
|
||||
if (typeof value === 'number') {
|
||||
|
||||
@ -13,8 +13,9 @@ export class IsAWSRegionConstraint implements ValidatorConstraintInterface {
|
||||
}
|
||||
}
|
||||
|
||||
export function IsAWSRegion(validationOptions?: ValidationOptions) {
|
||||
return function (object: object, propertyName: string) {
|
||||
export const IsAWSRegion =
|
||||
(validationOptions?: ValidationOptions) =>
|
||||
(object: object, propertyName: string) => {
|
||||
registerDecorator({
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
@ -23,4 +24,3 @@ export function IsAWSRegion(validationOptions?: ValidationOptions) {
|
||||
validator: IsAWSRegionConstraint,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@ -14,8 +14,9 @@ export class IsDurationConstraint implements ValidatorConstraintInterface {
|
||||
}
|
||||
}
|
||||
|
||||
export function IsDuration(validationOptions?: ValidationOptions) {
|
||||
return function (object: object, propertyName: string) {
|
||||
export const IsDuration =
|
||||
(validationOptions?: ValidationOptions) =>
|
||||
(object: object, propertyName: string) => {
|
||||
registerDecorator({
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
@ -24,4 +25,3 @@ export function IsDuration(validationOptions?: ValidationOptions) {
|
||||
validator: IsDurationConstraint,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@ -143,11 +143,11 @@ export class EnvironmentVariables {
|
||||
SENTRY_DSN?: string;
|
||||
}
|
||||
|
||||
export function validate(config: Record<string, unknown>) {
|
||||
export const validate = (config: Record<string, unknown>) => {
|
||||
const validatedConfig = plainToClass(EnvironmentVariables, config);
|
||||
|
||||
const errors = validateSync(validatedConfig);
|
||||
assert(!errors.length, errors.toString());
|
||||
|
||||
return validatedConfig;
|
||||
}
|
||||
};
|
||||
|
||||
@ -11,7 +11,7 @@ import { settings } from './constants/settings';
|
||||
import { LoggerService } from './integrations/logger/logger.service';
|
||||
import { EnvironmentService } from './integrations/environment/environment.service';
|
||||
|
||||
async function bootstrap() {
|
||||
const bootstrap = async () => {
|
||||
const app = await NestFactory.create(AppModule, {
|
||||
cors: true,
|
||||
});
|
||||
@ -39,6 +39,6 @@ async function bootstrap() {
|
||||
app.useLogger(app.get(EnvironmentService).getLogLevels());
|
||||
|
||||
await app.listen(app.get(EnvironmentService).getPort());
|
||||
}
|
||||
};
|
||||
|
||||
bootstrap();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import crypto from 'crypto';
|
||||
|
||||
export function anonymize(input: string) {
|
||||
export const anonymize = (input: string) => {
|
||||
// md5 shorter than sha-256 and collisions are not a security risk in this use-case
|
||||
return crypto.createHash('md5').update(input).digest('hex');
|
||||
}
|
||||
};
|
||||
|
||||
@ -23,6 +23,5 @@ export const assert: Assert = (condition, message, ErrorType) => {
|
||||
}
|
||||
};
|
||||
|
||||
export function assertNotNull<T>(item: T): item is NonNullable<T> {
|
||||
return item !== null && item !== undefined;
|
||||
}
|
||||
export const assertNotNull = <T>(item: T): item is NonNullable<T> =>
|
||||
item !== null && item !== undefined;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Readable } from 'stream';
|
||||
|
||||
export async function streamToBuffer(stream: Readable): Promise<Buffer> {
|
||||
export const streamToBuffer = async (stream: Readable): Promise<Buffer> => {
|
||||
const chunks: any[] = [];
|
||||
|
||||
for await (const chunk of stream) {
|
||||
@ -8,4 +8,4 @@ export async function streamToBuffer(stream: Readable): Promise<Buffer> {
|
||||
}
|
||||
|
||||
return Buffer.concat(chunks);
|
||||
}
|
||||
};
|
||||
|
||||
@ -16,7 +16,7 @@ const schemaDatabaseExists = async (databaseName: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
async function main() {
|
||||
const main = async () => {
|
||||
const databaseName = 'tests';
|
||||
// Check if schema exists
|
||||
const databaseExistsResult = await schemaDatabaseExists(databaseName);
|
||||
@ -27,7 +27,7 @@ async function main() {
|
||||
|
||||
// Check if database is initialized
|
||||
await prisma.$queryRaw`SELECT 1 FROM pg_tables WHERE tablename='_prisma_migrations';`;
|
||||
}
|
||||
};
|
||||
|
||||
main()
|
||||
.then(() => {
|
||||
|
||||
@ -21,12 +21,12 @@ export type TestingAppCreatePreHook = (
|
||||
/**
|
||||
* Sets basic e2e testing module of app
|
||||
*/
|
||||
export async function createApp(
|
||||
export const createApp = async (
|
||||
config: {
|
||||
moduleBuilderHook?: TestingModuleCreatePreHook;
|
||||
appInitHook?: TestingAppCreatePreHook;
|
||||
} = {},
|
||||
): Promise<[NestExpressApplication, TestingModule]> {
|
||||
): Promise<[NestExpressApplication, TestingModule]> => {
|
||||
let moduleBuilder: TestingModuleBuilder = Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
});
|
||||
@ -53,4 +53,4 @@ export async function createApp(
|
||||
app.use(mockAuthHandler);
|
||||
|
||||
return [await app.init(), moduleFixture];
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user