rez_core 2.1.53 → 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.
- package/dist/module/listmaster/controller/list-master.controller.d.ts +8 -1
- package/dist/module/listmaster/controller/list-master.controller.js +48 -2
- package/dist/module/listmaster/controller/list-master.controller.js.map +1 -1
- package/dist/module/listmaster/entity/list-master.entity.d.ts +1 -0
- package/dist/module/listmaster/entity/list-master.entity.js +4 -0
- package/dist/module/listmaster/entity/list-master.entity.js.map +1 -1
- package/dist/module/listmaster/listmaster.module.js +14 -3
- package/dist/module/listmaster/listmaster.module.js.map +1 -1
- package/dist/module/listmaster/repository/list-master-items.repository.d.ts +5 -0
- package/dist/module/listmaster/repository/list-master-items.repository.js +23 -1
- package/dist/module/listmaster/repository/list-master-items.repository.js.map +1 -1
- package/dist/module/listmaster/repository/list-master.repository.d.ts +1 -0
- package/dist/module/listmaster/repository/list-master.repository.js +3 -0
- package/dist/module/listmaster/repository/list-master.repository.js.map +1 -1
- package/dist/module/listmaster/service/list-master-item.service.d.ts +14 -0
- package/dist/module/listmaster/service/list-master-item.service.js +87 -0
- package/dist/module/listmaster/service/list-master-item.service.js.map +1 -0
- package/dist/module/listmaster/service/list-master.service.d.ts +6 -1
- package/dist/module/listmaster/service/list-master.service.js +31 -1
- package/dist/module/listmaster/service/list-master.service.js.map +1 -1
- package/dist/module/meta/controller/entity.controller.js +1 -1
- package/dist/module/meta/controller/entity.controller.js.map +1 -1
- package/dist/module/meta/service/entity-table.service.js +2 -1
- package/dist/module/meta/service/entity-table.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 +45 -1
- package/src/module/listmaster/entity/list-master.entity.ts +3 -0
- package/src/module/listmaster/listmaster.module.ts +14 -3
- package/src/module/listmaster/repository/list-master-items.repository.ts +39 -13
- package/src/module/listmaster/repository/list-master.repository.ts +13 -8
- package/src/module/listmaster/service/list-master-item.service.ts +106 -0
- package/src/module/listmaster/service/list-master.service.ts +48 -1
- package/src/module/meta/controller/entity.controller.ts +1 -1
- package/src/module/meta/service/entity-table.service.ts +3 -1
package/package.json
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Body,
|
|
3
3
|
Controller,
|
|
4
|
+
Delete,
|
|
5
|
+
Get,
|
|
4
6
|
HttpCode,
|
|
5
7
|
HttpStatus,
|
|
8
|
+
Inject,
|
|
6
9
|
Param,
|
|
7
10
|
Post,
|
|
8
11
|
Query,
|
|
12
|
+
Req,
|
|
9
13
|
Request,
|
|
10
14
|
UseGuards,
|
|
11
15
|
} from '@nestjs/common';
|
|
12
16
|
import { ListMasterService } from '../service/list-master.service';
|
|
13
17
|
import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
|
|
18
|
+
import { ListMasterItemService } from '../service/list-master-item.service';
|
|
14
19
|
|
|
15
20
|
@Controller('list-master')
|
|
16
21
|
export class ListMasterController {
|
|
17
|
-
constructor(
|
|
22
|
+
constructor(
|
|
23
|
+
@Inject('ListMasterService')
|
|
24
|
+
private readonly service: ListMasterService,
|
|
25
|
+
@Inject('ListMasterItemService')
|
|
26
|
+
private readonly listMasterItemService: ListMasterItemService,
|
|
27
|
+
) {}
|
|
18
28
|
|
|
19
29
|
@Post('/getDropdownData/:type')
|
|
20
30
|
@UseGuards(JwtAuthGuard)
|
|
@@ -39,4 +49,38 @@ export class ListMasterController {
|
|
|
39
49
|
loggedInUser,
|
|
40
50
|
);
|
|
41
51
|
}
|
|
52
|
+
|
|
53
|
+
@Get('/getListMasterItems/:type')
|
|
54
|
+
@UseGuards(JwtAuthGuard)
|
|
55
|
+
@HttpCode(HttpStatus.OK)
|
|
56
|
+
async getListMasterItems(@Param('type') type: string) {
|
|
57
|
+
console.log('Fetching list master items for type:', type);
|
|
58
|
+
return await this.listMasterItemService.getListMasterItemsByType(type);
|
|
59
|
+
}
|
|
60
|
+
@Post('/upsertListMasterItem/:type')
|
|
61
|
+
@UseGuards(JwtAuthGuard)
|
|
62
|
+
@HttpCode(HttpStatus.OK)
|
|
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
|
+
|
|
70
|
+
return await this.listMasterItemService.upsertListMasterItem(
|
|
71
|
+
type,
|
|
72
|
+
item.items,
|
|
73
|
+
loggedInUser,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@Delete('/deleteListMasterItem/:type/:code')
|
|
78
|
+
@UseGuards(JwtAuthGuard)
|
|
79
|
+
@HttpCode(HttpStatus.OK)
|
|
80
|
+
async deleteListMasterItem(
|
|
81
|
+
@Param('type') type: string,
|
|
82
|
+
@Param('code') code: string,
|
|
83
|
+
): Promise<string> {
|
|
84
|
+
return await this.listMasterItemService.deleteListMasterItem(type, code);
|
|
85
|
+
}
|
|
42
86
|
}
|
|
@@ -9,11 +9,22 @@ import { EntityModule } from '../meta/entity.module';
|
|
|
9
9
|
import { ListMasterController } from './controller/list-master.controller';
|
|
10
10
|
import { ThirdPartyModule } from '../third-party-module/third-party.module';
|
|
11
11
|
import { HttpModule } from '@nestjs/axios';
|
|
12
|
+
import { ListMasterItemService } from './service/list-master-item.service';
|
|
12
13
|
|
|
13
14
|
@Module({
|
|
14
|
-
imports: [
|
|
15
|
-
|
|
15
|
+
imports: [
|
|
16
|
+
TypeOrmModule.forFeature([ListMasterData, ListMasterItems]),
|
|
17
|
+
forwardRef(() => EntityModule),
|
|
18
|
+
ThirdPartyModule,
|
|
19
|
+
HttpModule,
|
|
20
|
+
],
|
|
21
|
+
providers: [
|
|
22
|
+
{ provide: 'ListMasterService', useClass: ListMasterService },
|
|
23
|
+
{ provide: 'ListMasterItemService', useClass: ListMasterItemService },
|
|
24
|
+
ListMasterRepository,
|
|
25
|
+
ListMasterItemsRepository,
|
|
26
|
+
],
|
|
16
27
|
controllers: [ListMasterController],
|
|
17
|
-
exports:[ListMasterService]
|
|
28
|
+
exports: ['ListMasterService', 'ListMasterItemService'],
|
|
18
29
|
})
|
|
19
30
|
export class ListMasterModule {}
|
|
@@ -4,18 +4,44 @@ import { Repository } from 'typeorm';
|
|
|
4
4
|
import { ListMasterItems } from '../entity/list-master-items.entity';
|
|
5
5
|
|
|
6
6
|
@Injectable()
|
|
7
|
-
export class ListMasterItemsRepository{
|
|
7
|
+
export class ListMasterItemsRepository {
|
|
8
|
+
constructor(
|
|
9
|
+
@InjectRepository(ListMasterItems)
|
|
10
|
+
private repo: Repository<ListMasterItems>,
|
|
11
|
+
) {}
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
async findItemsByType(type: string) {
|
|
14
|
-
const items = await this.repo.find({
|
|
15
|
-
where: { listtype: type, status: 'active' },
|
|
16
|
-
order: { sortindex: 'ASC' },
|
|
17
|
-
});
|
|
18
|
-
return items.map(i => ({ label: i.name, value: i.value }));
|
|
19
|
-
}
|
|
13
|
+
async create(item: Partial<ListMasterItems>) {
|
|
14
|
+
const newItem = this.repo.create(item);
|
|
15
|
+
return this.repo.save(newItem);
|
|
16
|
+
}
|
|
20
17
|
|
|
21
|
-
|
|
18
|
+
async update(id: number, item: Partial<ListMasterItems>) {
|
|
19
|
+
await this.repo.update(id, item);
|
|
20
|
+
return this.repo.findOne({ where: { id } });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async findItemsByType(type: string) {
|
|
24
|
+
const items = await this.repo.find({
|
|
25
|
+
where: { listtype: type, status: 'active' },
|
|
26
|
+
order: { sortindex: 'ASC' },
|
|
27
|
+
});
|
|
28
|
+
return items.map((i) => ({ label: i.name, value: i.value }));
|
|
29
|
+
}
|
|
30
|
+
|
|
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) {
|
|
39
|
+
return this.repo.findOne({
|
|
40
|
+
where: { code, listtype: type },
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async delete(item: Partial<ListMasterItems>) {
|
|
45
|
+
return this.repo.delete(item);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
Inject,
|
|
4
|
+
Injectable,
|
|
5
|
+
NotFoundException,
|
|
6
|
+
} from '@nestjs/common';
|
|
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';
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
export class ListMasterItemService {
|
|
13
|
+
constructor(
|
|
14
|
+
private readonly listItemsRepo: ListMasterItemsRepository,
|
|
15
|
+
private readonly listMasterRepo: ListMasterItemsRepository,
|
|
16
|
+
@Inject(forwardRef(() => EntityServiceImpl))
|
|
17
|
+
private readonly entityServiceImpl: EntityServiceImpl,
|
|
18
|
+
) {}
|
|
19
|
+
|
|
20
|
+
async getListMasterItemsByType(listType: string) {
|
|
21
|
+
return await this.listItemsRepo.findAllItemsByListType(listType, 'asc');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async createEntity(entityData: any, loggedInUser: UserData): Promise<any> {
|
|
25
|
+
return await this.entityServiceImpl.createEntity(entityData, loggedInUser);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async updateEntity(entityData: any, loggedInUser: UserData): Promise<any> {
|
|
29
|
+
return await this.entityServiceImpl.updateEntity(entityData, loggedInUser);
|
|
30
|
+
}
|
|
31
|
+
|
|
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
|
+
}
|
|
54
|
+
|
|
55
|
+
console.log('Existing item found:', existingItem);
|
|
56
|
+
|
|
57
|
+
if (existingItem) {
|
|
58
|
+
await this.updateEntity(
|
|
59
|
+
{
|
|
60
|
+
...existingItem,
|
|
61
|
+
...item,
|
|
62
|
+
listtype: listType,
|
|
63
|
+
},
|
|
64
|
+
loggedInUser,
|
|
65
|
+
);
|
|
66
|
+
} else {
|
|
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
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const updatedItems = await this.listItemsRepo.findAllItemsByListType(
|
|
86
|
+
listType,
|
|
87
|
+
'asc',
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
listType,
|
|
92
|
+
items: updatedItems,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async deleteListMasterItem(listType: string, code: string): Promise<string> {
|
|
97
|
+
const item = await this.listItemsRepo.findOneByCodeAndType(code, listType);
|
|
98
|
+
if (!item) {
|
|
99
|
+
throw new NotFoundException(
|
|
100
|
+
`Item with name ${code} not found in type ${listType}`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
await this.listItemsRepo.delete({ code, listtype: listType });
|
|
104
|
+
return `Item with name ${code} deleted successfully from type ${listType}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { EntityServiceImpl } from '../../meta/service/entity-service-impl.service';
|
|
2
1
|
import {
|
|
3
2
|
BadRequestException,
|
|
3
|
+
forwardRef,
|
|
4
|
+
Inject,
|
|
4
5
|
Injectable,
|
|
5
6
|
NotFoundException,
|
|
6
7
|
} from '@nestjs/common';
|
|
@@ -13,11 +14,14 @@ import { EntityManager } from 'typeorm';
|
|
|
13
14
|
import { EntityMasterService } from 'src/module/meta/service/entity-master.service';
|
|
14
15
|
import { UserData } from 'src/module/user/entity/user.entity';
|
|
15
16
|
import { log } from 'console';
|
|
17
|
+
import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
|
|
16
18
|
|
|
17
19
|
@Injectable()
|
|
18
20
|
export class ListMasterService {
|
|
19
21
|
constructor(
|
|
20
22
|
private readonly entityManager: EntityManager,
|
|
23
|
+
@Inject(forwardRef(() => EntityServiceImpl))
|
|
24
|
+
private readonly entityServiceImpl: EntityServiceImpl,
|
|
21
25
|
private readonly entityMasterService: EntityMasterService,
|
|
22
26
|
private readonly listMasterRepo: ListMasterRepository,
|
|
23
27
|
private readonly listItemsRepo: ListMasterItemsRepository,
|
|
@@ -232,4 +236,47 @@ export class ListMasterService {
|
|
|
232
236
|
return acc[key];
|
|
233
237
|
}, obj);
|
|
234
238
|
}
|
|
239
|
+
|
|
240
|
+
// createEntity method
|
|
241
|
+
async createEntity(entityData: any, loggedInUser: UserData): Promise<any> {
|
|
242
|
+
entityData.is_factory = entityData.is_factory || 0;
|
|
243
|
+
entityData.source = entityData.source || 'master';
|
|
244
|
+
entityData.status = entityData.status || 'ACTIVE';
|
|
245
|
+
entityData.type = entityData.type || 'LIST_MASTER';
|
|
246
|
+
|
|
247
|
+
// check if a list master with the same type already exists
|
|
248
|
+
const existingListMaster = await this.listMasterRepo.findByName(
|
|
249
|
+
entityData.name,
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
if (existingListMaster) {
|
|
253
|
+
throw new BadRequestException(
|
|
254
|
+
'List master with the same name already exists',
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const createdListMaster = await this.entityServiceImpl.createEntity(
|
|
259
|
+
entityData,
|
|
260
|
+
loggedInUser,
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
if (!createdListMaster) {
|
|
264
|
+
throw new BadRequestException('Failed to create entity');
|
|
265
|
+
}
|
|
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
|
+
|
|
272
|
+
return createdListMaster;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async updateEntity(entityData: any, loggedInUser: UserData): Promise<any> {
|
|
276
|
+
return await this.entityServiceImpl.updateEntity(entityData, loggedInUser);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async getEntityData(entity_type: string, id: number): Promise<any> {
|
|
280
|
+
return await this.entityServiceImpl.getEntityData(entity_type, id);
|
|
281
|
+
}
|
|
235
282
|
}
|
|
@@ -12,7 +12,9 @@ export class EntityTableService {
|
|
|
12
12
|
constructor(
|
|
13
13
|
private entityTableRepository: EntityTableRepository,
|
|
14
14
|
private readonly entityTableColumnRepository: EntityTableColumnRepository,
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
@Inject(forwardRef(() => 'ListMasterService'))
|
|
17
|
+
@Inject('ListMasterService')
|
|
16
18
|
private readonly listMasterService: ListMasterService,
|
|
17
19
|
|
|
18
20
|
private readonly savedFilterRepoService: SavedFilterRepositoryService,
|