rez_core 2.1.54 → 2.1.55

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 (24) hide show
  1. package/dist/module/listmaster/controller/list-master.controller.d.ts +5 -6
  2. package/dist/module/listmaster/controller/list-master.controller.js +10 -7
  3. package/dist/module/listmaster/controller/list-master.controller.js.map +1 -1
  4. package/dist/module/listmaster/listmaster.module.js +2 -2
  5. package/dist/module/listmaster/listmaster.module.js.map +1 -1
  6. package/dist/module/listmaster/repository/list-master-items.repository.d.ts +2 -1
  7. package/dist/module/listmaster/repository/list-master-items.repository.js +8 -2
  8. package/dist/module/listmaster/repository/list-master-items.repository.js.map +1 -1
  9. package/dist/module/listmaster/repository/list-master.repository.d.ts +1 -0
  10. package/dist/module/listmaster/repository/list-master.repository.js +3 -0
  11. package/dist/module/listmaster/repository/list-master.repository.js.map +1 -1
  12. package/dist/module/listmaster/service/list-master-item.service.d.ts +9 -7
  13. package/dist/module/listmaster/service/list-master-item.service.js +48 -18
  14. package/dist/module/listmaster/service/list-master-item.service.js.map +1 -1
  15. package/dist/module/listmaster/service/list-master.service.js +5 -2
  16. package/dist/module/listmaster/service/list-master.service.js.map +1 -1
  17. package/dist/tsconfig.build.tsbuildinfo +1 -1
  18. package/package.json +1 -1
  19. package/src/module/listmaster/controller/list-master.controller.ts +13 -4
  20. package/src/module/listmaster/listmaster.module.ts +2 -2
  21. package/src/module/listmaster/repository/list-master-items.repository.ts +9 -2
  22. package/src/module/listmaster/repository/list-master.repository.ts +13 -8
  23. package/src/module/listmaster/service/list-master-item.service.ts +73 -22
  24. package/src/module/listmaster/service/list-master.service.ts +10 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.54",
3
+ "version": "2.1.55",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -9,6 +9,7 @@ import {
9
9
  Param,
10
10
  Post,
11
11
  Query,
12
+ Req,
12
13
  Request,
13
14
  UseGuards,
14
15
  } from '@nestjs/common';
@@ -21,6 +22,7 @@ export class ListMasterController {
21
22
  constructor(
22
23
  @Inject('ListMasterService')
23
24
  private readonly service: ListMasterService,
25
+ @Inject('ListMasterItemService')
24
26
  private readonly listMasterItemService: ListMasterItemService,
25
27
  ) {}
26
28
 
@@ -58,20 +60,27 @@ export class ListMasterController {
58
60
  @Post('/upsertListMasterItem/:type')
59
61
  @UseGuards(JwtAuthGuard)
60
62
  @HttpCode(HttpStatus.OK)
61
- async upsertListMasterItem(@Param('type') type: string, @Body() item: any) {
63
+ async upsertListMasterItem(
64
+ @Param('type') type: string,
65
+ @Body() item: any,
66
+ @Req() req: Request & { user: any },
67
+ ) {
68
+ let loggedInUser = req.user.userData;
69
+
62
70
  return await this.listMasterItemService.upsertListMasterItem(
63
71
  type,
64
72
  item.items,
73
+ loggedInUser,
65
74
  );
66
75
  }
67
76
 
68
- @Delete('/deleteListMasterItem/:type/:name')
77
+ @Delete('/deleteListMasterItem/:type/:code')
69
78
  @UseGuards(JwtAuthGuard)
70
79
  @HttpCode(HttpStatus.OK)
71
80
  async deleteListMasterItem(
72
81
  @Param('type') type: string,
73
- @Param('name') name: string,
82
+ @Param('code') code: string,
74
83
  ): Promise<string> {
75
- return await this.listMasterItemService.deleteListMasterItem(type, name);
84
+ return await this.listMasterItemService.deleteListMasterItem(type, code);
76
85
  }
77
86
  }
@@ -20,11 +20,11 @@ import { ListMasterItemService } from './service/list-master-item.service';
20
20
  ],
21
21
  providers: [
22
22
  { provide: 'ListMasterService', useClass: ListMasterService },
23
- ListMasterItemService,
23
+ { provide: 'ListMasterItemService', useClass: ListMasterItemService },
24
24
  ListMasterRepository,
25
25
  ListMasterItemsRepository,
26
26
  ],
27
27
  controllers: [ListMasterController],
28
- exports: ['ListMasterService'],
28
+ exports: ['ListMasterService', 'ListMasterItemService'],
29
29
  })
30
30
  export class ListMasterModule {}
@@ -28,9 +28,16 @@ export class ListMasterItemsRepository {
28
28
  return items.map((i) => ({ label: i.name, value: i.value }));
29
29
  }
30
30
 
31
- async findOneByNameAndType(name: string, type: string) {
31
+ async findAllItemsByListType(type: string, sortBy: string) {
32
+ return this.repo.find({
33
+ where: { listtype: type },
34
+ order: { sortindex: sortBy === 'asc' ? 'ASC' : 'DESC' },
35
+ });
36
+ }
37
+
38
+ async findOneByCodeAndType(code: string, type: string) {
32
39
  return this.repo.findOne({
33
- where: { name, listtype: type, status: 'active' },
40
+ where: { code, listtype: type },
34
41
  });
35
42
  }
36
43
 
@@ -4,12 +4,17 @@ import { Repository } from 'typeorm';
4
4
  import { InjectRepository } from '@nestjs/typeorm';
5
5
 
6
6
  @Injectable()
7
- export class ListMasterRepository{
7
+ export class ListMasterRepository {
8
+ constructor(
9
+ @InjectRepository(ListMasterData)
10
+ private readonly repo: Repository<ListMasterData>,
11
+ ) {}
8
12
 
9
- constructor(
10
- @InjectRepository(ListMasterData) private readonly repo: Repository<ListMasterData>) {}
11
-
12
- findByType(type: string) {
13
- return this.repo.findOne({ where: { type } });
14
- }
15
- }
13
+ findByType(type: string) {
14
+ return this.repo.findOne({ where: { type } });
15
+ }
16
+
17
+ findByName(name: string) {
18
+ return this.repo.findOne({ where: { name } });
19
+ }
20
+ }
@@ -1,55 +1,106 @@
1
- import { Injectable, NotFoundException } from '@nestjs/common';
1
+ import {
2
+ forwardRef,
3
+ Inject,
4
+ Injectable,
5
+ NotFoundException,
6
+ } from '@nestjs/common';
2
7
  import { ListMasterItemsRepository } from '../repository/list-master-items.repository';
8
+ import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
9
+ import { UserData } from 'src/module/user/entity/user.entity';
3
10
 
4
11
  @Injectable()
5
12
  export class ListMasterItemService {
6
13
  constructor(
7
14
  private readonly listItemsRepo: ListMasterItemsRepository,
8
15
  private readonly listMasterRepo: ListMasterItemsRepository,
16
+ @Inject(forwardRef(() => EntityServiceImpl))
17
+ private readonly entityServiceImpl: EntityServiceImpl,
9
18
  ) {}
10
19
 
11
- async getListMasterItemsByType(type: string) {
12
- return await this.listItemsRepo.findItemsByType(type);
20
+ async getListMasterItemsByType(listType: string) {
21
+ return await this.listItemsRepo.findAllItemsByListType(listType, 'asc');
13
22
  }
14
23
 
15
- async upsertListMasterItem(type: string, item: any[]): Promise<any> {
16
- // Check if list master item with type and name already exists then update it else create a new one
24
+ async createEntity(entityData: any, loggedInUser: UserData): Promise<any> {
25
+ return await this.entityServiceImpl.createEntity(entityData, loggedInUser);
26
+ }
17
27
 
18
- console.log('Upserting list master item for type:', type, item);
28
+ async updateEntity(entityData: any, loggedInUser: UserData): Promise<any> {
29
+ return await this.entityServiceImpl.updateEntity(entityData, loggedInUser);
30
+ }
19
31
 
20
- // will need to loop through the item array
21
- for (const i of item) {
22
- console.log('Processing item:', i);
23
- const existingItem = await this.listItemsRepo.findOneByNameAndType(
24
- i.name,
25
- type,
26
- );
32
+ async upsertListMasterItem(
33
+ listType: string,
34
+ items: any[],
35
+ loggedInUser,
36
+ ): Promise<any> {
37
+ console.log('Upserting list master items for type:', listType);
38
+
39
+ for (const item of items) {
40
+ console.log('Processing item:', item);
41
+
42
+ let existingItem;
43
+
44
+ // If code is provided, use it for lookup
45
+ if (item.code) {
46
+ console.log('Code provided:', item.code);
47
+ existingItem = await this.listItemsRepo.findOneByCodeAndType(
48
+ item.code,
49
+ listType,
50
+ );
51
+
52
+ console.log('Existing item found by code:', existingItem);
53
+ }
27
54
 
28
55
  console.log('Existing item found:', existingItem);
29
56
 
30
57
  if (existingItem) {
31
- await this.listItemsRepo.update(existingItem.id, i);
58
+ await this.updateEntity(
59
+ {
60
+ ...existingItem,
61
+ ...item,
62
+ listtype: listType,
63
+ },
64
+ loggedInUser,
65
+ );
32
66
  } else {
33
- await this.listItemsRepo.create(i);
67
+ const createdItem = await this.createEntity(
68
+ {
69
+ ...item,
70
+ listtype: listType,
71
+ value: '',
72
+ },
73
+ loggedInUser,
74
+ );
75
+
76
+ // now update the value of the item to its code
77
+ console.log('Created item, updating value to code:', createdItem.code);
78
+
79
+ await this.listItemsRepo.update(createdItem.id, {
80
+ value: createdItem.code,
81
+ });
34
82
  }
35
83
  }
36
84
 
37
- const updatedItems = await this.listItemsRepo.findItemsByType(type);
85
+ const updatedItems = await this.listItemsRepo.findAllItemsByListType(
86
+ listType,
87
+ 'asc',
88
+ );
38
89
 
39
90
  return {
40
- type,
91
+ listType,
41
92
  items: updatedItems,
42
93
  };
43
94
  }
44
95
 
45
- async deleteListMasterItem(type: string, name: string): Promise<string> {
46
- const item = await this.listItemsRepo.findOneByNameAndType(name, type);
96
+ async deleteListMasterItem(listType: string, code: string): Promise<string> {
97
+ const item = await this.listItemsRepo.findOneByCodeAndType(code, listType);
47
98
  if (!item) {
48
99
  throw new NotFoundException(
49
- `Item with name ${name} not found in type ${type}`,
100
+ `Item with name ${code} not found in type ${listType}`,
50
101
  );
51
102
  }
52
- await this.listItemsRepo.delete({ listtype: type, name: name });
53
- return `Item with name ${name} deleted successfully from type ${type}`;
103
+ await this.listItemsRepo.delete({ code, listtype: listType });
104
+ return `Item with name ${code} deleted successfully from type ${listType}`;
54
105
  }
55
106
  }
@@ -242,14 +242,16 @@ export class ListMasterService {
242
242
  entityData.is_factory = entityData.is_factory || 0;
243
243
  entityData.source = entityData.source || 'master';
244
244
  entityData.status = entityData.status || 'ACTIVE';
245
+ entityData.type = entityData.type || 'LIST_MASTER';
245
246
 
246
247
  // check if a list master with the same type already exists
247
- const existingListMaster = await this.listMasterRepo.findByType(
248
- entityData.type,
248
+ const existingListMaster = await this.listMasterRepo.findByName(
249
+ entityData.name,
249
250
  );
251
+
250
252
  if (existingListMaster) {
251
253
  throw new BadRequestException(
252
- 'List master with the same type already exists.',
254
+ 'List master with the same name already exists',
253
255
  );
254
256
  }
255
257
 
@@ -262,6 +264,11 @@ export class ListMasterService {
262
264
  throw new BadRequestException('Failed to create entity');
263
265
  }
264
266
 
267
+ createdListMaster.type = createdListMaster.code;
268
+
269
+ // update the type of the created list master to code
270
+ await this.entityServiceImpl.updateEntity(createdListMaster, loggedInUser);
271
+
265
272
  return createdListMaster;
266
273
  }
267
274