@solidstarters/solid-core 1.2.121 → 1.2.123

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.
Files changed (97) hide show
  1. package/dist/controllers/authentication.controller.d.ts +3 -1
  2. package/dist/controllers/authentication.controller.d.ts.map +1 -1
  3. package/dist/controllers/setting.controller.d.ts +6 -3
  4. package/dist/controllers/setting.controller.d.ts.map +1 -1
  5. package/dist/controllers/setting.controller.js +32 -5
  6. package/dist/controllers/setting.controller.js.map +1 -1
  7. package/dist/controllers/user-activity-history.controller.d.ts +43 -0
  8. package/dist/controllers/user-activity-history.controller.d.ts.map +1 -0
  9. package/dist/controllers/user-activity-history.controller.js +179 -0
  10. package/dist/controllers/user-activity-history.controller.js.map +1 -0
  11. package/dist/controllers/user.controller.d.ts +2 -0
  12. package/dist/controllers/user.controller.d.ts.map +1 -1
  13. package/dist/controllers/user.controller.js +19 -0
  14. package/dist/controllers/user.controller.js.map +1 -1
  15. package/dist/dtos/create-setting.dto.d.ts +3 -0
  16. package/dist/dtos/create-setting.dto.d.ts.map +1 -1
  17. package/dist/dtos/create-setting.dto.js +19 -1
  18. package/dist/dtos/create-setting.dto.js.map +1 -1
  19. package/dist/dtos/create-user-activity-history.dto.d.ts +8 -0
  20. package/dist/dtos/create-user-activity-history.dto.d.ts.map +1 -0
  21. package/dist/dtos/create-user-activity-history.dto.js +54 -0
  22. package/dist/dtos/create-user-activity-history.dto.js.map +1 -0
  23. package/dist/dtos/update-setting.dto.d.ts +3 -0
  24. package/dist/dtos/update-setting.dto.d.ts.map +1 -1
  25. package/dist/dtos/update-setting.dto.js +19 -1
  26. package/dist/dtos/update-setting.dto.js.map +1 -1
  27. package/dist/dtos/update-user-activity-history.dto.d.ts +9 -0
  28. package/dist/dtos/update-user-activity-history.dto.d.ts.map +1 -0
  29. package/dist/dtos/update-user-activity-history.dto.js +57 -0
  30. package/dist/dtos/update-user-activity-history.dto.js.map +1 -0
  31. package/dist/dtos/update-user-profile.dto.d.ts +7 -0
  32. package/dist/dtos/update-user-profile.dto.d.ts.map +1 -0
  33. package/dist/dtos/update-user-profile.dto.js +41 -0
  34. package/dist/dtos/update-user-profile.dto.js.map +1 -0
  35. package/dist/dtos/update-user.dto.d.ts.map +1 -1
  36. package/dist/dtos/update-user.dto.js +1 -16
  37. package/dist/dtos/update-user.dto.js.map +1 -1
  38. package/dist/entities/setting.entity.d.ts +3 -0
  39. package/dist/entities/setting.entity.d.ts.map +1 -1
  40. package/dist/entities/setting.entity.js +11 -1
  41. package/dist/entities/setting.entity.js.map +1 -1
  42. package/dist/entities/user-activity-history.entity.d.ts +9 -0
  43. package/dist/entities/user-activity-history.entity.d.ts.map +1 -0
  44. package/dist/entities/user-activity-history.entity.js +46 -0
  45. package/dist/entities/user-activity-history.entity.js.map +1 -0
  46. package/dist/guards/authentication.guard.d.ts +3 -1
  47. package/dist/guards/authentication.guard.d.ts.map +1 -1
  48. package/dist/guards/authentication.guard.js +11 -2
  49. package/dist/guards/authentication.guard.js.map +1 -1
  50. package/dist/index.d.ts +4 -0
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +4 -0
  53. package/dist/index.js.map +1 -1
  54. package/dist/seeders/seed-data/solid-core-metadata.json +325 -0
  55. package/dist/services/authentication.service.d.ts +8 -2
  56. package/dist/services/authentication.service.d.ts.map +1 -1
  57. package/dist/services/authentication.service.js +26 -2
  58. package/dist/services/authentication.service.js.map +1 -1
  59. package/dist/services/import-transaction.service.js +1 -1
  60. package/dist/services/import-transaction.service.js.map +1 -1
  61. package/dist/services/request-context.service.d.ts +2 -0
  62. package/dist/services/request-context.service.d.ts.map +1 -1
  63. package/dist/services/request-context.service.js +6 -0
  64. package/dist/services/request-context.service.js.map +1 -1
  65. package/dist/services/setting.service.d.ts +11 -3
  66. package/dist/services/setting.service.d.ts.map +1 -1
  67. package/dist/services/setting.service.js +86 -60
  68. package/dist/services/setting.service.js.map +1 -1
  69. package/dist/services/user-activity-history.service.d.ts +26 -0
  70. package/dist/services/user-activity-history.service.d.ts.map +1 -0
  71. package/dist/services/user-activity-history.service.js +69 -0
  72. package/dist/services/user-activity-history.service.js.map +1 -0
  73. package/dist/solid-core.module.d.ts.map +1 -1
  74. package/dist/solid-core.module.js +8 -1
  75. package/dist/solid-core.module.js.map +1 -1
  76. package/dist/tsconfig.tsbuildinfo +1 -1
  77. package/package.json +1 -1
  78. package/src/controllers/setting.controller.ts +32 -4
  79. package/src/controllers/user-activity-history.controller.ts +93 -0
  80. package/src/controllers/user.controller.ts +12 -1
  81. package/src/dtos/create-setting.dto.ts +13 -1
  82. package/src/dtos/create-user-activity-history.dto.ts +30 -0
  83. package/src/dtos/update-setting.dto.ts +13 -1
  84. package/src/dtos/update-user-activity-history.dto.ts +32 -0
  85. package/src/dtos/update-user-profile.dto.ts +19 -0
  86. package/src/dtos/update-user.dto.ts +13 -13
  87. package/src/entities/setting.entity.ts +7 -1
  88. package/src/entities/user-activity-history.entity.ts +21 -0
  89. package/src/guards/authentication.guard.ts +12 -1
  90. package/src/index.ts +7 -0
  91. package/src/seeders/seed-data/solid-core-metadata.json +325 -0
  92. package/src/services/authentication.service.ts +45 -12
  93. package/src/services/import-transaction.service.ts +1 -1
  94. package/src/services/request-context.service.ts +8 -0
  95. package/src/services/setting.service.ts +103 -71
  96. package/src/services/user-activity-history.service.ts +49 -0
  97. package/src/solid-core.module.ts +8 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidstarters/solid-core",
3
- "version": "1.2.121",
3
+ "version": "1.2.123",
4
4
  "description": "This module is a NestJS module containing all the required core providers required by a Solid application",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import { Controller, Post, Body, Param, UploadedFiles, UseInterceptors, Put, Get, Query, Delete, Patch } from '@nestjs/common';
1
+ import { Controller, Post, Body, Param, UploadedFiles, UseInterceptors, Put, Get, Query, Delete, Patch, ParseArrayPipe, BadRequestException } from '@nestjs/common';
2
2
  import { AnyFilesInterceptor } from "@nestjs/platform-express";
3
3
  import { ApiBearerAuth, ApiQuery, ApiTags } from '@nestjs/swagger';
4
4
  import { SettingService } from '../services/setting.service';
@@ -89,7 +89,35 @@ export class SettingController {
89
89
  @ApiBearerAuth("jwt")
90
90
  @Post('/bulk-update')
91
91
  @UseInterceptors(AnyFilesInterceptor())
92
- async updateSettings(@Body() updateSettingsDto: UpdateSettingsDto, @UploadedFiles() files: Array<Express.Multer.File>) {
93
- return this.service.updateSettings(updateSettingsDto.settings, files);
92
+ async updateSettings(
93
+ @Body() body: any,
94
+ @UploadedFiles() files: Array<Express.Multer.File>
95
+ ) {
96
+ let settings: CreateSettingDto[] = [];
97
+
98
+ try {
99
+ settings = typeof body.settings === 'string' ? JSON.parse(body.settings) : body.settings;
100
+ } catch (e) {
101
+ throw new BadRequestException('Invalid settings payload');
102
+ }
103
+ return this.service.updateSettings(settings, files);
104
+ }
105
+
106
+
107
+ @ApiBearerAuth("jwt")
108
+ @Post('/bulk/user')
109
+ @UseInterceptors(AnyFilesInterceptor())
110
+ async updateUserSettings(
111
+ @Body() body: any,
112
+ @UploadedFiles() files: Array<Express.Multer.File>
113
+ ) {
114
+ let settings: CreateSettingDto[] = [];
115
+
116
+ try {
117
+ settings = typeof body.settings === 'string' ? JSON.parse(body.settings) : body.settings;
118
+ } catch (e) {
119
+ throw new BadRequestException('Invalid settings payload');
120
+ }
121
+ return this.service.updateSettings(settings, files);
94
122
  }
95
- }
123
+ }
@@ -0,0 +1,93 @@
1
+ import { Controller, Post, Body, Param, UploadedFiles, UseInterceptors, Put, Get, Query, Delete, Patch } from '@nestjs/common';
2
+ import { AnyFilesInterceptor } from "@nestjs/platform-express";
3
+ import { ApiBearerAuth, ApiQuery, ApiTags } from '@nestjs/swagger';
4
+ import { UserActivityHistoryService } from '../services/user-activity-history.service';
5
+ import { CreateUserActivityHistoryDto } from '../dtos/create-user-activity-history.dto';
6
+ import { UpdateUserActivityHistoryDto } from '../dtos/update-user-activity-history.dto';
7
+
8
+ enum ShowSoftDeleted {
9
+ INCLUSIVE = "inclusive",
10
+ EXCLUSIVE = "exclusive",
11
+ }
12
+
13
+ @ApiTags('Solid Core')
14
+ @Controller('user-activity-history')
15
+ export class UserActivityHistoryController {
16
+ constructor(private readonly service: UserActivityHistoryService) {}
17
+
18
+ @ApiBearerAuth("jwt")
19
+ @Post()
20
+ @UseInterceptors(AnyFilesInterceptor())
21
+ create(@Body() createDto: CreateUserActivityHistoryDto, @UploadedFiles() files: Array<Express.Multer.File>) {
22
+ return this.service.create(createDto, files);
23
+ }
24
+
25
+ @ApiBearerAuth("jwt")
26
+ @Post('/bulk')
27
+ @UseInterceptors(AnyFilesInterceptor())
28
+ insertMany(@Body() createDtos: CreateUserActivityHistoryDto[], @UploadedFiles() filesArray: Express.Multer.File[][] = []) {
29
+ return this.service.insertMany(createDtos, filesArray);
30
+ }
31
+
32
+
33
+ @ApiBearerAuth("jwt")
34
+ @Put(':id')
35
+ @UseInterceptors(AnyFilesInterceptor())
36
+ update(@Param('id') id: number, @Body() updateDto: UpdateUserActivityHistoryDto, @UploadedFiles() files: Array<Express.Multer.File>) {
37
+ return this.service.update(id, updateDto, files);
38
+ }
39
+
40
+ @ApiBearerAuth("jwt")
41
+ @Patch(':id')
42
+ @UseInterceptors(AnyFilesInterceptor())
43
+ partialUpdate(@Param('id') id: number, @Body() updateDto: UpdateUserActivityHistoryDto, @UploadedFiles() files: Array<Express.Multer.File>) {
44
+ return this.service.update(id, updateDto, files, true);
45
+ }
46
+
47
+ @ApiBearerAuth("jwt")
48
+ @Post('/bulk-recover')
49
+ async recoverMany(@Body() ids: number[]) {
50
+ return this.service.recoverMany(ids);
51
+ }
52
+
53
+ @ApiBearerAuth("jwt")
54
+ @Get('/recover/:id')
55
+ async recover(@Param('id') id: number) {
56
+ return this.service.recover(id);
57
+ }
58
+
59
+ @ApiBearerAuth("jwt")
60
+ @ApiQuery({ name: 'showSoftDeleted', required: false, enum: ShowSoftDeleted })
61
+ @ApiQuery({ name: 'limit', required: false, type: Number })
62
+ @ApiQuery({ name: 'offset', required: false, type: Number })
63
+ @ApiQuery({ name: 'fields', required: false, type: Array })
64
+ @ApiQuery({ name: 'sort', required: false, type: Array })
65
+ @ApiQuery({ name: 'groupBy', required: false, type: Array })
66
+ @ApiQuery({ name: 'populate', required: false, type: Array })
67
+ @ApiQuery({ name: 'populateMedia', required: false, type: Array })
68
+ @ApiQuery({ name: 'filters', required: false, type: Array })
69
+ @Get()
70
+ async findMany(@Query() query: any) {
71
+ return this.service.find(query);
72
+ }
73
+
74
+ @ApiBearerAuth("jwt")
75
+ @Get(':id')
76
+ async findOne(@Param('id') id: string, @Query() query: any) {
77
+ return this.service.findOne(+id, query);
78
+ }
79
+
80
+ @ApiBearerAuth("jwt")
81
+ @Delete('/bulk')
82
+ async deleteMany(@Body() ids: number[]) {
83
+ return this.service.deleteMany(ids);
84
+ }
85
+
86
+ @ApiBearerAuth("jwt")
87
+ @Delete(':id')
88
+ async delete(@Param('id') id: number) {
89
+ return this.service.delete(id);
90
+ }
91
+
92
+
93
+ }
@@ -10,6 +10,7 @@ import { ActiveUser } from '../decorators/active-user.decorator';
10
10
  import { ActiveUserData } from '../interfaces/active-user-data.interface';
11
11
  import { SolidRequestContextDecorator } from 'src/decorators/solid-request-context.decorator';
12
12
  import { SolidRequestContextDto } from 'src/dtos/solid-request-context.dto';
13
+ import { UpdateUserProfileDto } from 'src/dtos/update-user-profile.dto';
13
14
 
14
15
  @ApiTags('Solid Core')
15
16
  @Controller('user') //FIXME: Change this to the model plural name
@@ -116,5 +117,15 @@ export class UserController {
116
117
  return this.service.removeRoleFromUser(userEmail, roleName);
117
118
  }
118
119
 
119
-
120
+ @ApiBearerAuth('jwt')
121
+ @Post('/profile')
122
+ @UseInterceptors(AnyFilesInterceptor())
123
+ async updateOwnProfile(
124
+ @Body() updateDto: UpdateUserProfileDto,
125
+ @UploadedFiles() files: Array<Express.Multer.File>,
126
+ @SolidRequestContextDecorator() solidRequestContext: SolidRequestContextDto,
127
+ @ActiveUser() user: ActiveUserData,
128
+ ) {
129
+ return this.service.update(user.sub, updateDto, files, true, solidRequestContext);
130
+ }
120
131
  }
@@ -1,5 +1,5 @@
1
1
  import { IsString } from 'class-validator';
2
- import { IsOptional, IsBoolean } from 'class-validator';
2
+ import { IsOptional, IsBoolean, IsInt } from 'class-validator';
3
3
  import { ApiProperty } from '@nestjs/swagger';
4
4
 
5
5
  export class CreateSettingDto {
@@ -11,4 +11,16 @@ export class CreateSettingDto {
11
11
  @IsString()
12
12
  @ApiProperty()
13
13
  value: string;
14
+ @IsOptional()
15
+ @IsString()
16
+ @ApiProperty()
17
+ type: string;
18
+ @IsOptional()
19
+ @IsInt()
20
+ @ApiProperty({ description: "This is the user id field" })
21
+ userId: number;
22
+ @IsString()
23
+ @IsOptional()
24
+ @ApiProperty({ description: "This is the user id field" })
25
+ userUserKey: string;
14
26
  }
@@ -0,0 +1,30 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+ import { IsInt } from 'class-validator';
3
+ import { IsOptional } from 'class-validator';
4
+ import { IsString } from 'class-validator';
5
+ export class CreateUserActivityHistoryDto {
6
+ @IsOptional()
7
+ @IsInt()
8
+ @ApiProperty()
9
+ userId: number;
10
+
11
+ @IsString()
12
+ @IsOptional()
13
+ @ApiProperty()
14
+ userUserKey: string;
15
+
16
+ @IsOptional()
17
+ @IsString()
18
+ @ApiProperty()
19
+ event: string;
20
+
21
+ @IsOptional()
22
+ @IsString()
23
+ @ApiProperty()
24
+ ipAddress: string;
25
+
26
+ @IsOptional()
27
+ @IsString()
28
+ @ApiProperty()
29
+ userAgent: string;
30
+ }
@@ -1,4 +1,4 @@
1
- import { IsInt,IsOptional, IsString, IsBoolean } from 'class-validator';
1
+ import { IsInt, IsOptional, IsString, IsBoolean } from 'class-validator';
2
2
  import { ApiProperty } from '@nestjs/swagger';
3
3
 
4
4
  export class UpdateSettingDto {
@@ -13,4 +13,16 @@ export class UpdateSettingDto {
13
13
  @IsString()
14
14
  @ApiProperty()
15
15
  value: string;
16
+ @IsOptional()
17
+ @IsString()
18
+ @ApiProperty()
19
+ type: string;
20
+ @IsOptional()
21
+ @IsInt()
22
+ @ApiProperty({ description: "This is the user id field" })
23
+ userId: number;
24
+ @IsString()
25
+ @IsOptional()
26
+ @ApiProperty({ description: "This is the user id field" })
27
+ userUserKey: string;
16
28
  }
@@ -0,0 +1,32 @@
1
+ import { IsInt,IsOptional, IsString } from 'class-validator';
2
+ import { ApiProperty } from '@nestjs/swagger';
3
+ export class UpdateUserActivityHistoryDto {
4
+ @IsOptional()
5
+ @IsInt()
6
+ id: number;
7
+
8
+ @IsOptional()
9
+ @IsInt()
10
+ @ApiProperty()
11
+ userId: number;
12
+
13
+ @IsString()
14
+ @IsOptional()
15
+ @ApiProperty()
16
+ userUserKey: string;
17
+
18
+ @IsOptional()
19
+ @IsString()
20
+ @ApiProperty()
21
+ event: string;
22
+
23
+ @IsOptional()
24
+ @IsString()
25
+ @ApiProperty()
26
+ ipAddress: string;
27
+
28
+ @IsOptional()
29
+ @IsString()
30
+ @ApiProperty()
31
+ userAgent: string;
32
+ }
@@ -0,0 +1,19 @@
1
+ import { IsOptional, IsString, IsEmail } from 'class-validator';
2
+
3
+ export class UpdateUserProfileDto {
4
+ @IsOptional()
5
+ @IsString()
6
+ fullName?: string;
7
+
8
+ @IsOptional()
9
+ @IsString()
10
+ username?: string;
11
+
12
+ @IsOptional()
13
+ @IsEmail()
14
+ email?: string;
15
+
16
+ @IsOptional()
17
+ @IsString()
18
+ mobile?: string;
19
+ }
@@ -38,12 +38,12 @@ export class UpdateUserDto {
38
38
  @IsOptional()
39
39
  @IsBoolean()
40
40
  @ApiProperty()
41
- forcePasswordChange: boolean = true;
41
+ forcePasswordChange: boolean;
42
42
  @IsNotEmpty()
43
43
  @IsOptional()
44
44
  @IsString()
45
45
  @ApiProperty()
46
- lastLoginProvider: string = "local";
46
+ lastLoginProvider: string;
47
47
  @IsOptional()
48
48
  @IsString()
49
49
  @ApiProperty()
@@ -64,11 +64,11 @@ export class UpdateUserDto {
64
64
  @IsOptional()
65
65
  @IsBoolean()
66
66
  @ApiProperty()
67
- active: boolean = true;
67
+ active: boolean;
68
68
  @IsOptional()
69
69
  @IsDate()
70
70
  @ApiProperty()
71
- forgotPasswordConfirmedAt: Date = new Date("1970-01-01T00:00:00.000Z");
71
+ forgotPasswordConfirmedAt: Date;
72
72
  @IsOptional()
73
73
  @IsString()
74
74
  @ApiProperty()
@@ -76,11 +76,11 @@ export class UpdateUserDto {
76
76
  @IsOptional()
77
77
  @IsDate()
78
78
  @ApiProperty()
79
- verificationTokenOnForgotPasswordExpiresAt: Date = new Date("1970-01-01T00:00:00.000Z");
79
+ verificationTokenOnForgotPasswordExpiresAt: Date;
80
80
  @IsOptional()
81
81
  @IsDate()
82
82
  @ApiProperty()
83
- emailVerifiedOnRegistrationAt: Date = new Date("1970-01-01T00:00:00.000Z");
83
+ emailVerifiedOnRegistrationAt: Date;
84
84
  @IsOptional()
85
85
  @IsString()
86
86
  @ApiProperty()
@@ -88,11 +88,11 @@ export class UpdateUserDto {
88
88
  @IsOptional()
89
89
  @IsDate()
90
90
  @ApiProperty()
91
- emailVerificationTokenOnRegistrationExpiresAt: Date = new Date("1970-01-01T00:00:00.000Z");
91
+ emailVerificationTokenOnRegistrationExpiresAt: Date;
92
92
  @IsOptional()
93
93
  @IsDate()
94
94
  @ApiProperty()
95
- mobileVerifiedOnRegistrationAt: Date = new Date("1970-01-01T00:00:00.000Z");
95
+ mobileVerifiedOnRegistrationAt: Date;
96
96
  @IsOptional()
97
97
  @IsString()
98
98
  @ApiProperty()
@@ -100,11 +100,11 @@ export class UpdateUserDto {
100
100
  @IsOptional()
101
101
  @IsDate()
102
102
  @ApiProperty()
103
- mobileVerificationTokenOnRegistrationExpiresAt: Date = new Date("1970-01-01T00:00:00.000Z");
103
+ mobileVerificationTokenOnRegistrationExpiresAt: Date;
104
104
  @IsOptional()
105
105
  @IsDate()
106
106
  @ApiProperty()
107
- emailVerifiedOnLoginAt: Date = new Date("1970-01-01T00:00:00.000Z");
107
+ emailVerifiedOnLoginAt: Date;
108
108
  @IsOptional()
109
109
  @IsString()
110
110
  @ApiProperty()
@@ -112,11 +112,11 @@ export class UpdateUserDto {
112
112
  @IsOptional()
113
113
  @IsDate()
114
114
  @ApiProperty()
115
- emailVerificationTokenOnLoginExpiresAt: Date = new Date("1970-01-01T00:00:00.000Z");
115
+ emailVerificationTokenOnLoginExpiresAt: Date;
116
116
  @IsOptional()
117
117
  @IsDate()
118
118
  @ApiProperty()
119
- mobileVerifiedOnLoginAt: Date = new Date("1970-01-01T00:00:00.000Z");
119
+ mobileVerifiedOnLoginAt: Date;
120
120
  @IsOptional()
121
121
  @IsString()
122
122
  @ApiProperty()
@@ -124,7 +124,7 @@ export class UpdateUserDto {
124
124
  @IsOptional()
125
125
  @IsDate()
126
126
  @ApiProperty()
127
- mobileVerificationTokenOnLoginExpiresAt: Date = new Date("1970-01-01T00:00:00.000Z");
127
+ mobileVerificationTokenOnLoginExpiresAt: Date;
128
128
  @IsOptional()
129
129
  @IsString()
130
130
  @ApiProperty()
@@ -1,5 +1,6 @@
1
1
  import { CommonEntity } from 'src/entities/common.entity'
2
- import {Entity, Column, Index} from 'typeorm'
2
+ import { Entity, Column, Index, JoinColumn, ManyToOne } from 'typeorm';
3
+ import { User } from 'src/entities/user.entity'
3
4
 
4
5
  @Entity("ss_setting")
5
6
  export class Setting extends CommonEntity {
@@ -8,4 +9,9 @@ export class Setting extends CommonEntity {
8
9
  key: string;
9
10
  @Column({ type: "varchar", nullable: true })
10
11
  value: string;
12
+ @Column({ name: "type", type: "varchar", nullable: true })
13
+ type: string;
14
+ @ManyToOne(() => User, { onDelete: "CASCADE", nullable: true })
15
+ @JoinColumn()
16
+ user: User;
11
17
  }
@@ -0,0 +1,21 @@
1
+ import { CommonEntity } from 'src/entities/common.entity'
2
+ import {Entity, JoinColumn, ManyToOne, Column, Index} from 'typeorm';
3
+ import { User } from 'src/entities/user.entity'
4
+ @Entity("ss_user_activity_history")
5
+ export class UserActivityHistory extends CommonEntity{
6
+ @ManyToOne(() => User, { onDelete: "CASCADE", nullable: true })
7
+ @JoinColumn()
8
+ user: User;
9
+
10
+ @Index()
11
+ @Column({ type: "varchar", nullable: true })
12
+ event: string;
13
+
14
+ @Index()
15
+ @Column({ type: "varchar", nullable: true })
16
+ ipAddress: string;
17
+
18
+ @Index()
19
+ @Column({ type: "varchar", nullable: true })
20
+ userAgent: string;
21
+ }
@@ -10,6 +10,7 @@ import { AuthType } from '../enums/auth-type.enum';
10
10
  import { AccessTokenGuard } from './access-token.guard';
11
11
  import { IS_PUBLIC_KEY } from '../decorators/public.decorator';
12
12
  import { PermissionMetadataService } from '../services/permission-metadata.service';
13
+ import { ClsService } from 'nestjs-cls';
13
14
 
14
15
  @Injectable()
15
16
  export class AuthenticationGuard implements CanActivate {
@@ -24,7 +25,8 @@ export class AuthenticationGuard implements CanActivate {
24
25
  constructor(
25
26
  private readonly reflector: Reflector,
26
27
  private readonly accessTokenGuard: AccessTokenGuard,
27
- private readonly permissionService: PermissionMetadataService
28
+ private readonly permissionService: PermissionMetadataService,
29
+ private readonly cls: ClsService,
28
30
  ) { }
29
31
 
30
32
  async canActivate(context: ExecutionContext): Promise<boolean> {
@@ -33,6 +35,15 @@ export class AuthenticationGuard implements CanActivate {
33
35
  const request = context.switchToHttp().getRequest();
34
36
  request['isListedInPublicRole'] = false;
35
37
 
38
+ // Set IP and User-Agent into CLS context
39
+ const rawIp = request.headers['x-forwarded-for'] || request.socket?.remoteAddress || request.ip;
40
+ const ip = Array.isArray(rawIp) ? rawIp[0] :
41
+ typeof rawIp === 'string' ? rawIp.split(',')[0].trim() : '';
42
+ const userAgent = request.headers['user-agent'] || '';
43
+
44
+ this.cls.set('ipAddress', ip);
45
+ this.cls.set('userAgent', userAgent);
46
+
36
47
  const isPublic = this.reflector.get(IS_PUBLIC_KEY, context.getHandler());
37
48
  if (isPublic) {
38
49
  return true;
package/src/index.ts CHANGED
@@ -86,6 +86,9 @@ export * from './dtos/update-security-rule.dto'
86
86
  export * from './dtos/update-chatter-message.dto'
87
87
  export * from './dtos/update-chatter-message-details.dto'
88
88
  export * from './dtos/update-locale.dto'
89
+ export * from './dtos/create-user-activity-history.dto'
90
+ export * from './dtos/update-user-activity-history.dto'
91
+
89
92
  export * from './entities/action-metadata.entity'
90
93
  export * from './entities/common.entity'
91
94
  export * from './entities/email-attachment.entity'
@@ -117,6 +120,8 @@ export * from './entities/export-transaction.entity'
117
120
  export * from './entities/import-transaction.entity'
118
121
  export * from './entities/import-transaction-error-log.entity'
119
122
  export * from './entities/locale.entity'
123
+ export * from './entities/user-activity-history.entity'
124
+
120
125
  export * from './enums/auth-type.enum'
121
126
 
122
127
  export * from './filters/http-exception.filter'
@@ -234,6 +239,8 @@ export * from './services/request-context.service'
234
239
  export * from './services/chatter-message.service'
235
240
  export * from './services/chatter-message-details.service'
236
241
  export * from './services/locale.service'
242
+ export * from './services/user-activity-history.service'
243
+
237
244
  // Repositories
238
245
  export * from './repository/solid-base.repository'
239
246
  export * from './repository/security-rule.repository'