rez_core 2.1.106 → 2.1.107

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.106",
3
+ "version": "2.1.107",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -1,6 +1,6 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { InjectRepository } from '@nestjs/typeorm';
3
- import { Repository } from 'typeorm';
3
+ import { Repository, In } from 'typeorm';
4
4
  import { ListMasterItems } from '../entity/list-master-items.entity';
5
5
 
6
6
  @Injectable()
@@ -20,7 +20,12 @@ export class ListMasterItemsRepository {
20
20
  return this.repo.findOne({ where: { id } });
21
21
  }
22
22
 
23
- async findItemsByType(type: string, sort_by?, organizationId?: number) {
23
+ async findItemsByType(
24
+ type: string,
25
+ sort_by?,
26
+ inactiveIdsArray?: number[],
27
+ organizationId?: number,
28
+ ) {
24
29
  let orderBy: Record<string, 'ASC' | 'DESC'> = {}; // no default sort unless specified
25
30
 
26
31
  // Only sort if sort_by is provided
@@ -57,7 +62,29 @@ export class ListMasterItemsRepository {
57
62
  order: orderBy,
58
63
  });
59
64
 
60
- return items.map((i) => ({ label: i.name, value: i.id }));
65
+ let result = items.map((i) => ({ label: i.name, value: i.id }));
66
+
67
+ // If inactive IDs are passed, fetch them
68
+ if (inactiveIdsArray?.length) {
69
+ const inactiveItems = await this.repo.find({
70
+ where: {
71
+ listtype: type,
72
+ organization_id: organizationId,
73
+ status: 'INACTIVE',
74
+ id: In(inactiveIdsArray),
75
+ },
76
+ order: orderBy,
77
+ });
78
+
79
+ const inactiveMapped = inactiveItems.map((i) => ({
80
+ label: `${i.name} [INACTIVE]`,
81
+ value: i.id,
82
+ }));
83
+
84
+ result = [...result, ...inactiveMapped];
85
+ }
86
+
87
+ return result;
61
88
  }
62
89
 
63
90
  async findOperatorsByType(type: string, organizationId?: number) {
@@ -58,7 +58,6 @@ export class ListMasterService {
58
58
  loggedInUser?.organization_id,
59
59
  );
60
60
 
61
- console.log(config, 'config');
62
61
  if (!config) throw new NotFoundException(`Type ${type} not found`);
63
62
 
64
63
  switch (config.source) {
@@ -74,6 +73,7 @@ export class ListMasterService {
74
73
  return this.listItemsRepo.findItemsByType(
75
74
  type,
76
75
  config.sort_by,
76
+ inactiveIdsArray,
77
77
  loggedInUser?.organization_id,
78
78
  );
79
79
 
@@ -108,8 +108,9 @@ export class ListMasterService {
108
108
 
109
109
  const applyCommonFilters = (qb: any, status?: number) => {
110
110
  if (status) {
111
- qb.where(`${tableName}.status = :status`, { status });
112
- qb.orWhere(`${tableName}.status = 'Active'`);
111
+ const isView = tableName.endsWith('_vw'); // auto-detect view
112
+ const statusColumn = isView ? 'status_id' : 'status';
113
+ qb.andWhere(`${tableName}.${statusColumn} = :status`, { status });
113
114
  }
114
115
 
115
116
  if (loggedInUser?.level_type && loggedInUser?.level_id) {
@@ -159,7 +160,7 @@ export class ListMasterService {
159
160
  .createQueryBuilder()
160
161
  .select('*')
161
162
  .from(tableName, tableName),
162
- resolveStatus.id || null,
163
+ resolveStatus.id,
163
164
  );
164
165
 
165
166
  const activeResults = await activeQuery.getRawMany();
@@ -182,7 +183,7 @@ export class ListMasterService {
182
183
  .createQueryBuilder()
183
184
  .select('*')
184
185
  .from(tableName, tableName),
185
- resolveInactiveStatus.id || null,
186
+ resolveInactiveStatus.id,
186
187
  );
187
188
 
188
189
  inactiveQuery.andWhere(`${tableName}.id IN (:...ids)`, {