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.
- package/dist/module/listmaster/controller/list-master.controller.d.ts +6 -6
- package/dist/module/listmaster/controller/list-master.controller.js +26 -11
- package/dist/module/listmaster/controller/list-master.controller.js.map +1 -1
- package/dist/module/listmaster/listmaster.module.js +2 -2
- package/dist/module/listmaster/listmaster.module.js.map +1 -1
- package/dist/module/listmaster/repository/list-master-items.repository.d.ts +2 -1
- package/dist/module/listmaster/repository/list-master-items.repository.js +12 -2
- package/dist/module/listmaster/repository/list-master-items.repository.js.map +1 -1
- package/dist/module/listmaster/repository/list-master.repository.d.ts +2 -0
- package/dist/module/listmaster/repository/list-master.repository.js +12 -0
- package/dist/module/listmaster/repository/list-master.repository.js.map +1 -1
- package/dist/module/listmaster/service/list-master-item.service.d.ts +9 -7
- package/dist/module/listmaster/service/list-master-item.service.js +43 -19
- package/dist/module/listmaster/service/list-master-item.service.js.map +1 -1
- package/dist/module/listmaster/service/list-master.service.d.ts +1 -0
- package/dist/module/listmaster/service/list-master.service.js +9 -2
- package/dist/module/listmaster/service/list-master.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/listmaster/controller/list-master.controller.ts +31 -7
- package/src/module/listmaster/listmaster.module.ts +2 -2
- package/src/module/listmaster/repository/list-master-items.repository.ts +19 -2
- package/src/module/listmaster/repository/list-master.repository.ts +29 -9
- package/src/module/listmaster/service/list-master-item.service.ts +64 -23
- package/src/module/listmaster/service/list-master.service.ts +15 -4
package/package.json
CHANGED
|
@@ -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(
|
|
55
|
-
|
|
56
|
-
|
|
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(
|
|
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/:
|
|
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('
|
|
97
|
+
@Param('code') code: string,
|
|
74
98
|
): Promise<string> {
|
|
75
|
-
return await this.listMasterItemService.deleteListMasterItem(type,
|
|
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
|
|
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: {
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 {
|
|
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(
|
|
12
|
-
return
|
|
20
|
+
async getListMasterItemsByType(listType: string, search?: string) {
|
|
21
|
+
return this.listItemsRepo.findAllItemsByListType(listType, 'asc', search);
|
|
13
22
|
}
|
|
14
23
|
|
|
15
|
-
async
|
|
16
|
-
|
|
24
|
+
async createEntity(entityData: any, loggedInUser: UserData): Promise<any> {
|
|
25
|
+
return await this.entityServiceImpl.createEntity(entityData, loggedInUser);
|
|
26
|
+
}
|
|
17
27
|
|
|
18
|
-
|
|
28
|
+
async updateEntity(entityData: any, loggedInUser: UserData): Promise<any> {
|
|
29
|
+
return await this.entityServiceImpl.updateEntity(entityData, loggedInUser);
|
|
30
|
+
}
|
|
19
31
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
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.
|
|
49
|
+
await this.updateEntity(
|
|
50
|
+
{
|
|
51
|
+
...existingItem,
|
|
52
|
+
...item,
|
|
53
|
+
listtype: listType,
|
|
54
|
+
},
|
|
55
|
+
loggedInUser,
|
|
56
|
+
);
|
|
32
57
|
} else {
|
|
33
|
-
await this.
|
|
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.
|
|
75
|
+
const updatedItems = await this.listItemsRepo.findAllItemsByListType(
|
|
76
|
+
listType,
|
|
77
|
+
'asc',
|
|
78
|
+
);
|
|
38
79
|
|
|
39
80
|
return {
|
|
40
|
-
|
|
81
|
+
listType,
|
|
41
82
|
items: updatedItems,
|
|
42
83
|
};
|
|
43
84
|
}
|
|
44
85
|
|
|
45
|
-
async deleteListMasterItem(
|
|
46
|
-
const item = await this.listItemsRepo.
|
|
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 ${
|
|
90
|
+
`Item with name ${code} not found in type ${listType}`,
|
|
50
91
|
);
|
|
51
92
|
}
|
|
52
|
-
await this.listItemsRepo.delete({
|
|
53
|
-
return `Item with name ${
|
|
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.
|
|
248
|
-
entityData.
|
|
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
|
|
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
|
}
|