hgs-twilio-class-lib 1.1.86 → 1.1.87

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.
@@ -35,6 +35,7 @@ export declare class RealTimeDashboardController {
35
35
  editItem(reqBody: {
36
36
  syncMapName: string;
37
37
  data: RealtimeDashboardSummaryModel;
38
+ ifMatch: string | undefined;
38
39
  }): Promise<any>;
39
40
  deleteItem(query: Pick<RealtimeDashboardSummaryModel, "id"> & {
40
41
  syncMapName: string;
@@ -171,7 +171,7 @@ class RealTimeDashboardController {
171
171
  query.allowedFields = allowedFields;
172
172
  }
173
173
  query.category = "QueueDetails";
174
- let result = yield table.getAll(query);
174
+ let result = yield table.getAllItems(query);
175
175
  return { result, meta: query };
176
176
  }
177
177
  catch (error) {
@@ -183,7 +183,7 @@ class RealTimeDashboardController {
183
183
  editItem(reqBody) {
184
184
  return __awaiter(this, void 0, void 0, function* () {
185
185
  try {
186
- const { syncMapName, data } = reqBody;
186
+ const { syncMapName, data, ifMatch } = reqBody;
187
187
  if (!syncMapName) {
188
188
  throw new Error("syncMapName is required.");
189
189
  }
@@ -194,7 +194,7 @@ class RealTimeDashboardController {
194
194
  const dbTransaction = yield this.getItemTransaction(syncMapName);
195
195
  const table = dbTransaction.objectStore(syncMapName);
196
196
  const key = queuedetails.id;
197
- const result = yield table.put(queuedetails.serialize, key);
197
+ const result = yield table.putItem(queuedetails.serialize, key, ifMatch);
198
198
  return result;
199
199
  }
200
200
  catch (error) {
@@ -15,6 +15,8 @@ export declare class SyncMapItem extends ServiceObjectStore {
15
15
  get(query: IDBValidKey | IDBKeyRange): IDBRequest<any>;
16
16
  getAll(query?: IDBValidKey | IDBKeyRange | null | undefined, count?: number | undefined): IDBRequest<any[]>;
17
17
  getAll(query: SearchParameterType, count?: number | undefined): Promise<IDBRequest<any[]>>;
18
+ getAllItems(query?: IDBValidKey | IDBKeyRange | null | undefined, count?: number | undefined): IDBRequest<any[]>;
19
+ getAllItems(query: SearchParameterType, count?: number | undefined): Promise<IDBRequest<any[]>>;
18
20
  getAllKeys(query?: IDBValidKey | IDBKeyRange | null | undefined, count?: number | undefined): IDBRequest<IDBValidKey[]>;
19
21
  getKey(query: IDBValidKey | IDBKeyRange): IDBRequest<IDBValidKey | undefined>;
20
22
  index(name: string): IDBIndex;
@@ -22,4 +24,6 @@ export declare class SyncMapItem extends ServiceObjectStore {
22
24
  openKeyCursor(query?: IDBValidKey | IDBKeyRange | null | undefined, direction?: IDBCursorDirection | undefined): IDBRequest<IDBCursor | null>;
23
25
  put(value: any, key?: IDBValidKey | undefined): IDBRequest<IDBValidKey>;
24
26
  put(value: Object, key: IDBValidKey): Promise<IDBRequest<IDBValidKey>>;
27
+ putItem(value: any, key?: IDBValidKey | undefined, ifMatchValue?: string | undefined): IDBRequest<IDBValidKey>;
28
+ putItem(value: Object, key: IDBValidKey, ifMatchValue?: string | undefined): Promise<IDBRequest<IDBValidKey>>;
25
29
  }
@@ -115,6 +115,74 @@ class SyncMapItem extends ServiceObjectStore_1.ServiceObjectStore {
115
115
  };
116
116
  });
117
117
  }
118
+ getAllItems(query, count) {
119
+ return SyncMapItemsTransaction_1.SyncMapItemTransaction.syncMapInstance.syncMapItems.list().then((mapItems) => {
120
+ let items = mapItems.map((item) => (Object.assign(Object.assign({}, item.data), { revision: item.revision })));
121
+ let totalPages = 0;
122
+ if (query && typeof query === 'object' && "sortOptions" in query) {
123
+ let sortBy;
124
+ let direction;
125
+ if (typeof query.sortOptions === "string") {
126
+ query.sortOptions = JSON.parse(query.sortOptions);
127
+ }
128
+ if (Array.isArray(query.sortOptions)) {
129
+ query.sortOptions.forEach(item => {
130
+ if (Object.keys(item)[0] && item[Object.keys(item)[0]]) {
131
+ sortBy = Object.keys(item)[0];
132
+ direction = item[Object.keys(item)[0]].toUpperCase() === 'ASC' ? true : false;
133
+ }
134
+ items = (0, sort_1.sortData)(items, sortBy, direction);
135
+ });
136
+ }
137
+ else if (query.sortOptions) {
138
+ let sortOptions;
139
+ sortOptions = query.sortOptions;
140
+ Object.keys(query.sortOptions).forEach(item => {
141
+ if (sortOptions[item]) {
142
+ sortBy = item;
143
+ direction = sortOptions[item].toUpperCase() === 'ASC' ? true : false;
144
+ }
145
+ items = (0, sort_1.sortData)(items, sortBy, direction);
146
+ });
147
+ }
148
+ }
149
+ let filterOptions = null;
150
+ if (query && typeof query === 'object' && "allowedFields" in query) {
151
+ filterOptions = Filter_1.Filter.generateFilterOptions(items, query.allowedFields);
152
+ }
153
+ if (query && typeof query === 'object' && ("timezone" in query || "dateFormat" in query || "timeFormat" in query)) {
154
+ let timezone = "timezone" in query ? query.timezone : "";
155
+ let dateFormat = "dateFormat" in query ? query.dateFormat : "";
156
+ let timeFormat = "timeFormat" in query ? query.timeFormat : "";
157
+ items = (0, dateFormat_1.dateFormatData)(items, dateFormat, timeFormat, timezone);
158
+ }
159
+ if (query && typeof query === "object" && "filters" in query && "category" in query) {
160
+ let filters = query.filters;
161
+ let category = typeof query.category === "string" ? query.category : "";
162
+ items = (0, newFilter_1.filterData)(items, filters, category);
163
+ }
164
+ if (query && typeof query === 'object' && "searchOptions" in query && query.searchOptions) {
165
+ let searchOptions = typeof query === 'object' && "searchOptions" in query ? query.searchOptions : "";
166
+ items = (0, search_1.searchData)(items, searchOptions);
167
+ }
168
+ // if (query && typeof query === 'object' && "filters" in query && query.filters) {
169
+ // let filters: any = typeof query === 'object' && "filters" in query ? query.filters : "";
170
+ // // console.log("filtered data:::", typeof JSON.parse(filters));
171
+ // items = filterData(items, filters)
172
+ // }
173
+ if (query && typeof query === 'object' && "itemsPerPage" in query) {
174
+ let itemsPerPage = typeof query === 'object' && "itemsPerPage" in query ? query.itemsPerPage : 5;
175
+ let pageNo = typeof query === 'object' && "pageNo" in query ? query.pageNo : 1;
176
+ totalPages = (items.length !== 0) && ((itemsPerPage < items.length) || (itemsPerPage > items.length)) ? Math.ceil(items.length / itemsPerPage) : 1;
177
+ items = (0, pagination_1.paginateData)(items, itemsPerPage, pageNo);
178
+ }
179
+ return {
180
+ totalPages,
181
+ items,
182
+ filterOptions
183
+ };
184
+ });
185
+ }
118
186
  getAllKeys(query, count) {
119
187
  throw new Error("Method not implemented.");
120
188
  }
@@ -135,5 +203,10 @@ class SyncMapItem extends ServiceObjectStore_1.ServiceObjectStore {
135
203
  return mapItem.key;
136
204
  });
137
205
  }
206
+ putItem(value, key, ifMatchValue) {
207
+ return SyncMapItemsTransaction_1.SyncMapItemTransaction.syncMapInstance.syncMapItems(key).update(ifMatchValue ? { data: value, ifMatch: ifMatchValue } : { data: value }).then((mapItem) => {
208
+ return mapItem.key;
209
+ });
210
+ }
138
211
  }
139
212
  exports.SyncMapItem = SyncMapItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hgs-twilio-class-lib",
3
- "version": "1.1.86",
3
+ "version": "1.1.87",
4
4
  "description": "Flex 2.0 backend to connect with any database ",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./types/index.d.ts",