rez_core 2.1.54 → 2.1.56

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 (25) hide show
  1. package/dist/module/listmaster/controller/list-master.controller.d.ts +6 -6
  2. package/dist/module/listmaster/controller/list-master.controller.js +26 -11
  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 +12 -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 +2 -0
  10. package/dist/module/listmaster/repository/list-master.repository.js +12 -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 +43 -19
  14. package/dist/module/listmaster/service/list-master-item.service.js.map +1 -1
  15. package/dist/module/listmaster/service/list-master.service.d.ts +1 -0
  16. package/dist/module/listmaster/service/list-master.service.js +9 -2
  17. package/dist/module/listmaster/service/list-master.service.js.map +1 -1
  18. package/dist/tsconfig.build.tsbuildinfo +1 -1
  19. package/package.json +1 -1
  20. package/src/module/listmaster/controller/list-master.controller.ts +31 -7
  21. package/src/module/listmaster/listmaster.module.ts +2 -2
  22. package/src/module/listmaster/repository/list-master-items.repository.ts +19 -2
  23. package/src/module/listmaster/repository/list-master.repository.ts +29 -9
  24. package/src/module/listmaster/service/list-master-item.service.ts +64 -23
  25. package/src/module/listmaster/service/list-master.service.ts +15 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.54",
3
+ "version": "2.1.56",
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
 
@@ -51,27 +53,49 @@ export class ListMasterController {
51
53
  @Get('/getListMasterItems/:type')
52
54
  @UseGuards(JwtAuthGuard)
53
55
  @HttpCode(HttpStatus.OK)
54
- async getListMasterItems(@Param('type') type: string) {
55
- console.log('Fetching list master items for type:', type);
56
- return await this.listMasterItemService.getListMasterItemsByType(type);
56
+ async getListMasterItems(
57
+ @Param('type') type: string,
58
+ @Query('search') search?: string,
59
+ ) {
60
+ return await this.listMasterItemService.getListMasterItemsByType(
61
+ type,
62
+ search,
63
+ );
57
64
  }
65
+
66
+ @Get('')
67
+ @UseGuards(JwtAuthGuard)
68
+ @HttpCode(HttpStatus.OK)
69
+ async getAllListMasterItems(
70
+ @Query('search') search?: string,
71
+ ): Promise<any[]> {
72
+ return await this.service.getAllListMasterItems(search);
73
+ }
74
+
58
75
  @Post('/upsertListMasterItem/:type')
59
76
  @UseGuards(JwtAuthGuard)
60
77
  @HttpCode(HttpStatus.OK)
61
- async upsertListMasterItem(@Param('type') type: string, @Body() item: any) {
78
+ async upsertListMasterItem(
79
+ @Param('type') type: string,
80
+ @Body() item: any,
81
+ @Req() req: Request & { user: any },
82
+ ) {
83
+ let loggedInUser = req.user.userData;
84
+
62
85
  return await this.listMasterItemService.upsertListMasterItem(
63
86
  type,
64
87
  item.items,
88
+ loggedInUser,
65
89
  );
66
90
  }
67
91
 
68
- @Delete('/deleteListMasterItem/:type/:name')
92
+ @Delete('/deleteListMasterItem/:type/:code')
69
93
  @UseGuards(JwtAuthGuard)
70
94
  @HttpCode(HttpStatus.OK)
71
95
  async deleteListMasterItem(
72
96
  @Param('type') type: string,
73
- @Param('name') name: string,
97
+ @Param('code') code: string,
74
98
  ): Promise<string> {
75
- return await this.listMasterItemService.deleteListMasterItem(type, name);
99
+ return await this.listMasterItemService.deleteListMasterItem(type, code);
76
100
  }
77
101
  }
@@ -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,26 @@ 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, search?: string) {
32
+ const qb = this.repo
33
+ .createQueryBuilder('item')
34
+ .where('item.listtype = :type', { type });
35
+
36
+ if (search?.trim()) {
37
+ qb.andWhere(
38
+ '(LOWER(item.name) LIKE :search OR LOWER(item.code) LIKE :search)',
39
+ { search: `%${search.toLowerCase()}%` },
40
+ );
41
+ }
42
+
43
+ qb.orderBy('item.sortindex', sortBy === 'asc' ? 'ASC' : 'DESC');
44
+
45
+ return await qb.getMany();
46
+ }
47
+
48
+ async findOneByCodeAndType(code: string, type: string) {
32
49
  return this.repo.findOne({
33
- where: { name, listtype: type, status: 'active' },
50
+ where: { code, listtype: type },
34
51
  });
35
52
  }
36
53
 
@@ -4,12 +4,32 @@ import { Repository } from 'typeorm';
4
4
  import { InjectRepository } from '@nestjs/typeorm';
5
5
 
6
6
  @Injectable()
7
- export class ListMasterRepository{
8
-
9
- constructor(
10
- @InjectRepository(ListMasterData) private readonly repo: Repository<ListMasterData>) {}
11
-
12
- findByType(type: string) {
13
- return this.repo.findOne({ where: { type } });
14
- }
15
- }
7
+ export class ListMasterRepository {
8
+ constructor(
9
+ @InjectRepository(ListMasterData)
10
+ private readonly repo: Repository<ListMasterData>,
11
+ ) {}
12
+
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
+
21
+ async findAllItems(search?: string) {
22
+ const qb = this.repo
23
+ .createQueryBuilder('item')
24
+ .where('item.source = :source', { source: 'master' });
25
+
26
+ if (search?.trim()) {
27
+ qb.andWhere(
28
+ '(LOWER(item.name) LIKE :search OR LOWER(item.code) LIKE :search)',
29
+ { search: `%${search.toLowerCase()}%` },
30
+ );
31
+ }
32
+
33
+ return await qb.getMany();
34
+ }
35
+ }
@@ -1,55 +1,96 @@
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, search?: string) {
21
+ return this.listItemsRepo.findAllItemsByListType(listType, 'asc', search);
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
+ for (const item of items) {
38
+ let existingItem;
27
39
 
28
- console.log('Existing item found:', existingItem);
40
+ // If code is provided, use it for lookup
41
+ if (item.code) {
42
+ existingItem = await this.listItemsRepo.findOneByCodeAndType(
43
+ item.code,
44
+ listType,
45
+ );
46
+ }
29
47
 
30
48
  if (existingItem) {
31
- await this.listItemsRepo.update(existingItem.id, i);
49
+ await this.updateEntity(
50
+ {
51
+ ...existingItem,
52
+ ...item,
53
+ listtype: listType,
54
+ },
55
+ loggedInUser,
56
+ );
32
57
  } else {
33
- await this.listItemsRepo.create(i);
58
+ const createdItem = await this.createEntity(
59
+ {
60
+ ...item,
61
+ listtype: listType,
62
+ value: '',
63
+ },
64
+ loggedInUser,
65
+ );
66
+
67
+ // now update the value of the item to its code
68
+
69
+ await this.listItemsRepo.update(createdItem.id, {
70
+ value: createdItem.code,
71
+ });
34
72
  }
35
73
  }
36
74
 
37
- const updatedItems = await this.listItemsRepo.findItemsByType(type);
75
+ const updatedItems = await this.listItemsRepo.findAllItemsByListType(
76
+ listType,
77
+ 'asc',
78
+ );
38
79
 
39
80
  return {
40
- type,
81
+ listType,
41
82
  items: updatedItems,
42
83
  };
43
84
  }
44
85
 
45
- async deleteListMasterItem(type: string, name: string): Promise<string> {
46
- const item = await this.listItemsRepo.findOneByNameAndType(name, type);
86
+ async deleteListMasterItem(listType: string, code: string): Promise<string> {
87
+ const item = await this.listItemsRepo.findOneByCodeAndType(code, listType);
47
88
  if (!item) {
48
89
  throw new NotFoundException(
49
- `Item with name ${name} not found in type ${type}`,
90
+ `Item with name ${code} not found in type ${listType}`,
50
91
  );
51
92
  }
52
- await this.listItemsRepo.delete({ listtype: type, name: name });
53
- return `Item with name ${name} deleted successfully from type ${type}`;
93
+ await this.listItemsRepo.delete({ code, listtype: listType });
94
+ return `Item with name ${code} deleted successfully from type ${listType}`;
54
95
  }
55
96
  }
@@ -13,7 +13,6 @@ import { HttpService } from '@nestjs/axios';
13
13
  import { EntityManager } from 'typeorm';
14
14
  import { EntityMasterService } from 'src/module/meta/service/entity-master.service';
15
15
  import { UserData } from 'src/module/user/entity/user.entity';
16
- import { log } from 'console';
17
16
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
18
17
 
19
18
  @Injectable()
@@ -242,14 +241,17 @@ export class ListMasterService {
242
241
  entityData.is_factory = entityData.is_factory || 0;
243
242
  entityData.source = entityData.source || 'master';
244
243
  entityData.status = entityData.status || 'ACTIVE';
244
+ entityData.type = entityData.type || 'LIST_MASTER';
245
+ entityData.sort_by = entityData.sort_by || 'asc';
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
 
@@ -272,4 +279,8 @@ export class ListMasterService {
272
279
  async getEntityData(entity_type: string, id: number): Promise<any> {
273
280
  return await this.entityServiceImpl.getEntityData(entity_type, id);
274
281
  }
282
+
283
+ async getAllListMasterItems(search?: string): Promise<any[]> {
284
+ return await this.listMasterRepo.findAllItems(search);
285
+ }
275
286
  }