Skip to content

Commit 540e465

Browse files
committed
data seed removed from services
1 parent c6ccf8c commit 540e465

File tree

2 files changed

+22
-72
lines changed

2 files changed

+22
-72
lines changed

src/projects/projects.service.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,8 @@ export class ProjectsService {
1010
constructor(
1111
private prismaService: PrismaService,
1212
private buildsService: BuildsService,
13-
private testVariationsService: TestVariationsService,
14-
) {
15-
// create default project if there are none in DB
16-
this.findAll().then(projects => {
17-
if (projects.length === 0) {
18-
this.create({
19-
name: 'Default project'
20-
}).then(project => {
21-
console.log('##############################');
22-
console.log('## CREATING DEFAULT PROJECT ##');
23-
console.log('##############################');
24-
console.log('');
25-
console.log(`Project name ${project.name}`);
26-
console.log(`Project key: ${project.id}`);
27-
})
28-
}
29-
})
30-
}
13+
private testVariationsService: TestVariationsService
14+
) {}
3115

3216
async findAll(): Promise<Project[]> {
3317
return this.prismaService.project.findMany();
@@ -51,10 +35,9 @@ export class ProjectsService {
5135
});
5236

5337
try {
54-
await Promise.all(project.builds.map(build => this.buildsService.remove(build.id)));
38+
await Promise.all(project.builds.map((build) => this.buildsService.remove(build.id)));
5539
await Promise.all(
56-
project.testVariations.map(testVariation => this.testVariationsService.remove(testVariation.id)
57-
),
40+
project.testVariations.map((testVariation) => this.testVariationsService.remove(testVariation.id))
5841
);
5942
} catch (err) {
6043
console.log(err);

src/users/users.service.ts

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,7 @@ import { UserLoginRequestDto } from './dto/user-login-request.dto';
1010

1111
@Injectable()
1212
export class UsersService {
13-
constructor(private prismaService: PrismaService, private authService: AuthService) {
14-
// create default user if there are none in DB
15-
this.userList().then(userList => {
16-
if (userList.length === 0) {
17-
const defaultEmail = '[email protected]';
18-
const defaultPassword = '123456';
19-
20-
this.create({
21-
email: defaultEmail,
22-
password: defaultPassword,
23-
firstName: 'fname',
24-
lastName: 'lname'
25-
}).then(
26-
user => {
27-
console.log('###########################');
28-
console.log('## CREATING DEFAULT USER ##');
29-
console.log('###########################');
30-
console.log('');
31-
console.log(`The user with the email "${defaultEmail}" and password "${defaultPassword}" was created`);
32-
console.log(`The Api key is: ${user.apiKey}`);
33-
}
34-
);
35-
}
36-
});
37-
}
13+
constructor(private prismaService: PrismaService, private authService: AuthService) {}
3814

3915
userList(): Promise<User[]> {
4016
return this.prismaService.user.findMany();
@@ -57,23 +33,20 @@ export class UsersService {
5733
return new UserLoginResponseDto(userData, null);
5834
} catch (err) {
5935
if (err.original.constraint === 'user_email_key') {
60-
throw new HttpException(
61-
`User with email '${err.errors[0].value}' already exists`,
62-
HttpStatus.CONFLICT,
63-
);
36+
throw new HttpException(`User with email '${err.errors[0].value}' already exists`, HttpStatus.CONFLICT);
6437
}
6538

6639
throw new HttpException(err, HttpStatus.INTERNAL_SERVER_ERROR);
6740
}
6841
}
6942

7043
async findOne(id: string): Promise<User> {
71-
return this.prismaService.user.findOne({ where: { id } })
44+
return this.prismaService.user.findOne({ where: { id } });
7245
}
7346

7447
async get(id: string): Promise<UserDto> {
75-
const user = await this.findOne(id)
76-
return new UserDto(user)
48+
const user = await this.findOne(id);
49+
return new UserDto(user);
7750
}
7851

7952
async update(id: string, userDto: UpdateUserDto): Promise<UserLoginResponseDto> {
@@ -83,51 +56,45 @@ export class UsersService {
8356
email: userDto.email,
8457
firstName: userDto.firstName,
8558
lastName: userDto.lastName,
86-
}
87-
})
59+
},
60+
});
8861
const token = this.authService.signToken(user);
8962
return new UserLoginResponseDto(user, token);
9063
}
9164

9265
async generateNewApiKey(user: User): Promise<string> {
93-
const newApiKey = this.authService.generateApiKey()
66+
const newApiKey = this.authService.generateApiKey();
9467
await this.prismaService.user.update({
9568
where: { id: user.id },
9669
data: {
97-
apiKey: newApiKey
98-
}
99-
})
70+
apiKey: newApiKey,
71+
},
72+
});
10073
return newApiKey;
10174
}
10275

10376
async changePassword(user: User, newPassword: string): Promise<boolean> {
10477
await this.prismaService.user.update({
10578
where: { id: user.id },
10679
data: {
107-
password: await this.authService.encryptPassword(newPassword)
108-
}
109-
})
80+
password: await this.authService.encryptPassword(newPassword),
81+
},
82+
});
11083
return true;
11184
}
11285

11386
async login(userLoginRequestDto: UserLoginRequestDto) {
11487
const user = await this.prismaService.user.findOne({
115-
where: { email: userLoginRequestDto.email }
116-
})
88+
where: { email: userLoginRequestDto.email },
89+
});
11790
if (!user) {
118-
throw new HttpException(
119-
'Invalid email or password.',
120-
HttpStatus.BAD_REQUEST,
121-
);
91+
throw new HttpException('Invalid email or password.', HttpStatus.BAD_REQUEST);
12292
}
12393

12494
const isMatch = await this.authService.compare(userLoginRequestDto.password, user.password);
12595

12696
if (!isMatch) {
127-
throw new HttpException(
128-
'Invalid email or password.',
129-
HttpStatus.BAD_REQUEST,
130-
);
97+
throw new HttpException('Invalid email or password.', HttpStatus.BAD_REQUEST);
13198
}
13299

133100
const token = this.authService.signToken(user);

0 commit comments

Comments
 (0)