Hozifa Elgherbawy commited on
Commit
329acb2
·
unverified ·
2 Parent(s): e7864c7 ff0ecdf

Merge pull request #73 from Modarb-Ai-Trainer:validation

Browse files
src/modules/console/modules/users/services/users.service.ts CHANGED
@@ -1,4 +1,13 @@
1
- import { User } from "@common/models/user.model";
 
2
  import { CrudService } from "@lib/services/crud.service";
 
3
 
4
- export class UsersService extends CrudService(User) {}
 
 
 
 
 
 
 
 
1
+ import { User, UserDocument } from "@common/models/user.model";
2
+ import { HttpError } from "@lib/error-handling/http-error";
3
  import { CrudService } from "@lib/services/crud.service";
4
+ import { AnyKeys } from "mongoose";
5
 
6
+ export class UsersService extends CrudService(User) {
7
+ create(data: any): Promise<UserDocument> {
8
+ if(data.password !== data.confirmPassword) {
9
+ throw new HttpError(400, "passwords do not match");
10
+ }
11
+ return super.create(data);
12
+ }
13
+ }
src/modules/users/modules/auth/services/users-auth.service.ts CHANGED
@@ -8,13 +8,16 @@ import { CrudService } from "@lib/services/crud.service";
8
 
9
  export class UsersAuthService extends CrudService(User) {
10
  async register(createParams: IUserRegister) {
 
 
 
11
  return this.create(createParams);
12
  }
13
 
14
  async login(loginRequest: ILogin) {
15
  const user = await this.findOne({ email: loginRequest.email });
16
  if (!user) throw new HttpError(401, "Invalid Credentials");
17
-
18
  const isPasswordCorrect = await bcrypt.compare(
19
  loginRequest.password,
20
  user.password
 
8
 
9
  export class UsersAuthService extends CrudService(User) {
10
  async register(createParams: IUserRegister) {
11
+ if (createParams.password !== createParams.confirmPassword) {
12
+ throw new HttpError(400, "passwords do not match");
13
+ }
14
  return this.create(createParams);
15
  }
16
 
17
  async login(loginRequest: ILogin) {
18
  const user = await this.findOne({ email: loginRequest.email });
19
  if (!user) throw new HttpError(401, "Invalid Credentials");
20
+
21
  const isPasswordCorrect = await bcrypt.compare(
22
  loginRequest.password,
23
  user.password
src/modules/users/modules/exercises/controllers/exercises.controller.ts CHANGED
@@ -47,7 +47,7 @@ export class UsersExerciseController extends BaseController {
47
  { path: "equipments" }
48
  ]
49
  }
50
- );
51
 
52
  return JsonResponse.success(
53
  {
 
47
  { path: "equipments" }
48
  ]
49
  }
50
+ );
51
 
52
  return JsonResponse.success(
53
  {