Skip to content

Commit 1809b5f

Browse files
authored
Merge pull request #221 from import-ai/fix/lint
fix(lint): Fix lint
2 parents 99d8b62 + afc659e commit 1809b5f

18 files changed

+71
-83
lines changed

src/api-key/api-key.service.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { Test, TestingModule } from '@nestjs/testing';
33
import { getRepositoryToken } from '@nestjs/typeorm';
44
import { Repository } from 'typeorm';
5-
import { ForbiddenException } from '@nestjs/common';
65
import { APIKeyService } from './api-key.service';
76
import {
87
APIKey,
@@ -74,8 +73,10 @@ describe('APIKeyService', () => {
7473
t: jest.fn((key: string, options?: any) => {
7574
// Return mock translations for test purposes
7675
const translations: Record<string, string> = {
77-
'apikey.errors.noPermissionForNamespace': 'User {{userId}} does not have permission to namespace {{namespaceId}}',
78-
'apikey.errors.noWritePermission': 'User {{userId}} does not have write permission to resource {{resourceId}} in namespace {{namespaceId}}',
76+
'apikey.errors.noPermissionForNamespace':
77+
'User {{userId}} does not have permission to namespace {{namespaceId}}',
78+
'apikey.errors.noWritePermission':
79+
'User {{userId}} does not have write permission to resource {{resourceId}} in namespace {{namespaceId}}',
7980
};
8081
let translation = translations[key] || key;
8182
if (options?.args) {

src/auth/api-key/api-key-auth.guard.spec.ts

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { Test, TestingModule } from '@nestjs/testing';
2-
import {
3-
ExecutionContext,
4-
UnauthorizedException,
5-
ForbiddenException,
6-
} from '@nestjs/common';
2+
import { ExecutionContext } from '@nestjs/common';
73
import { Reflector } from '@nestjs/core';
84
import { APIKeyAuthGuard } from 'omniboxd/auth';
95
import { APIKeyService } from 'omniboxd/api-key/api-key.service';
@@ -20,7 +16,6 @@ describe('APIKeyAuthGuard', () => {
2016
let guard: APIKeyAuthGuard;
2117
let apiKeyService: jest.Mocked<APIKeyService>;
2218
let reflector: jest.Mocked<Reflector>;
23-
let i18nService: jest.Mocked<I18nService>;
2419

2520
beforeEach(async () => {
2621
const module: TestingModule = await Test.createTestingModule({
@@ -44,11 +39,14 @@ describe('APIKeyAuthGuard', () => {
4439
t: jest.fn((key: string) => {
4540
// Return mock translations for test purposes
4641
const translations: Record<string, string> = {
47-
'apikey.errors.authorizationHeaderRequired': 'Authorization header is required',
42+
'apikey.errors.authorizationHeaderRequired':
43+
'Authorization header is required',
4844
'apikey.errors.invalidApiKeyFormat': 'Invalid API key format',
4945
'apikey.errors.invalidApiKey': 'Invalid API key',
50-
'apikey.errors.noPermissionForTarget': 'No permission for target {{target}}',
51-
'apikey.errors.noSpecificPermission': 'No {{permission}} permission for target {{target}}',
46+
'apikey.errors.noPermissionForTarget':
47+
'No permission for target {{target}}',
48+
'apikey.errors.noSpecificPermission':
49+
'No {{permission}} permission for target {{target}}',
5250
};
5351
return translations[key] || key;
5452
}),
@@ -60,7 +58,6 @@ describe('APIKeyAuthGuard', () => {
6058
guard = module.get<APIKeyAuthGuard>(APIKeyAuthGuard);
6159
apiKeyService = module.get(APIKeyService);
6260
reflector = module.get(Reflector);
63-
i18nService = module.get(I18nService);
6461
});
6562

6663
const createMockExecutionContext = (
@@ -111,9 +108,7 @@ describe('APIKeyAuthGuard', () => {
111108
.mockReturnValueOnce({ enabled: true }); // apiKeyAuthOptions = { enabled: true }
112109
const context = createMockExecutionContext();
113110

114-
await expect(guard.canActivate(context)).rejects.toThrow(
115-
AppException,
116-
);
111+
await expect(guard.canActivate(context)).rejects.toThrow(AppException);
117112
});
118113

119114
it('should throw AppException when API key does not start with sk-', async () => {
@@ -122,9 +117,7 @@ describe('APIKeyAuthGuard', () => {
122117
.mockReturnValueOnce({ enabled: true }); // apiKeyAuthOptions = { enabled: true }
123118
const context = createMockExecutionContext('Bearer invalid-key');
124119

125-
await expect(guard.canActivate(context)).rejects.toThrow(
126-
AppException,
127-
);
120+
await expect(guard.canActivate(context)).rejects.toThrow(AppException);
128121
});
129122

130123
it('should throw AppException when API key is not found', async () => {
@@ -134,9 +127,7 @@ describe('APIKeyAuthGuard', () => {
134127
const context = createMockExecutionContext('Bearer sk-validformat');
135128
apiKeyService.findByValue.mockResolvedValue(null);
136129

137-
await expect(guard.canActivate(context)).rejects.toThrow(
138-
AppException,
139-
);
130+
await expect(guard.canActivate(context)).rejects.toThrow(AppException);
140131
});
141132

142133
it('should allow valid API key and set apiKey and user on request', async () => {
@@ -245,9 +236,7 @@ describe('APIKeyAuthGuard', () => {
245236
const context = createMockExecutionContext('Bearer sk-validkey');
246237
apiKeyService.findByValue.mockResolvedValue(mockApiKey);
247238

248-
await expect(guard.canActivate(context)).rejects.toThrow(
249-
AppException,
250-
);
239+
await expect(guard.canActivate(context)).rejects.toThrow(AppException);
251240
});
252241

253242
it('should throw AppException when API key lacks specific permission type', async () => {
@@ -283,9 +272,7 @@ describe('APIKeyAuthGuard', () => {
283272
const context = createMockExecutionContext('Bearer sk-validkey');
284273
apiKeyService.findByValue.mockResolvedValue(mockApiKey);
285274

286-
await expect(guard.canActivate(context)).rejects.toThrow(
287-
AppException,
288-
);
275+
await expect(guard.canActivate(context)).rejects.toThrow(AppException);
289276
});
290277

291278
it('should allow API key with multiple matching permissions', async () => {

src/auth/api-key/api-key-auth.guard.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class APIKeyAuthGuard implements CanActivate {
7777
apiKeyAuthOptions.permissions &&
7878
apiKeyAuthOptions.permissions.length > 0
7979
) {
80-
await this.validatePermissions(
80+
this.validatePermissions(
8181
apiKey.attrs.permissions || [],
8282
apiKeyAuthOptions.permissions,
8383
);
@@ -90,10 +90,10 @@ export class APIKeyAuthGuard implements CanActivate {
9090
return true;
9191
}
9292

93-
private async validatePermissions(
93+
private validatePermissions(
9494
apiKeyPermissions: APIKeyPermission[],
9595
requiredPermissions: APIKeyPermission[],
96-
): Promise<void> {
96+
): void {
9797
for (const required of requiredPermissions) {
9898
const apiKeyPermission = apiKeyPermissions.find(
9999
(p) => p.target === required.target,

src/auth/auth.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export class AuthService {
288288
}
289289
}
290290

291-
async jwtVerify(token: string) {
291+
jwtVerify(token: string) {
292292
if (!token) {
293293
const message = this.i18n.t('auth.errors.noToken');
294294
throw new AppException(message, 'NO_TOKEN', HttpStatus.UNAUTHORIZED);

src/auth/cookie/cookie-auth.guard.spec.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Test, TestingModule } from '@nestjs/testing';
2-
import { ExecutionContext, UnauthorizedException } from '@nestjs/common';
2+
import { ExecutionContext } from '@nestjs/common';
33
import { Reflector } from '@nestjs/core';
44
import { CookieAuthGuard } from 'omniboxd/auth/cookie/cookie-auth.guard';
55
import { AuthService } from 'omniboxd/auth/auth.service';
@@ -10,7 +10,6 @@ describe('CookieAuthGuard', () => {
1010
let guard: CookieAuthGuard;
1111
let reflector: jest.Mocked<Reflector>;
1212
let authService: jest.Mocked<AuthService>;
13-
let i18nService: jest.Mocked<I18nService>;
1413

1514
beforeEach(async () => {
1615
const module: TestingModule = await Test.createTestingModule({
@@ -34,7 +33,8 @@ describe('CookieAuthGuard', () => {
3433
t: jest.fn((key: string) => {
3534
// Return mock translations for test purposes
3635
const translations: Record<string, string> = {
37-
'auth.errors.tokenCookieRequired': 'Authentication token cookie is required',
36+
'auth.errors.tokenCookieRequired':
37+
'Authentication token cookie is required',
3838
'auth.errors.tokenInvalid': 'Invalid or expired token',
3939
'auth.errors.invalidTokenPayload': 'Invalid token payload',
4040
};
@@ -48,7 +48,6 @@ describe('CookieAuthGuard', () => {
4848
guard = module.get<CookieAuthGuard>(CookieAuthGuard);
4949
reflector = module.get(Reflector);
5050
authService = module.get(AuthService);
51-
i18nService = module.get(I18nService);
5251
});
5352

5453
const createMockExecutionContext = (cookies: any = {}): ExecutionContext => {
@@ -94,9 +93,7 @@ describe('CookieAuthGuard', () => {
9493
.mockReturnValueOnce({ enabled: true }); // cookieAuthOptions with default onAuthFail = 'reject'
9594
const context = createMockExecutionContext();
9695

97-
await expect(guard.canActivate(context)).rejects.toThrow(
98-
AppException,
99-
);
96+
await expect(guard.canActivate(context)).rejects.toThrow(AppException);
10097
});
10198

10299
it('should throw AppException when token is invalid', async () => {
@@ -106,9 +103,7 @@ describe('CookieAuthGuard', () => {
106103
const context = createMockExecutionContext({ token: 'invalid-token' });
107104
authService.jwtVerify.mockRejectedValue(new Error('Invalid token'));
108105

109-
await expect(guard.canActivate(context)).rejects.toThrow(
110-
AppException,
111-
);
106+
await expect(guard.canActivate(context)).rejects.toThrow(AppException);
112107
});
113108

114109
it('should throw AppException when token payload is invalid', async () => {
@@ -118,9 +113,7 @@ describe('CookieAuthGuard', () => {
118113
const context = createMockExecutionContext({ token: 'valid-token' });
119114
authService.jwtVerify.mockResolvedValue({}); // No sub field
120115

121-
await expect(guard.canActivate(context)).rejects.toThrow(
122-
AppException,
123-
);
116+
await expect(guard.canActivate(context)).rejects.toThrow(AppException);
124117
});
125118

126119
it('should successfully authenticate with valid token and set cookie auth data', async () => {

src/auth/social.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { EntityManager } from 'typeorm';
22
import generateId from 'omniboxd/utils/generate-id';
33
import { UserService } from 'omniboxd/user/user.service';
44
import { WechatCheckResponseDto } from 'omniboxd/auth/dto/wechat-login.dto';
5-
import { HttpStatus, Inject, Injectable } from '@nestjs/common';
5+
import { HttpStatus, Injectable } from '@nestjs/common';
66
import { AppException } from 'omniboxd/common/exceptions/app.exception';
77
import { I18nService } from 'nestjs-i18n';
88
import { CacheService } from 'omniboxd/common/cache.service';

src/decorators/user-id.decorator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export const UserId = createParamDecorator(
1818

1919
if (!userId && !optional) {
2020
// Note: Decorators cannot easily inject I18nService, using static message
21-
throw new AppException('Not authorized', 'NOT_AUTHORIZED', HttpStatus.UNAUTHORIZED);
21+
throw new AppException(
22+
'Not authorized',
23+
'NOT_AUTHORIZED',
24+
HttpStatus.UNAUTHORIZED,
25+
);
2226
}
2327

2428
return userId;

src/feedback/feedback.controller.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ export class FeedbackController {
3535
if (file.mimetype.startsWith('image/')) {
3636
cb(null, true);
3737
} else {
38-
cb(new AppException('Only image files are allowed', 'ONLY_IMAGE_FILES_ALLOWED', HttpStatus.BAD_REQUEST), false);
38+
cb(
39+
new AppException(
40+
'Only image files are allowed',
41+
'ONLY_IMAGE_FILES_ALLOWED',
42+
HttpStatus.BAD_REQUEST,
43+
),
44+
false,
45+
);
3946
}
4047
},
4148
}),

src/permissions/permissions.controller.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import { PermissionDto } from './dto/permission.dto';
1515

1616
@Controller('api/v1/namespaces/:namespaceId/resources/:resourceId/permissions')
1717
export class PermissionsController {
18-
constructor(
19-
private readonly permissionsService: PermissionsService,
20-
) {}
18+
constructor(private readonly permissionsService: PermissionsService) {}
2119

2220
@Get()
2321
async listPermissions(

src/search/search.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ export class SearchService {
4343
const baseUrl = this.configService.get<string>('OBB_WIZARD_BASE_URL');
4444
if (!baseUrl) {
4545
const message = this.i18n.t('system.errors.missingWizardBaseUrl');
46-
throw new AppException(message, 'MISSING_WIZARD_BASE_URL', HttpStatus.INTERNAL_SERVER_ERROR);
46+
throw new AppException(
47+
message,
48+
'MISSING_WIZARD_BASE_URL',
49+
HttpStatus.INTERNAL_SERVER_ERROR,
50+
);
4751
}
4852
this.wizardApiService = new WizardAPIService(baseUrl, this.i18n);
4953
}

0 commit comments

Comments
 (0)