Skip to content

Commit

Permalink
[ZARS-669][FIX] fix and run linter
Browse files Browse the repository at this point in the history
  • Loading branch information
af-egr committed Nov 28, 2024
1 parent 7739362 commit 68c3f2f
Show file tree
Hide file tree
Showing 36 changed files with 115 additions and 74 deletions.
22 changes: 0 additions & 22 deletions .eslintrc.js

This file was deleted.

34 changes: 34 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const tsParser = require('@typescript-eslint/parser');
const tsEslintPlugin = require('@typescript-eslint/eslint-plugin');
const prettierPlugin = require('eslint-plugin-prettier');
const prettierConfig = require('eslint-config-prettier');

module.exports = [
{
files: ['**/*.ts', '**/*.tsx'], // Apply to TypeScript files
languageOptions: {
parser: tsParser,
parserOptions: {
project: './tsconfig.json',
sourceType: 'module',
},
},
plugins: {
'@typescript-eslint': tsEslintPlugin,
prettier: prettierPlugin,
},
rules: {
...tsEslintPlugin.configs.recommended.rules, // Load recommended TypeScript rules
...prettierConfig.rules, // Load Prettier rules
'prettier/prettier': 'error', // Enforce Prettier formatting
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['.eslintrc.js'], // Special handling for config files
ignores: [],
},
];
4 changes: 2 additions & 2 deletions src/modules/auth/__tests__/role.guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('RoleGuard', () => {
return { user };
});

jest.spyOn(context, 'switchToHttp').mockImplementationOnce(() => ({ getRequest: getRequestMock } as any));
jest.spyOn(context, 'switchToHttp').mockImplementationOnce(() => ({ getRequest: getRequestMock }) as any);
const result = guard.canActivate(context);
expect(result).toEqual(false);
});
Expand All @@ -82,7 +82,7 @@ describe('RoleGuard', () => {
return { user };
});

jest.spyOn(context, 'switchToHttp').mockImplementationOnce(() => ({ getRequest: getRequestMock } as any));
jest.spyOn(context, 'switchToHttp').mockImplementationOnce(() => ({ getRequest: getRequestMock }) as any);
const result = guard.canActivate(context);
expect(result).toEqual(true);
});
Expand Down
5 changes: 4 additions & 1 deletion src/modules/auth/strategies/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { JwksProvider } from './jwks.provider';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(protected readonly configService: ConfigService, protected readonly jwksProvider: JwksProvider) {
constructor(
protected readonly configService: ConfigService,
protected readonly jwksProvider: JwksProvider,
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class CommentAnswerEventService {
) {
const commentLocation = answer.locations.includes(MiiLocation.VirtualAll)
? ALL_ACTIVE_LOCATIONS
: answer.locations ?? [];
: (answer.locations ?? []);

const locations = reduceParticipatingLocations(proposal, commentLocation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class CommentEventService {
private async handleProposalMessageToLocationCreation(proposal: Proposal, comment: Comment, proposalUrl: string) {
const commentLocation = comment.locations.includes(MiiLocation.VirtualAll)
? ALL_ACTIVE_LOCATIONS
: comment.locations ?? [];
: (comment.locations ?? []);

const locations = reduceParticipatingLocations(proposal, commentLocation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { getResearcherSignedEmailForDizMembers, getSigningCompleteEmailForFdpgMe

@Injectable()
export class ContractingService {
constructor(private keycloakUtilService: KeycloakUtilService, private emailService: EmailService) {}
constructor(
private keycloakUtilService: KeycloakUtilService,
private emailService: EmailService,
) {}

private async handleResearcherSign(proposal: Proposal, vote: boolean, proposalUrl: string) {
const emailTasks: Promise<void>[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { getDizApprovalEmailForUacMembers, getVotingCompleteEmailForFdpgMember }

@Injectable()
export class LocationVoteService {
constructor(private keycloakUtilService: KeycloakUtilService, private emailService: EmailService) {}
constructor(
private keycloakUtilService: KeycloakUtilService,
private emailService: EmailService,
) {}

private isVotingComplete(proposal: Proposal): boolean {
const numberOfVotedLocations = proposal.requestedButExcludedLocations.length + proposal.uacApprovedLocations.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { getProposalLockedEmailForOwner, getProposalUnlockedEmailForOwner } from

@Injectable()
export class ProposalLockService {
constructor(private keycloakUtilService: KeycloakUtilService, private emailService: EmailService) {}
constructor(
private keycloakUtilService: KeycloakUtilService,
private emailService: EmailService,
) {}

private async handleProposalLock(proposal: Proposal, proposalUrl: string) {
const ownerTask = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { Publication } from 'src/modules/proposal/schema/sub-schema/publication.

@Injectable()
export class PublicationsService {
constructor(private keycloakUtilService: KeycloakUtilService, private emailService: EmailService) {}
constructor(
private keycloakUtilService: KeycloakUtilService,
private emailService: EmailService,
) {}

async handlePublicationCreate(proposal: Proposal, publication: PublicationCreateDto, proposalUrl: string) {
const emailTasks: Promise<void>[] = [];
Expand Down
5 changes: 4 additions & 1 deletion src/modules/event-engine/events/reports/reports.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {

@Injectable()
export class ReportsService {
constructor(private keycloakUtilService: KeycloakUtilService, private emailService: EmailService) {}
constructor(
private keycloakUtilService: KeycloakUtilService,
private emailService: EmailService,
) {}

async handleReportCreate(proposal: Proposal, report: ReportDto, proposalUrl: string) {
const emailTasks: Promise<void>[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import {

@Injectable()
export class StatusChangeService {
constructor(private keycloakUtilService: KeycloakUtilService, private emailService: EmailService) {}
constructor(
private keycloakUtilService: KeycloakUtilService,
private emailService: EmailService,
) {}

private async handleProposalSubmit(proposal: Proposal, proposalUrl: string) {
const ownerTask = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import {

@Injectable()
export class StatusReminderService {
constructor(private keycloakUtilService: KeycloakUtilService, private emailService: EmailService) {}
constructor(
private keycloakUtilService: KeycloakUtilService,
private emailService: EmailService,
) {}

private async handleFdpgCheckReminder(proposal: ProposalWithoutContent, proposalUrl: string) {
const fdpgTask = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { HistoryEventGetDto } from '../dto/proposal/history-event.dto';
import { HistoryEvent } from '../schema/sub-schema/history-event.schema';
import { HistoryEventType } from '../enums/history-event.enum';

export const ExposeHistory = () => (target: Object, propertyKey: string) => {
export const ExposeHistory = () => (target: object, propertyKey: string) => {
Expose()(target, propertyKey);
Transform((params) => {
const user = parseGroupToUser(params.options.groups);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parseGroupToUser } from 'src/shared/utils/user-group.utils';

import { getMostAdvancedState } from '../utils/validate-access.util';

export const ExposeLocationStatus = (options?: ExposeOptions) => (target: Object, propertyKey: string) => {
export const ExposeLocationStatus = (options?: ExposeOptions) => (target: object, propertyKey: string) => {
Expose(options)(target, propertyKey);
Transform((params) => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const generalAccessTypes = [
UseCaseUpload.ProposalPDF,
UseCaseUpload.ReportUpload,
] as UploadType[];
export const ExposeUpload = () => (target: Object, propertyKey: string) => {
export const ExposeUpload = () => (target: object, propertyKey: string) => {
Expose()(target, propertyKey);
Transform((params) => {
const user = parseGroupToUser(params.options.groups);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class ConditionalApprovalGetDto {
@Expose()
dataAmount: number;

@Expose({ groups: [Role.FdpgMember]})
@Expose({ groups: [Role.FdpgMember] })
uploadId: string;

@ExposeId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class EthicVoteDto extends WithIdForObjectDto {
@Expose()
@IsOptional({ groups: [ProposalValidation.IsDraft] })
@ValidateIf((ethicVote: EthicVoteDto) => ethicVote.isExisting)
@Equals( true)
@Equals(true)
admitReputationOfAttachment: boolean;

@Expose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IsEnum, IsOptional, MaxLength } from 'class-validator';
import { ProposalValidation } from 'src/modules/proposal/enums/porposal-validation.enum';
import { WithIdForArrayDto } from 'src/shared/dto/with-id-for-array.dto';
import { IsNotEmptyString } from 'src/shared/validators/is-not-empty-string.validator';
import { PublicationType } from '../../../enums/publication-type.enum'
import { PublicationType } from '../../../enums/publication-type.enum';

export class PublicationDto extends WithIdForArrayDto {
@Expose()
Expand All @@ -22,5 +22,4 @@ export class PublicationDto extends WithIdForArrayDto {
@IsOptional({ groups: [ProposalValidation.IsDraft] })
@MaxLength(10000)
authors: string;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export class PlannedPublication {

@Prop({
type: Boolean,
default: false
default: false,
})
noPublicationPlanned: boolean
noPublicationPlanned: boolean;
}

export const PlannedPublicationSchema = SchemaFactory.createForClass(PlannedPublication);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Document } from 'mongoose';
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { PublicationType } from '../../../enums/publication-type.enum'
import { PublicationType } from '../../../enums/publication-type.enum';
export type PublicationDocument = Publication & Document;

@Schema({ _id: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { Publication, PublicationDocument } from '../schema/sub-schema/publicati

@Injectable()
export class ProposalPublicationService {
constructor(private proposalCrudService: ProposalCrudService, private eventEngineService: EventEngineService) {}
constructor(
private proposalCrudService: ProposalCrudService,
private eventEngineService: EventEngineService,
) {}

async createPublication(
proposalId: string,
Expand Down
5 changes: 4 additions & 1 deletion src/modules/proposal/services/proposal-upload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { validateUploadDeletion } from '../utils/validate-upload-deletion.util';

@Injectable()
export class ProposalUploadService {
constructor(private proposalCrudService: ProposalCrudService, private storageService: StorageService) {}
constructor(
private proposalCrudService: ProposalCrudService,
private storageService: StorageService,
) {}

async upload(
proposalId: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class IsUniqueAbbreviationConstraint implements ValidatorConstraintInterf
}

export function IsUniqueAbbreviation(validationOptions?: ValidationOptions) {
return (object: Object, propertyName: string) => {
return (object: object, propertyName: string) => {
registerDecorator({
async: true,
name: 'isUniqueAbbreviation',
Expand Down
2 changes: 1 addition & 1 deletion src/modules/storage/__tests__/storage.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('StorageService', () => {
statObject: jest.fn(),
removeObject: jest.fn(),
removeObjects: jest.fn(),
presignedGetObject: jest.fn()
presignedGetObject: jest.fn(),
};

const configService = {
Expand Down
16 changes: 8 additions & 8 deletions src/modules/storage/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ export class StorageService {

constructor(private readonly configService: ConfigService) {
const endPoint = this.configService.get('S3_ENDPOINT');
const port = parseInt(this.configService.get('S3_PORT') || "443");
const port = parseInt(this.configService.get('S3_PORT') || '443');
const useSSL = (this.configService.get('S3_USE_SSL') || '').toLowerCase() === 'true';
const accessKey = this.configService.get("S3_ACCESSKEY")
const secretKey = this.configService.get("S3_SECRETKEY")
const accessKey = this.configService.get('S3_ACCESSKEY');
const secretKey = this.configService.get('S3_SECRETKEY');

this.minioClient = new Client({
endPoint,
port,
useSSL,
accessKey,
secretKey
secretKey,
});

this.bucketName = this.configService.get("S3_BUCKET");
this.bucketName = this.configService.get('S3_BUCKET');
}

async uploadFile(blobName: string, file: Express.Multer.File, user: IRequestUser): Promise<void> {
Expand All @@ -39,8 +39,8 @@ export class StorageService {
const metadata: ItemBucketMetadata = {
'Content-Type': file.mimetype,
'Content-Disposition': `attachment; filename="${filenameRemovedNonAscii}"; filename*=UTF-8''${encodedFileName}`,
'userLocation': userLocationRemovedNonAscii,
'userId': user.userId
userLocation: userLocationRemovedNonAscii,
userId: user.userId,
};

try {
Expand All @@ -63,7 +63,7 @@ export class StorageService {
return await this.minioClient.presignedGetObject(this.bucketName, blobName, lifetimeInSeconds);
}

private async blobExists(blobName: string): Promise<Boolean> {
private async blobExists(blobName: string): Promise<boolean> {
try {
await this.minioClient.statObject(this.bucketName, blobName);
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/decorators/transform/expose-id.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Expose, ExposeOptions, Transform } from 'class-transformer';

// https://github.com/typestack/class-transformer/issues/494
export const ExposeId = (options?: ExposeOptions) => (target: Object, propertyKey: string) => {
export const ExposeId = (options?: ExposeOptions) => (target: object, propertyKey: string) => {
Expose(options)(target, propertyKey);
Transform(({ obj }) => {
return obj[propertyKey];
Expand Down
8 changes: 4 additions & 4 deletions src/shared/types/nested-key-of.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ type Join<K, P> = K extends string | number
type NestedPath<T, D extends number = 10> = [D] extends [never]
? never
: T extends object
? {
[K in keyof T]-?: K extends string | number ? `${K}` | Join<K, NestedPath<T[K], Prev[D]>> : never;
}[keyof T]
: '';
? {
[K in keyof T]-?: K extends string | number ? `${K}` | Join<K, NestedPath<T[K], Prev[D]>> : never;
}[keyof T]
: '';

type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...0[]];
2 changes: 1 addition & 1 deletion src/shared/utils/find-by-key-nested.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IResult {
* @returns Returns the found object and path where the key matches the value.
*/
export const findByKeyNested = (
target: Array<any> | Object,
target: Array<any> | object,
key: string,
value: string | number | boolean,
pathAcc: (string | number)[] = [],
Expand Down
2 changes: 1 addition & 1 deletion src/shared/validators/is-after-today.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const isAfterToday = (value: string): boolean => {
return startOfToday <= incomingDate;
};
export function IsAfterToday(validationOptions?: ValidationOptions) {
return (object: Object, propertyName: string) => {
return (object: object, propertyName: string) => {
registerDecorator({
name: 'isAfterToday',
target: object.constructor,
Expand Down
Loading

0 comments on commit 68c3f2f

Please sign in to comment.