rez_core 5.0.134 → 5.0.136
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/dist/module/meta/controller/media.controller.d.ts +3 -0
- package/dist/module/meta/controller/media.controller.js +27 -0
- package/dist/module/meta/controller/media.controller.js.map +1 -1
- package/dist/module/meta/service/media-data.service.d.ts +1 -0
- package/dist/module/meta/service/media-data.service.js +22 -1
- package/dist/module/meta/service/media-data.service.js.map +1 -1
- package/dist/module/user/service/user-session.service.js +12 -11
- package/dist/module/user/service/user-session.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/meta/controller/media.controller.ts +28 -0
- package/src/module/meta/service/media-data.service.ts +53 -7
- package/src/module/user/service/user-session.service.ts +64 -67
package/package.json
CHANGED
|
@@ -104,4 +104,32 @@ export class MediaController {
|
|
|
104
104
|
body.parent_type,
|
|
105
105
|
);
|
|
106
106
|
}
|
|
107
|
+
|
|
108
|
+
// media.controller.ts
|
|
109
|
+
@Get('inline/:id')
|
|
110
|
+
async getInlineUrl(
|
|
111
|
+
@Param('id') id: number,
|
|
112
|
+
@Res() res: Response,
|
|
113
|
+
@Req() req: Request & { user: any },
|
|
114
|
+
@Query('expiresIn') expiresIn?: number,
|
|
115
|
+
) {
|
|
116
|
+
const loggedInUser = req.user.userData;
|
|
117
|
+
try {
|
|
118
|
+
const inlineUrl = await this.mediaDataService.getMediaInlineUrl(
|
|
119
|
+
id,
|
|
120
|
+
loggedInUser,
|
|
121
|
+
expiresIn,
|
|
122
|
+
);
|
|
123
|
+
res.status(HttpStatus.OK).json({
|
|
124
|
+
message: 'Inline URL fetched successfully',
|
|
125
|
+
success: true,
|
|
126
|
+
data: { inlineUrl },
|
|
127
|
+
});
|
|
128
|
+
} catch (error) {
|
|
129
|
+
res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
|
|
130
|
+
message: error.message || 'Error fetching inline URL',
|
|
131
|
+
success: false,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
107
135
|
}
|
|
@@ -4,7 +4,10 @@ import { S3 } from 'aws-sdk';
|
|
|
4
4
|
import axios from 'axios';
|
|
5
5
|
import { EntityManager } from 'typeorm';
|
|
6
6
|
import { v4 as uuidv4 } from 'uuid';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
ENTITYTYPE_MEDIA,
|
|
9
|
+
STATUS_PENDING,
|
|
10
|
+
} from '../../../constant/global.constant';
|
|
8
11
|
import { MediaData } from '../entity/media-data.entity';
|
|
9
12
|
import { MediaDataRepository } from '../repository/media-data.repository';
|
|
10
13
|
import { EntityServiceImpl } from './entity-service-impl.service';
|
|
@@ -154,7 +157,7 @@ export class MediaDataService extends EntityServiceImpl {
|
|
|
154
157
|
Bucket: this.bucketName,
|
|
155
158
|
Key: mediaData.media_url,
|
|
156
159
|
Expires: Number(expiresIn) || 60 * 5,
|
|
157
|
-
ResponseContentDisposition: 'inline'
|
|
160
|
+
ResponseContentDisposition: 'inline',
|
|
158
161
|
});
|
|
159
162
|
return {
|
|
160
163
|
signedUrl,
|
|
@@ -168,6 +171,37 @@ export class MediaDataService extends EntityServiceImpl {
|
|
|
168
171
|
}
|
|
169
172
|
}
|
|
170
173
|
|
|
174
|
+
// media-data.service.ts
|
|
175
|
+
async getMediaInlineUrl(id: number, loggedInUser, expiresIn?: number) {
|
|
176
|
+
try {
|
|
177
|
+
const entityData = await this.getEntityData(
|
|
178
|
+
ENTITYTYPE_MEDIA,
|
|
179
|
+
id,
|
|
180
|
+
loggedInUser,
|
|
181
|
+
);
|
|
182
|
+
const mediaData = entityData as MediaData;
|
|
183
|
+
|
|
184
|
+
if (!mediaData) {
|
|
185
|
+
throw new Error('Media not found');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const signedUrl = await this.s3.getSignedUrlPromise('getObject', {
|
|
189
|
+
Bucket: this.bucketName,
|
|
190
|
+
Key: mediaData.media_url,
|
|
191
|
+
Expires: Number(expiresIn) || 60 * 5,
|
|
192
|
+
ResponseContentDisposition: 'inline',
|
|
193
|
+
ResponseContentType: this.getContentType(
|
|
194
|
+
mediaData.file_name.split('.').pop() || '',
|
|
195
|
+
),
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
return signedUrl;
|
|
199
|
+
} catch (error) {
|
|
200
|
+
console.error('Error generating inline URL:', error);
|
|
201
|
+
throw new Error('Failed to generate inline URL');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
171
205
|
public async buildUploadPathGenericdd(
|
|
172
206
|
mappedEntityType: string,
|
|
173
207
|
loggedInUser,
|
|
@@ -195,7 +229,8 @@ export class MediaDataService extends EntityServiceImpl {
|
|
|
195
229
|
const replacements: Record<string, string | null> = {};
|
|
196
230
|
|
|
197
231
|
// --- ORG ---
|
|
198
|
-
const organizationRepo =
|
|
232
|
+
const organizationRepo =
|
|
233
|
+
this.reflectionHelper.getRepoService('OrganizationData');
|
|
199
234
|
let organizationData = await organizationRepo.findOne({
|
|
200
235
|
where: {
|
|
201
236
|
id: loggedInUser.organization_id,
|
|
@@ -222,7 +257,10 @@ export class MediaDataService extends EntityServiceImpl {
|
|
|
222
257
|
}
|
|
223
258
|
|
|
224
259
|
// Get entity data for level_code
|
|
225
|
-
const getEntityData = await this.entityMasterService.getEntityData(
|
|
260
|
+
const getEntityData = await this.entityMasterService.getEntityData(
|
|
261
|
+
levelEntityType,
|
|
262
|
+
loggedInUser,
|
|
263
|
+
);
|
|
226
264
|
|
|
227
265
|
if (!getEntityData) return null;
|
|
228
266
|
const levelEntityDataResult = await this.entityManager.query(
|
|
@@ -269,7 +307,10 @@ export class MediaDataService extends EntityServiceImpl {
|
|
|
269
307
|
// );
|
|
270
308
|
|
|
271
309
|
// Get entity data for level_code
|
|
272
|
-
const getEntityData = await this.entityMasterService.getEntityData(
|
|
310
|
+
const getEntityData = await this.entityMasterService.getEntityData(
|
|
311
|
+
mappedEntityType,
|
|
312
|
+
loggedInUser,
|
|
313
|
+
);
|
|
273
314
|
|
|
274
315
|
if (!getEntityData) return null;
|
|
275
316
|
const levelEntityDataResult = await this.entityManager.query(
|
|
@@ -288,7 +329,10 @@ export class MediaDataService extends EntityServiceImpl {
|
|
|
288
329
|
// If we have parent template, modify the path to include it
|
|
289
330
|
pathTemplate = '${org_code}/template/${template_code}';
|
|
290
331
|
} else {
|
|
291
|
-
const getEntityData = await this.entityMasterService.getEntityData(
|
|
332
|
+
const getEntityData = await this.entityMasterService.getEntityData(
|
|
333
|
+
mappedEntityType,
|
|
334
|
+
loggedInUser,
|
|
335
|
+
);
|
|
292
336
|
|
|
293
337
|
if (!getEntityData) return null;
|
|
294
338
|
const levelEntityDataResult = await this.entityManager.query(
|
|
@@ -415,7 +459,9 @@ export class MediaDataService extends EntityServiceImpl {
|
|
|
415
459
|
return null;
|
|
416
460
|
});
|
|
417
461
|
} else {
|
|
418
|
-
const organizationProfileRepo = this.reflectionHelper.getRepoService(
|
|
462
|
+
const organizationProfileRepo = this.reflectionHelper.getRepoService(
|
|
463
|
+
'OrganizationProfile',
|
|
464
|
+
);
|
|
419
465
|
organizationData = await organizationProfileRepo.find({
|
|
420
466
|
where: {
|
|
421
467
|
id: loggedInUser.organization_id,
|
|
@@ -71,6 +71,7 @@ export class UserSessionService {
|
|
|
71
71
|
await this.userSessionRepository.saveSession(userSession);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
|
|
74
75
|
async switchCurrentLevelService(
|
|
75
76
|
currentUser: any,
|
|
76
77
|
data: any,
|
|
@@ -122,82 +123,78 @@ export class UserSessionService {
|
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
async checkIfUserHasMapping(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
): Promise<boolean> {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
126
|
+
userId: number,
|
|
127
|
+
appcode: string,
|
|
128
|
+
levelType: string,
|
|
129
|
+
levelId: string,
|
|
130
|
+
): Promise<boolean> {
|
|
131
|
+
// Get repositories dynamically via reflectionHelper
|
|
132
|
+
const userRoleMappingRepo =
|
|
133
|
+
this.reflectionHelper.getRepoService('UserRoleMapping');
|
|
134
|
+
const appMasterRepo = this.reflectionHelper.getRepoService('AppMaster');
|
|
135
|
+
|
|
136
|
+
// Use QueryBuilder with proper aliases
|
|
137
|
+
const count = await userRoleMappingRepo
|
|
138
|
+
.createQueryBuilder('urm')
|
|
139
|
+
.innerJoin(
|
|
140
|
+
appMasterRepo.metadata.tableName,
|
|
141
|
+
'app',
|
|
142
|
+
'app.appcode = urm.appcode',
|
|
143
|
+
)
|
|
144
|
+
.where('urm.user_id = :userId', { userId })
|
|
145
|
+
.andWhere('urm.appcode = :appcode', { appcode })
|
|
146
|
+
.andWhere('urm.level_type = :levelType', { levelType })
|
|
147
|
+
.andWhere('urm.level_id = :levelId', { levelId })
|
|
148
|
+
.andWhere('app.show_in_ui = true')
|
|
149
|
+
.getCount();
|
|
150
|
+
|
|
151
|
+
return count > 0;
|
|
152
|
+
}
|
|
154
153
|
|
|
155
154
|
async getUserRoleMappingForApp(userId: number, appcode: string) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
this.reflectionHelper.getRepoService('
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
'
|
|
169
|
-
'app.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (!mapping || mapping.level_type !== 'BRN') {
|
|
178
|
-
return mapping;
|
|
179
|
-
}
|
|
155
|
+
const userRoleMappingRepo =
|
|
156
|
+
this.reflectionHelper.getRepoService('UserRoleMapping');
|
|
157
|
+
const appMasterRepo = this.reflectionHelper.getRepoService('AppMaster');
|
|
158
|
+
|
|
159
|
+
const mapping = await userRoleMappingRepo
|
|
160
|
+
.createQueryBuilder('urm')
|
|
161
|
+
.innerJoin(
|
|
162
|
+
appMasterRepo.metadata.tableName,
|
|
163
|
+
'app',
|
|
164
|
+
'app.appcode = urm.appcode',
|
|
165
|
+
)
|
|
166
|
+
.where('urm.user_id = :userId', { userId })
|
|
167
|
+
.andWhere('urm.appcode = :appcode', { appcode })
|
|
168
|
+
.andWhere('app.show_in_ui = true')
|
|
169
|
+
.getOne();
|
|
170
|
+
|
|
171
|
+
if (!mapping) {
|
|
172
|
+
throw new BadRequestException(
|
|
173
|
+
`User does not have visible access to app ${appcode}`,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
180
176
|
|
|
181
|
-
|
|
182
|
-
|
|
177
|
+
if (mapping.level_type !== 'BRN') {
|
|
178
|
+
return mapping;
|
|
179
|
+
}
|
|
183
180
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
181
|
+
// Resolve SCH under brand
|
|
182
|
+
const schoolRepo = this.reflectionHelper.getRepoService('SSOSchool');
|
|
183
|
+
const school = await schoolRepo.findOne({
|
|
184
|
+
where: { brand_id: mapping.level_id },
|
|
185
|
+
order: { id: 'ASC' },
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
if (!school) {
|
|
189
|
+
throw new BadRequestException(
|
|
190
|
+
`No schools found under brand ${mapping.level_id}`,
|
|
191
|
+
);
|
|
192
|
+
}
|
|
190
193
|
|
|
191
|
-
if (school) {
|
|
192
194
|
return {
|
|
193
195
|
...mapping,
|
|
194
196
|
level_type: 'SCH',
|
|
195
197
|
level_id: school.id,
|
|
196
198
|
};
|
|
197
199
|
}
|
|
198
|
-
|
|
199
|
-
// If no SCH found
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
200
|
}
|