rez_core 1.0.99 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "1.0.99",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -22,7 +22,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
22
22
  }
23
23
 
24
24
  async validate(payload) {
25
- const { userId, sessionToken } = payload;
25
+ const { userId, sessionToken,appcode } = payload;
26
26
 
27
27
  // Check if session exists and is valid
28
28
  const userSession = await this.userSessionRepository.findOne({
@@ -37,6 +37,6 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
37
37
  throw new UnauthorizedException('Invalid or expired session');
38
38
  }
39
39
 
40
- return { userId, sessionToken };
40
+ return { userId, sessionToken ,appcode};
41
41
  }
42
42
  }
@@ -20,11 +20,11 @@ export class LoginController {
20
20
  @Post('login')
21
21
 
22
22
  async login(@Body() body, @Res() res: Response) {
23
- return res
24
- .status(HttpStatus.OK)
25
- .json(await this.loginService.login(body.email_id, body.password));
26
-
23
+ const { email_id, password, appcode,organization_id} = body;
24
+ const result = await this.loginService.login(email_id, password, appcode,organization_id);
25
+ return res.status(HttpStatus.OK).json(result);
27
26
  }
27
+
28
28
 
29
29
  @UseGuards(JwtAuthGuard)
30
30
  @Post('logout')
@@ -13,34 +13,41 @@ export class UserRepository {
13
13
  async findById(userId: number): Promise<UserData | null> {
14
14
  return this.userRepository.findOne({ where: { id: userId } });
15
15
  }
16
-
17
16
  async findByEmailId(
18
17
  email: string,
19
18
  organization_id?: number,
19
+ appCode?: string,
20
20
  ): Promise<UserData | null> {
21
21
  if (!email) return null;
22
-
22
+
23
23
  const where: any = { email_id: email };
24
24
  if (organization_id !== undefined) {
25
25
  where.organization_id = organization_id;
26
26
  }
27
-
27
+ if (appCode !== undefined) {
28
+ where.appcode = appCode;
29
+ }
28
30
  return this.userRepository.findOne({ where });
29
31
  }
30
-
32
+
31
33
  async findByMobile(
32
34
  mobile: string,
33
35
  organization_id?: number,
36
+ appCode?: string,
34
37
  ): Promise<UserData | null> {
35
38
  if (!mobile) return null;
36
-
39
+
37
40
  const where: any = { mobile };
38
41
  if (organization_id !== undefined) {
39
42
  where.organization_id = organization_id;
40
43
  }
41
-
44
+ if (appCode !== undefined) {
45
+ where.appcode = appCode;
46
+ }
47
+
42
48
  return this.userRepository.findOne({ where });
43
49
  }
50
+
44
51
 
45
52
  async saveUser(user: UserData): Promise<UserData> {
46
53
  return this.userRepository.save(user);
@@ -16,8 +16,8 @@ export class LoginService {
16
16
  masterKey: string = this.configService.get('MASTER_KEY') || '';
17
17
  masterIv: string = this.configService.get('MASTER_IV') || '';
18
18
 
19
- async login(email: string, password: string) {
20
- const user = await this.userService.findByEmailId(email);
19
+ async login(email: string, password: string,appcode:string,organization_id) {
20
+ const user = await this.userService.findByEmailId(email,organization_id,appcode);
21
21
  if (!user) {
22
22
  return {
23
23
  success: false,
@@ -28,7 +28,7 @@ export class UserSessionService {
28
28
 
29
29
  await this.userSessionRepository.saveSession(userSession);
30
30
 
31
- const payload = { userId: user.id, sessionToken };
31
+ const payload = { userId: user.id, sessionToken, appcode: user.appcode };
32
32
  const accessToken = this.jwtAuthService.generateJwt(payload);
33
33
 
34
34
  userSession.access_token = accessToken;
@@ -165,11 +165,11 @@ export class UserService extends EntityServiceImpl {
165
165
  return savedData;
166
166
  }
167
167
 
168
- async findByEmailId(email_id: string): Promise<UserData | null> {
169
- return await this.userRepository.findByEmailId(email_id);
168
+ async findByEmailId(email_id: string,organization_id?: number,appCode?:string): Promise<UserData | null> {
169
+ return await this.userRepository.findByEmailId(email_id,organization_id,appCode);
170
170
  }
171
171
 
172
- async findByMobile(mobile: string): Promise<UserData | null> {
173
- return await this.userRepository.findByMobile(mobile);
172
+ async findByMobile(mobile: string,organization_id?: number,appCode?:string): Promise<UserData | null> {
173
+ return await this.userRepository.findByMobile(mobile,organization_id,appCode);
174
174
  }
175
175
  }