rez_core 1.0.37 → 1.0.38

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.37",
3
+ "version": "1.0.38",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -30,6 +30,7 @@
30
30
  "@nestjs/swagger": "^11.0.3",
31
31
  "@nestjs/typeorm": "^11.0.0",
32
32
  "250218_nodejs_core": "file:",
33
+ "aws-sdk": "^2.1692.0",
33
34
  "bcrypt": "^5.1.1",
34
35
  "class-transformer": "^0.5.1",
35
36
  "class-validator": "^0.14.1",
@@ -46,6 +47,7 @@
46
47
  "reflect-metadata": "^0.2.2",
47
48
  "rxjs": "^7.8.1",
48
49
  "typeorm": "^0.3.20",
50
+ "uuid": "^11.1.0",
49
51
  "winston": "^3.17.0",
50
52
  "xlsx": "^0.18.5"
51
53
  },
@@ -17,3 +17,4 @@ export const secretKey: string = process.env.secret_key || '';
17
17
  // STATUS
18
18
  export const STATUS_ACTIVE = 'ACTIVE';
19
19
  export const STATUS_INACTIVE = 'INACTIVE';
20
+ export const STATUS_PENDING = 'PENDING';
@@ -3,9 +3,10 @@ import { TypeOrmModule } from '@nestjs/typeorm';
3
3
  import { OrganizationService } from './service/organization.service';
4
4
  import { OrganizationData } from './entity/organization.entity';
5
5
  import { OrganizationController } from './controller/organization.controller';
6
+ import { UserModule } from '../user/user.module';
6
7
 
7
8
  @Module({
8
- imports: [TypeOrmModule.forFeature([OrganizationData])],
9
+ imports: [TypeOrmModule.forFeature([OrganizationData]), UserModule],
9
10
  controllers:[OrganizationController],
10
11
  providers: [OrganizationService],
11
12
  exports: [OrganizationService],
@@ -0,0 +1,45 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ HttpStatus,
5
+ Post,
6
+ Res,
7
+ UseGuards,
8
+ } from '@nestjs/common';
9
+ import { MediaDataService } from '../service/media-data.service';
10
+ import { JwtAuthGuard } from '../../auth/guards/jwt.guard';
11
+ import { Response } from 'express';
12
+
13
+ @Controller('media')
14
+ @UseGuards(JwtAuthGuard)
15
+ export class MediaController {
16
+ constructor(private readonly mediaDataService: MediaDataService) {}
17
+
18
+ @Post('initiate-upload')
19
+ async initiateUpload(
20
+ @Body()
21
+ body: {
22
+ file_name: string;
23
+ attribute_key: string;
24
+ mapped_entity_type?: string;
25
+ mapped_entity_id?: number;
26
+ },
27
+ @Res() res: Response,
28
+ ) {
29
+ let result = await this.mediaDataService.generateMediaUploadDetails(
30
+ body.file_name,
31
+ body.attribute_key,
32
+ body.mapped_entity_type,
33
+ body.mapped_entity_id,
34
+ );
35
+ if (result) {
36
+ res.status(HttpStatus.OK).json({
37
+ message: 'Upload initiated successfully',
38
+ success: true,
39
+ data: result,
40
+ });
41
+ } else {
42
+ throw new Error('Something went wrong!');
43
+ }
44
+ }
45
+ }
@@ -22,6 +22,7 @@ import { EntityListService } from './service/entity-list.service';
22
22
  import { MediaData } from './entity/media-data.entity';
23
23
  import { MediaDataService } from './service/media-data.service';
24
24
  import { MediaDataRepository } from './repository/media-data.repository';
25
+ import { MediaController } from './controller/media.controller';
25
26
 
26
27
  @Module({
27
28
  imports: [
@@ -59,6 +60,6 @@ import { MediaDataRepository } from './repository/media-data.repository';
59
60
  EntityTableColumnService,
60
61
  MediaDataService,
61
62
  ],
62
- controllers: [EntityController, MasterController],
63
+ controllers: [EntityController, MasterController, MediaController],
63
64
  })
64
65
  export class EntityModule {}
@@ -1,12 +1,76 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { EntityServiceImpl } from './entity-service-impl.service';
3
3
  import { MediaDataRepository } from '../repository/media-data.repository';
4
+ import { ConfigService } from '@nestjs/config';
5
+ import { S3 } from 'aws-sdk';
6
+ import { MediaData } from '../entity/media-data.entity';
7
+ import { STATUS_PENDING } from '../../../constant/global.constant';
8
+ import { v4 as uuidv4 } from 'uuid';
4
9
 
5
10
  @Injectable()
6
11
  export class MediaDataService extends EntityServiceImpl {
7
- constructor(private readonly mediaRepository: MediaDataRepository) {
12
+
13
+
14
+ constructor(
15
+ private readonly configService: ConfigService,
16
+ private readonly mediaRepository: MediaDataRepository,
17
+ ) {
8
18
  super();
9
19
  }
20
+
21
+ s3AccessKeyID=this.configService.get('AWS.S3.AWS_ACCESS_KEY_ID')
22
+ s3AccessKeySecret=this.configService.get('AWS.S3.AWS_SECRET_KEY')
23
+ s3Region=this.configService.get('AWS.S3.AWS_REGION')
24
+ bucketName = this.configService.get<string>('AWS.S3.BUCKET_NAME');
25
+
26
+ s3 = new S3({
27
+ accessKeyId: this.s3AccessKeyID,
28
+ secretAccessKey: this.s3AccessKeySecret,
29
+ region: this.s3Region,
30
+ signatureVersion: 'v4',
31
+ });
32
+
33
+
34
+ async generateMediaUploadDetails(
35
+ fileName: string,
36
+ mappedAttributeKey: string,
37
+ mappedEntityType?: string,
38
+ mappedEntityId?: number,
39
+ ) {
40
+
41
+ if (!fileName || !mappedAttributeKey) {
42
+ return null;
43
+ }
44
+ const ext = fileName.split('.').pop()?.toLowerCase() ?? '';
45
+
46
+ const id = uuidv4();
47
+ const s3Key = `uploads/${mappedAttributeKey}/${id}.${ext}`;
48
+ console.log(s3Key)
49
+
50
+ const uploadUrl = await this.s3.getSignedUrlPromise('putObject', {
51
+ Bucket: this.bucketName,
52
+ Key: s3Key,
53
+ Expires: 60 * 5, // URL valid for 5 mins
54
+ ContentType: this.getContentType(ext),
55
+ });
56
+
57
+ let mediaData = new MediaData();
58
+ mediaData.mapped_attribute_key = mappedAttributeKey;
59
+ mediaData.status = STATUS_PENDING;
60
+ if (mappedEntityType) {
61
+ mediaData.mapped_entity_type = mappedEntityType;
62
+ }
63
+ if (mappedEntityId) {
64
+ mediaData.mapped_entity_id = mappedEntityId;
65
+ }
66
+
67
+ let savedEntity = await super.createEntity(mediaData, null);
68
+
69
+ if (savedEntity) {
70
+ return { id: savedEntity.id, path: s3Key, uploadUrl };
71
+ }
72
+ return null;
73
+ }
10
74
 
11
75
  async findByAttributeKeyAndMappedEntityIdAndMappedEntityType(
12
76
  attributeKey: string,
@@ -41,4 +105,14 @@ export class MediaDataService extends EntityServiceImpl {
41
105
  mappedEntityType,
42
106
  );
43
107
  }
108
+
109
+ private getContentType(ext: string): string {
110
+ const map = {
111
+ pdf: 'application/pdf',
112
+ jpg: 'image/jpeg',
113
+ jpeg: 'image/jpeg',
114
+ png: 'image/png',
115
+ };
116
+ return map[ext] || 'application/octet-stream';
117
+ }
44
118
  }
@@ -47,7 +47,7 @@ export class UserService extends EntityServiceImpl {
47
47
  throw new BadRequestException('User already exists');
48
48
  }
49
49
  userData.name =
50
- userData.first_name + userData.last_name ? userData.last_name : '';
50
+ (userData.first_name ? userData.first_name : '') + (userData.last_name ? userData.last_name : '');
51
51
  let password;
52
52
  if (userData.password) {
53
53
  password = EncryptUtilService.encryptGCM(
@@ -1,7 +1,7 @@
1
- DB_HOST: "localhost"
1
+ DB_HOST: "13.234.25.234"
2
2
  DB_PORT: "3306"
3
3
  DB_USER: "root"
4
- DB_PASS: "root"
4
+ DB_PASS: "Rezolut@123"
5
5
  DB_NAME: "core"
6
6
  MASTER_KEY: "0QZ2eRJv5oVILYnyBlC+FbSGVQiWKReh"
7
7
  MASTER_IV: "heuUQf5uPVtkotrFAOKUVw=="
@@ -12,4 +12,10 @@ CALLBACK_URL: "http://localhost:3000/auth/google/callback"
12
12
  OTP_EXPIRY: "10"
13
13
  OTP_LENGTH: "6"
14
14
  VERIFY_OTP: "false"
15
- DEFAULT_OTP: "123456"
15
+ DEFAULT_OTP: "123456"
16
+ AWS:
17
+ S3:
18
+ AWS_ACCESS_KEY_ID: "AKIAYYKIBDDSVJMYCJUV"
19
+ AWS_SECRET_KEY: "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"
20
+ AWS_REGION: "ap-south-1"
21
+ BUCKET_NAME: "testether"