rez_core 2.1.28 → 2.1.29

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": "2.1.28",
3
+ "version": "2.1.29",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -13,6 +13,8 @@ import {
13
13
  UseGuards,
14
14
  Inject,
15
15
  Request,
16
+ InternalServerErrorException,
17
+ NotFoundException,
16
18
  } from '@nestjs/common';
17
19
  import { EntityServiceImpl } from '../service/entity-service-impl.service';
18
20
  import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
@@ -63,56 +65,36 @@ export class EntityController {
63
65
  async create(
64
66
  @Body() entityData: BaseEntity,
65
67
  @Query('entity_type') entityType: string,
66
- @Res() res: Response,
67
68
  @Req() req: Request & { user: any },
68
69
  ) {
69
- try {
70
- let loggedInUser = req.user.userData;
71
- let appcode = req.user.userData.appcode;
72
- if (!entityType) {
73
- return res.status(HttpStatus.BAD_REQUEST).json({
74
- success: false,
75
- error: 'Query parameter "entity_type" is required',
76
- });
77
- }
78
- const entityMaster =
79
- await this.entityMasterService.getEntityData(entityType);
70
+ let loggedInUser = req.user.userData;
71
+ let appcode = req.user.userData.appcode;
80
72
 
81
- const entityService =
82
- await this.reflectionHelper.getBean<EntityServiceImpl>(
83
- entityMaster.entity_service,
84
- );
85
-
86
- if (!entityService) {
87
- return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
88
- success: false,
89
- error: `No service found for Entity Type ${entityType}`,
90
- });
91
- }
92
- const createdEntity = await entityService.createEntity(
93
- entityData,
94
- loggedInUser as UserData,
95
- null,
96
- appcode,
73
+ if (!entityType) {
74
+ throw new BadRequestException(
75
+ `Query parameter "entity_type" is required`,
97
76
  );
77
+ }
98
78
 
99
- if (!createdEntity) {
100
- return res.status(HttpStatus.BAD_REQUEST).json({
101
- success: false,
102
- error: createdEntity?.error || 'Entity creation failed',
103
- });
104
- }
79
+ const entityMaster =
80
+ await this.entityMasterService.getEntityData(entityType);
81
+ const entityService =
82
+ await this.reflectionHelper.getBean<EntityServiceImpl>(
83
+ entityMaster.entity_service,
84
+ );
105
85
 
106
- return res.status(HttpStatus.OK).json({
107
- success: true,
108
- data: createdEntity,
109
- });
110
- } catch (error) {
111
- return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
112
- success: false,
113
- error: error.message || 'Internal server error',
114
- });
86
+ if (!entityService) {
87
+ throw new InternalServerErrorException(
88
+ `No service found for Entity Type ${entityType}`,
89
+ );
115
90
  }
91
+
92
+ return entityService.createEntity(
93
+ entityData,
94
+ loggedInUser as UserData,
95
+ null,
96
+ appcode,
97
+ );
116
98
  }
117
99
 
118
100
  @Post('update/:id')
@@ -120,68 +102,44 @@ export class EntityController {
120
102
  @Param('id') id: number,
121
103
  @Body() entityData: BaseEntity,
122
104
  @Query('entity_type') entityType: string,
123
- @Res() response: Response,
124
105
  @Req() req: Request & { user: any },
125
106
  ) {
126
- try {
127
- let loggedInUser = req.user.userData;
128
- // let loggedInUser = await this.entityService.getEntityData(
129
- // ENTITYTYPE_USER,
130
- // requestedUser.userId,
131
- // );
132
- if (!entityType) {
133
- return response.status(HttpStatus.BAD_REQUEST).json({
134
- success: false,
135
- error: 'Query parameter "entity_type" is required',
136
- });
137
- }
107
+ const loggedInUser = req.user.userData;
138
108
 
139
- const entityMaster =
140
- await this.entityMasterService.getEntityData(entityType);
141
-
142
- const entityService =
143
- await this.reflectionHelper.getBean<EntityServiceImpl>(
144
- entityMaster.entity_service,
145
- );
146
-
147
- if (!entityService) {
148
- return response.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
149
- success: false,
150
- error: `No service found for entity_type "${entityType}"`,
151
- });
152
- }
109
+ if (!entityType) {
110
+ throw new BadRequestException(
111
+ 'Query parameter "entity_type" is required',
112
+ );
113
+ }
153
114
 
154
- let existingEntity = await entityService.getEntityData(entityType, id);
155
- if (!existingEntity) {
156
- return response.status(HttpStatus.NOT_FOUND).json({
157
- success: false,
158
- error: `No entity found for id "${id}"`,
159
- });
160
- }
161
- // let mergeEntity = JsonUtil.merge(existingEntity, entityData);
115
+ const entityMaster =
116
+ await this.entityMasterService.getEntityData(entityType);
162
117
 
163
- const updatedEntity = await entityService.updateEntity(
164
- entityData,
165
- loggedInUser as UserData,
118
+ const entityService =
119
+ await this.reflectionHelper.getBean<EntityServiceImpl>(
120
+ entityMaster.entity_service,
166
121
  );
167
122
 
168
- if (!updatedEntity) {
169
- return response.status(HttpStatus.BAD_REQUEST).json({
170
- success: false,
171
- error: updatedEntity?.error || 'Entity creation failed',
172
- });
173
- }
123
+ if (!entityService) {
124
+ throw new InternalServerErrorException(
125
+ `No service found for entity_type "${entityType}"`,
126
+ );
127
+ }
174
128
 
175
- return response.status(HttpStatus.OK).json({
176
- success: true,
177
- data: updatedEntity.data,
178
- });
179
- } catch (error) {
180
- return response.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
181
- success: false,
182
- error: error.message || 'Internal server error',
183
- });
129
+ const existingEntity = await entityService.getEntityData(entityType, id);
130
+ if (!existingEntity) {
131
+ throw new NotFoundException(`No entity found for id "${id}"`);
184
132
  }
133
+
134
+ const updatedEntity = await entityService.updateEntity(
135
+ entityData,
136
+ loggedInUser as UserData,
137
+ );
138
+
139
+ return {
140
+ success: true,
141
+ data: updatedEntity.data,
142
+ };
185
143
  }
186
144
 
187
145
  @Post('getFilteredDataWithTabs/:entity_type')