Skip to content

Commit adf09fe

Browse files
committed
feat: reformat code
1 parent bcd1685 commit adf09fe

File tree

76 files changed

+216
-596
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+216
-596
lines changed

.prettierrc

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
{
2+
"printWidth": 120,
23
"singleQuote": true,
3-
"trailingComma": "all",
4-
"printWidth": 100,
5-
"tabWidth": 2,
6-
"semi": true,
7-
"bracketSpacing": true,
8-
"arrowParens": "avoid",
9-
"endOfLine": "lf",
10-
"useTabs": false,
11-
"quoteProps": "as-needed",
12-
"jsxSingleQuote": false,
13-
"bracketSameLine": false,
14-
"proseWrap": "preserve",
15-
"htmlWhitespaceSensitivity": "css",
16-
"embeddedLanguageFormatting": "auto"
4+
"trailingComma": "all"
175
}

src/application/commands/admin/change-password.command.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ export class AdminChangePasswordCommand extends Command<void> {
1414

1515
@Injectable()
1616
@CommandHandler(AdminChangePasswordCommand)
17-
export class AdminChangePasswordCommandHandler
18-
implements ICommandHandler<AdminChangePasswordCommand>
19-
{
17+
export class AdminChangePasswordCommandHandler implements ICommandHandler<AdminChangePasswordCommand> {
2018
constructor(
2119
private readonly userService: UserService,
2220
@Inject(LoggerService) private readonly logger: LoggerService,

src/application/commands/auth/login.command.spec.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,7 @@ const mockLoggerService = {
5959

6060
// Create utility functions for test data
6161
const createTestUser = (): User => {
62-
const user = User.create(
63-
new Email('[email protected]'),
64-
'hashedPassword',
65-
new FirstName('John'),
66-
new LastName('Doe'),
67-
);
62+
const user = User.create(new Email('[email protected]'), 'hashedPassword', new FirstName('John'), new LastName('Doe'));
6863

6964
// Add roles
7065
const role = Role.fromData({
@@ -141,7 +136,7 @@ describe('LoginCommandHandler', () => {
141136
firstName: user.firstName.getValue(),
142137
lastName: user.lastName.getValue(),
143138
emailVerified: emailVerified || false,
144-
roles: user.roles.map(role => ({
139+
roles: user.roles.map((role) => ({
145140
id: role.id.getValue(),
146141
name: role.name,
147142
})),
@@ -164,10 +159,7 @@ describe('LoginCommandHandler', () => {
164159

165160
// Act & Assert
166161
await expect(handler.execute(command)).rejects.toThrow(UnauthorizedException);
167-
expect(userService.validateCredentials).toHaveBeenCalledWith(
168-
169-
'wrongPassword',
170-
);
162+
expect(userService.validateCredentials).toHaveBeenCalledWith('[email protected]', 'wrongPassword');
171163
});
172164

173165
it('should return email verification required response when email is not verified', async () => {
@@ -193,10 +185,7 @@ describe('LoginCommandHandler', () => {
193185
message: 'Email verification required',
194186
});
195187

196-
expect(userService.validateCredentials).toHaveBeenCalledWith(
197-
198-
'Password123!',
199-
);
188+
expect(userService.validateCredentials).toHaveBeenCalledWith('[email protected]', 'Password123!');
200189
expect(authService.updateLastLogin).toHaveBeenCalledWith(user.id.getValue());
201190
expect(authService.isEmailVerified).toHaveBeenCalledWith('[email protected]');
202191
});
@@ -225,10 +214,7 @@ describe('LoginCommandHandler', () => {
225214
message: 'OTP verification required',
226215
});
227216

228-
expect(userService.validateCredentials).toHaveBeenCalledWith(
229-
230-
'Password123!',
231-
);
217+
expect(userService.validateCredentials).toHaveBeenCalledWith('[email protected]', 'Password123!');
232218
expect(authService.updateLastLogin).toHaveBeenCalledWith(user.id.getValue());
233219
expect(authService.isEmailVerified).toHaveBeenCalledWith('[email protected]');
234220
});
@@ -266,10 +252,7 @@ describe('LoginCommandHandler', () => {
266252
}),
267253
});
268254

269-
expect(userService.validateCredentials).toHaveBeenCalledWith(
270-
271-
'Password123!',
272-
);
255+
expect(userService.validateCredentials).toHaveBeenCalledWith('[email protected]', 'Password123!');
273256
expect(authService.updateLastLogin).toHaveBeenCalledWith(user.id.getValue());
274257
expect(authService.isEmailVerified).toHaveBeenCalledWith('[email protected]');
275258
expect(roleRepository.findById).toHaveBeenCalledWith(user.roles[0].id.getValue());
@@ -328,7 +311,7 @@ describe('LoginCommandHandler', () => {
328311
mockAuthService.isEmailVerified.mockResolvedValue(true);
329312

330313
// Mock repository to return different roles based on role id
331-
mockRoleRepository.findById.mockImplementation(roleId => {
314+
mockRoleRepository.findById.mockImplementation((roleId) => {
332315
if (roleId === '550e8400-e29b-41d4-a716-446655440001') {
333316
return Promise.resolve(userRoleWithPermissions);
334317
} else if (roleId === '550e8400-e29b-41d4-a716-446655440003') {

src/application/commands/auth/login.command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class LoginCommandHandler implements ICommandHandler<LoginCommand> {
9797
for (const role of user.roles) {
9898
const roleWithPermissions = await this.roleRepository.findById(role.id.getValue());
9999
if (roleWithPermissions && roleWithPermissions.permissions) {
100-
roleWithPermissions.permissions.forEach(permission => {
100+
roleWithPermissions.permissions.forEach((permission) => {
101101
userPermissions.add(permission.getStringName());
102102
});
103103
}
@@ -106,7 +106,7 @@ export class LoginCommandHandler implements ICommandHandler<LoginCommand> {
106106
this.logger.debug({
107107
message: 'User permissions collected',
108108
userId: user.id.getValue(),
109-
roles: user.roles.map(r => r.name),
109+
roles: user.roles.map((r) => r.name),
110110
permissionsCount: userPermissions.size,
111111
});
112112

src/application/commands/auth/refresh-token.command.spec.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,7 @@ const mockLoggerService = {
6666

6767
// Create test data
6868
const createTestUser = (): User => {
69-
const user = User.create(
70-
new Email('[email protected]'),
71-
'hashedPassword',
72-
new FirstName('John'),
73-
new LastName('Doe'),
74-
);
69+
const user = User.create(new Email('[email protected]'), 'hashedPassword', new FirstName('John'), new LastName('Doe'));
7570

7671
// Add role - need to use fromData method to set ID
7772
const role = Role.fromData({
@@ -181,13 +176,9 @@ describe('RefreshTokenCommandHandler', () => {
181176
userId: '550e8400-e29b-41d4-a716-446655440010',
182177
});
183178

184-
expect(authService.validateRefreshToken).toHaveBeenCalledWith(
185-
'550e8400-e29b-41d4-a716-446655440005',
186-
);
179+
expect(authService.validateRefreshToken).toHaveBeenCalledWith('550e8400-e29b-41d4-a716-446655440005');
187180
expect(userRepository.findById).toHaveBeenCalledWith('550e8400-e29b-41d4-a716-446655440000');
188-
expect(authService.revokeRefreshToken).toHaveBeenCalledWith(
189-
'550e8400-e29b-41d4-a716-446655440005',
190-
);
181+
expect(authService.revokeRefreshToken).toHaveBeenCalledWith('550e8400-e29b-41d4-a716-446655440005');
191182
expect(roleRepository.findById).toHaveBeenCalledWith('550e8400-e29b-41d4-a716-446655440001');
192183
expect(authService.isEmailVerified).toHaveBeenCalledWith('[email protected]');
193184

@@ -222,9 +213,7 @@ describe('RefreshTokenCommandHandler', () => {
222213

223214
// Act & Assert
224215
await expect(handler.execute(command)).rejects.toThrow(UnauthorizedException);
225-
expect(authService.validateRefreshToken).toHaveBeenCalledWith(
226-
'550e8400-e29b-41d4-a716-446655440006',
227-
);
216+
expect(authService.validateRefreshToken).toHaveBeenCalledWith('550e8400-e29b-41d4-a716-446655440006');
228217
expect(userRepository.findById).not.toHaveBeenCalled();
229218
});
230219

@@ -241,9 +230,7 @@ describe('RefreshTokenCommandHandler', () => {
241230

242231
// Act & Assert
243232
await expect(handler.execute(command)).rejects.toThrow(UnauthorizedException);
244-
expect(authService.validateRefreshToken).toHaveBeenCalledWith(
245-
'550e8400-e29b-41d4-a716-446655440005',
246-
);
233+
expect(authService.validateRefreshToken).toHaveBeenCalledWith('550e8400-e29b-41d4-a716-446655440005');
247234
expect(userRepository.findById).toHaveBeenCalledWith('550e8400-e29b-41d4-a716-446655440000');
248235
expect(authService.revokeRefreshToken).not.toHaveBeenCalled();
249236
});
@@ -300,7 +287,7 @@ describe('RefreshTokenCommandHandler', () => {
300287
mockAuthService.isEmailVerified.mockResolvedValue(true);
301288

302289
// Mock repository to return different roles based on role id
303-
mockRoleRepository.findById.mockImplementation(roleId => {
290+
mockRoleRepository.findById.mockImplementation((roleId) => {
304291
if (roleId === '550e8400-e29b-41d4-a716-446655440001') {
305292
return Promise.resolve(userRoleWithPermissions);
306293
} else if (roleId === '550e8400-e29b-41d4-a716-446655440003') {

src/application/commands/auth/refresh-token.command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class RefreshTokenCommandHandler implements ICommandHandler<RefreshTokenC
5151
for (const role of user.roles) {
5252
const roleWithPermissions = await this.roleRepository.findById(role.id.getValue());
5353
if (roleWithPermissions && roleWithPermissions.permissions) {
54-
roleWithPermissions.permissions.forEach(permission => {
54+
roleWithPermissions.permissions.forEach((permission) => {
5555
userPermissions.add(permission.getStringName());
5656
});
5757
}
@@ -65,7 +65,7 @@ export class RefreshTokenCommandHandler implements ICommandHandler<RefreshTokenC
6565
sub: user.id.getValue(),
6666
email: user.email.getValue(),
6767
emailVerified: isEmailVerified,
68-
roles: user.roles.map(role => role.name),
68+
roles: user.roles.map((role) => role.name),
6969
permissions: Array.from(userPermissions),
7070
};
7171

src/application/commands/auth/register-user.command.spec.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('RegisterUserCommandHandler', () => {
4343
userService = module.get<UserService>(UserService);
4444

4545
// Mock UserMapper
46-
jest.spyOn(UserMapper, 'toBaseResponse').mockImplementation(user => {
46+
jest.spyOn(UserMapper, 'toBaseResponse').mockImplementation((user) => {
4747
return {
4848
id: user.id.getValue(),
4949
email: user.email.getValue(),
@@ -86,12 +86,7 @@ describe('RegisterUserCommandHandler', () => {
8686
lastName: createdUser.lastName.getValue(),
8787
});
8888

89-
expect(userService.createUser).toHaveBeenCalledWith(
90-
91-
'Password123!',
92-
'New',
93-
'User',
94-
);
89+
expect(userService.createUser).toHaveBeenCalledWith('[email protected]', 'Password123!', 'New', 'User');
9590

9691
expect(UserMapper.toBaseResponse).toHaveBeenCalledWith(createdUser);
9792
});
@@ -111,11 +106,6 @@ describe('RegisterUserCommandHandler', () => {
111106
// Act & Assert
112107
await expect(handler.execute(command)).rejects.toThrow(error);
113108

114-
expect(userService.createUser).toHaveBeenCalledWith(
115-
116-
'Password123!',
117-
'Existing',
118-
'User',
119-
);
109+
expect(userService.createUser).toHaveBeenCalledWith('[email protected]', 'Password123!', 'Existing', 'User');
120110
});
121111
});

src/application/commands/auth/request-password-reset.command.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ export class RequestPasswordResetCommand extends Command<{ message: string }> {
1313

1414
@Injectable()
1515
@CommandHandler(RequestPasswordResetCommand)
16-
export class RequestPasswordResetCommandHandler
17-
implements ICommandHandler<RequestPasswordResetCommand>
18-
{
16+
export class RequestPasswordResetCommandHandler implements ICommandHandler<RequestPasswordResetCommand> {
1917
constructor(
2018
private readonly authService: AuthService,
2119
private readonly emailProvider: EmailProvider,
@@ -36,8 +34,7 @@ export class RequestPasswordResetCommandHandler
3634
if (error instanceof EntityNotFoundException) {
3735
// For security reasons, we don't want to reveal whether an email exists in our system
3836
return {
39-
message:
40-
'If your email exists in our system, you will receive a password reset link shortly',
37+
message: 'If your email exists in our system, you will receive a password reset link shortly',
4138
};
4239
}
4340
throw error;

src/application/commands/auth/reset-password.command.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { ResetPasswordRequest } from '@application/dtos';
2-
import {
3-
EntityNotFoundException,
4-
OtpExpiredException,
5-
OtpInvalidException,
6-
} from '@core/exceptions/domain-exceptions';
2+
import { EntityNotFoundException, OtpExpiredException, OtpInvalidException } from '@core/exceptions/domain-exceptions';
73
import { AuthService } from '@core/services/auth.service';
84
import { UserService } from '@core/services/user.service';
95
import { BadRequestException, Injectable, UnauthorizedException } from '@nestjs/common';

src/application/commands/auth/send-verification-email.command.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ export class SendVerificationEmailCommand extends Command<{ message: string }> {
1212

1313
@Injectable()
1414
@CommandHandler(SendVerificationEmailCommand)
15-
export class SendVerificationEmailCommandHandler
16-
implements ICommandHandler<SendVerificationEmailCommand>
17-
{
15+
export class SendVerificationEmailCommandHandler implements ICommandHandler<SendVerificationEmailCommand> {
1816
constructor(
1917
private readonly authService: AuthService,
2018
private readonly emailProvider: EmailProvider,

0 commit comments

Comments
 (0)