ravcredit-lib 0.0.11 → 0.0.12
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/fesm2022/ravcredit-lib.mjs +1997 -0
- package/fesm2022/ravcredit-lib.mjs.map +1 -0
- package/index.d.ts +1647 -0
- package/package.json +25 -13
- package/ng-package.json +0 -7
- package/src/lib/ravcredit-lib.component.spec.ts +0 -23
- package/src/lib/ravcredit-lib.component.ts +0 -16
- package/src/lib/ravcredit-lib.service.spec.ts +0 -16
- package/src/lib/ravcredit-lib.service.ts +0 -9
- package/src/lib/v1/const/constants.ts +0 -35
- package/src/lib/v1/dto/AddressDto.ts +0 -27
- package/src/lib/v1/dto/BusinessDeadlineDto.ts +0 -9
- package/src/lib/v1/dto/ConektaDto.ts +0 -386
- package/src/lib/v1/dto/ContractDto.ts +0 -46
- package/src/lib/v1/dto/CustomerDto.ts +0 -47
- package/src/lib/v1/dto/DeviceDto.ts +0 -13
- package/src/lib/v1/dto/DynamiCoreDto.ts +0 -1017
- package/src/lib/v1/dto/FinancialDto.ts +0 -156
- package/src/lib/v1/dto/PassportDto.ts +0 -143
- package/src/lib/v1/dto/PayLinkResDto.ts +0 -144
- package/src/lib/v1/dto/PayOrderResAlternaDto.ts +0 -348
- package/src/lib/v1/dto/PayOrderResOxxoDto.ts +0 -254
- package/src/lib/v1/dto/PaymentLinkDto.ts +0 -161
- package/src/lib/v1/dto/ScheduleDto.ts +0 -17
- package/src/lib/v1/dto/UserDto.ts +0 -27
- package/src/lib/v1/dto/WeekScheduleDTO.ts +0 -46
- package/src/lib/v1/idb/idb.service.spec.ts +0 -16
- package/src/lib/v1/idb/indexed-db.service.ts +0 -396
- package/src/lib/v1/objects/oAddress.ts +0 -19
- package/src/lib/v1/objects/oBusiness.ts +0 -112
- package/src/lib/v1/objects/oClient.ts +0 -46
- package/src/lib/v1/objects/oConekta.ts +0 -408
- package/src/lib/v1/objects/oContract.ts +0 -30
- package/src/lib/v1/objects/oContractAll.ts +0 -38
- package/src/lib/v1/objects/oCustomer.ts +0 -36
- package/src/lib/v1/objects/oDevice.ts +0 -5
- package/src/lib/v1/objects/oFinancial.ts +0 -32
- package/src/lib/v1/objects/oGlobal.ts +0 -186
- package/src/lib/v1/objects/oLogIn.ts +0 -43
- package/src/lib/v1/objects/oNewPayment.ts +0 -18
- package/src/lib/v1/objects/oNotification.ts +0 -34
- package/src/lib/v1/objects/oPassport.ts +0 -65
- package/src/lib/v1/objects/oUser.ts +0 -35
- package/src/lib/v1/objects/oVerification.ts +0 -48
- package/src/lib/v1/util/UtilBusiness.ts +0 -186
- package/src/lib/v1/util/UtilClient.ts +0 -285
- package/src/lib/v1/util/UtilConekta.ts +0 -97
- package/src/lib/v1/util/UtilContract.ts +0 -386
- package/src/lib/v1/util/UtilDashboard.ts +0 -19
- package/src/lib/v1/util/UtilDynamiCore.ts +0 -752
- package/src/lib/v1/util/UtilNotification.ts +0 -46
- package/src/lib/v1/util/UtilPassport.ts +0 -32
- package/src/lib/v1/util/UtilPayment.ts +0 -22
- package/src/lib/v1/util/UtilTime.ts +0 -181
- package/src/lib/v1/util/UtilsHttp.ts +0 -11
- package/src/lib/v2/const/constants.ts +0 -38
- package/src/lib/v2/messaging/messaging.ts +0 -10
- package/src/public-api.ts +0 -37
- package/tsconfig.lib.json +0 -15
- package/tsconfig.lib.prod.json +0 -11
- package/tsconfig.spec.json +0 -15
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { IsArray, IsBoolean, IsNumber, IsString, ValidateNested } from 'class-validator';
|
|
2
|
-
import { Type } from 'class-transformer';
|
|
3
|
-
import { CustomerInfoDto } from './CustomerDto';
|
|
4
|
-
|
|
5
|
-
export enum eCurrencies { MXN = 'MXN' }
|
|
6
|
-
|
|
7
|
-
export enum ePaymentMethods {
|
|
8
|
-
cash = 'cash',
|
|
9
|
-
card = 'card',
|
|
10
|
-
bank_transfer = 'bank_transfer',
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const PaymentOptions = [
|
|
14
|
-
ePaymentMethods.cash,
|
|
15
|
-
ePaymentMethods.card,
|
|
16
|
-
ePaymentMethods.bank_transfer,
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
export const cPaymentLink = 'PaymentLink';
|
|
20
|
-
|
|
21
|
-
export class LineItemsDto {
|
|
22
|
-
@IsString()
|
|
23
|
-
name: string;
|
|
24
|
-
|
|
25
|
-
@IsNumber()
|
|
26
|
-
unit_price: number;
|
|
27
|
-
|
|
28
|
-
@IsNumber()
|
|
29
|
-
quantity: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export class OrderTemplateDto {
|
|
33
|
-
@IsArray()
|
|
34
|
-
@ValidateNested({ each: true })
|
|
35
|
-
@Type(() => LineItemsDto)
|
|
36
|
-
line_items: LineItemsDto[];
|
|
37
|
-
|
|
38
|
-
@IsString() // Assuming eCurrencies is a string
|
|
39
|
-
currency: string;
|
|
40
|
-
|
|
41
|
-
@ValidateNested()
|
|
42
|
-
@Type(() => CustomerInfoDto)
|
|
43
|
-
customer_info: CustomerInfoDto;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export class MetadataDto {
|
|
47
|
-
@IsString()
|
|
48
|
-
datos_extra: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export class PaymentMethodsDto {
|
|
52
|
-
@IsString()
|
|
53
|
-
type: string;
|
|
54
|
-
|
|
55
|
-
@IsNumber()
|
|
56
|
-
expires_at: number;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export class ChargesDto {
|
|
60
|
-
@ValidateNested()
|
|
61
|
-
@Type(() => PaymentMethodsDto)
|
|
62
|
-
payment_method: PaymentMethodsDto;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export class PaymentOrderObjectDto {
|
|
66
|
-
@IsString() // Assuming eCurrencies is a string
|
|
67
|
-
currency: string;
|
|
68
|
-
|
|
69
|
-
@ValidateNested()
|
|
70
|
-
@Type(() => CustomerInfoDto)
|
|
71
|
-
customer_info: CustomerInfoDto;
|
|
72
|
-
|
|
73
|
-
@IsArray()
|
|
74
|
-
@ValidateNested({ each: true })
|
|
75
|
-
@Type(() => LineItemsDto)
|
|
76
|
-
line_items: LineItemsDto[];
|
|
77
|
-
|
|
78
|
-
@ValidateNested()
|
|
79
|
-
@Type(() => MetadataDto)
|
|
80
|
-
metadata: MetadataDto;
|
|
81
|
-
|
|
82
|
-
@IsArray()
|
|
83
|
-
@ValidateNested({ each: true })
|
|
84
|
-
@Type(() => ChargesDto)
|
|
85
|
-
charges: ChargesDto[];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export class PaymentLinkObjectDto {
|
|
89
|
-
@IsString()
|
|
90
|
-
name: string;
|
|
91
|
-
|
|
92
|
-
@IsString()
|
|
93
|
-
type: string;
|
|
94
|
-
|
|
95
|
-
@IsBoolean()
|
|
96
|
-
recurrent: boolean;
|
|
97
|
-
|
|
98
|
-
@IsNumber()
|
|
99
|
-
expired_at: number;
|
|
100
|
-
|
|
101
|
-
@IsArray()
|
|
102
|
-
@IsString({ each: true })
|
|
103
|
-
allowed_payment_methods: string[];
|
|
104
|
-
|
|
105
|
-
@IsBoolean()
|
|
106
|
-
needs_shipping_contact: boolean;
|
|
107
|
-
|
|
108
|
-
@ValidateNested()
|
|
109
|
-
@Type(() => OrderTemplateDto)
|
|
110
|
-
order_template: OrderTemplateDto;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
// export interface iLineItems {
|
|
115
|
-
// name: string; // "Red Wine",
|
|
116
|
-
// unit_price: number; // 1000,
|
|
117
|
-
// quantity: number; // 10
|
|
118
|
-
// }
|
|
119
|
-
//
|
|
120
|
-
// export interface iOrderTemplate {
|
|
121
|
-
// line_items: iLineItems[],
|
|
122
|
-
// currency: eCurrencies// "MXN",
|
|
123
|
-
// customer_info: CustomerInfoDto
|
|
124
|
-
// }
|
|
125
|
-
|
|
126
|
-
//
|
|
127
|
-
// export interface iMetadata {
|
|
128
|
-
// datos_extra: string;
|
|
129
|
-
// }
|
|
130
|
-
//
|
|
131
|
-
// export interface iPaymentMethods {
|
|
132
|
-
// type: string;
|
|
133
|
-
// expires_at: number;
|
|
134
|
-
// }
|
|
135
|
-
//
|
|
136
|
-
// export interface iCharges {
|
|
137
|
-
// payment_method: iPaymentMethods;
|
|
138
|
-
// }
|
|
139
|
-
//
|
|
140
|
-
// export interface iPaymentOrderObject {
|
|
141
|
-
// currency: eCurrencies;// "MXN",
|
|
142
|
-
// customer_info: CustomerInfoDto;
|
|
143
|
-
// line_items: iLineItems[];
|
|
144
|
-
// metadata: iMetadata;
|
|
145
|
-
// charges: iCharges[];
|
|
146
|
-
// }
|
|
147
|
-
//
|
|
148
|
-
// export interface iPaymentLinkObject {
|
|
149
|
-
// name: string; // "Payment Link Name",
|
|
150
|
-
// type: string; // "PaymentLink",
|
|
151
|
-
// recurrent: boolean; // false,
|
|
152
|
-
// expired_at: number; // 1597635007,
|
|
153
|
-
// allowed_payment_methods: string[];// ["cash", "card", "bank_transfer"],
|
|
154
|
-
// needs_shipping_contact: boolean;// false,
|
|
155
|
-
// order_template: iOrderTemplate;
|
|
156
|
-
// }
|
|
157
|
-
|
|
158
|
-
// Example CustomerInfo
|
|
159
|
-
// {
|
|
160
|
-
// "customer_id": "cus_2nYSnP4EDiREgGte9"
|
|
161
|
-
// }
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { IsEnum, IsNumber, IsOptional, IsString } from 'class-validator';
|
|
2
|
-
import { eRoles } from '../interfaces/iGlobal';
|
|
3
|
-
|
|
4
|
-
export class UserDto {
|
|
5
|
-
@IsString()
|
|
6
|
-
id: string;
|
|
7
|
-
|
|
8
|
-
@IsString()
|
|
9
|
-
username: string;
|
|
10
|
-
|
|
11
|
-
@IsString()
|
|
12
|
-
name: string;
|
|
13
|
-
|
|
14
|
-
@IsString()
|
|
15
|
-
password: string;
|
|
16
|
-
|
|
17
|
-
@IsEnum(eRoles)
|
|
18
|
-
role: eRoles;
|
|
19
|
-
|
|
20
|
-
@IsOptional()
|
|
21
|
-
@IsNumber()
|
|
22
|
-
lastLogin?: number;
|
|
23
|
-
|
|
24
|
-
@IsOptional()
|
|
25
|
-
@IsNumber()
|
|
26
|
-
createdAt?: number;
|
|
27
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { IsOptional } from "class-validator";
|
|
2
|
-
|
|
3
|
-
export class WeekScheduleDTO {
|
|
4
|
-
|
|
5
|
-
@IsOptional()
|
|
6
|
-
monday: {
|
|
7
|
-
open: string,
|
|
8
|
-
close: string
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
@IsOptional()
|
|
12
|
-
tuesday: {
|
|
13
|
-
open: string,
|
|
14
|
-
close: string
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
@IsOptional()
|
|
18
|
-
wednesday: {
|
|
19
|
-
open: string,
|
|
20
|
-
close: string
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
@IsOptional()
|
|
24
|
-
thursday: {
|
|
25
|
-
open: string,
|
|
26
|
-
close: string
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
@IsOptional()
|
|
30
|
-
friday: {
|
|
31
|
-
open: string,
|
|
32
|
-
close: string
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
@IsOptional()
|
|
36
|
-
saturday: {
|
|
37
|
-
open: string,
|
|
38
|
-
close: string
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
@IsOptional()
|
|
42
|
-
sunday: {
|
|
43
|
-
open: string,
|
|
44
|
-
close: string
|
|
45
|
-
};
|
|
46
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { TestBed } from '@angular/core/testing';
|
|
2
|
-
|
|
3
|
-
import { IndexedDbService } from './indexed-db.service';
|
|
4
|
-
|
|
5
|
-
describe('IdbService', () => {
|
|
6
|
-
let service: IndexedDbService;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
TestBed.configureTestingModule({});
|
|
10
|
-
service = TestBed.inject(IndexedDbService);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should be created', () => {
|
|
14
|
-
expect(service).toBeTruthy();
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,396 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import { oUser } from '../objects/oUser';
|
|
3
|
-
import {IDBPDatabase, openDB} from 'idb';
|
|
4
|
-
import {
|
|
5
|
-
dbAuthStore, dbBusinessConfig, dbBusinessInfo,
|
|
6
|
-
dbClientsStore,
|
|
7
|
-
dbConektaClientsStore, dbConektaReferencesStore,
|
|
8
|
-
dbContractsStore, dbDynamicReferencesStore,
|
|
9
|
-
dbName, dbNotificationsStore, dbPassportReferencesStore,
|
|
10
|
-
dbVersion,
|
|
11
|
-
keyPathId,
|
|
12
|
-
keyUserID
|
|
13
|
-
} from '../const/constants';
|
|
14
|
-
import {oClient} from '../objects/oClient';
|
|
15
|
-
import {tyClientContract} from '../objects/oGlobal';
|
|
16
|
-
import {oContract} from '../objects/oContract';
|
|
17
|
-
import {eProvider} from '../util/UtilContract';
|
|
18
|
-
import {oBusinessConfig, oBusinessInfo} from '../objects/oBusiness';
|
|
19
|
-
import {oNotification} from '../objects/oNotification';
|
|
20
|
-
|
|
21
|
-
@Injectable({
|
|
22
|
-
providedIn: 'root'
|
|
23
|
-
})
|
|
24
|
-
export class IndexedDbService {
|
|
25
|
-
|
|
26
|
-
indexDbStatus = false
|
|
27
|
-
iDb!: IDBPDatabase<unknown>
|
|
28
|
-
|
|
29
|
-
constructor() {
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// async dbAuthorization() {
|
|
33
|
-
// // const k = this.getLocalUser()
|
|
34
|
-
// // if (k == null) return false
|
|
35
|
-
// //
|
|
36
|
-
// // const db = await openDB(dbName, dbVersion)
|
|
37
|
-
// // // utils store = db.transaction(dbUsersStore).objectStore(dbUsersStore)
|
|
38
|
-
// // const auth = await db.get(dbAuthStore, k)
|
|
39
|
-
// // // utils auth = await store.get(k)
|
|
40
|
-
// // db.close()
|
|
41
|
-
//
|
|
42
|
-
// let auth: any = null
|
|
43
|
-
// return auth;
|
|
44
|
-
//
|
|
45
|
-
// }
|
|
46
|
-
|
|
47
|
-
/****************** SIMPLE Transactional - CRUD *************************************/
|
|
48
|
-
|
|
49
|
-
async dbGetObject<T>(store: string, data: any): Promise<T> {
|
|
50
|
-
if (!data) return data
|
|
51
|
-
const db = await openDB(dbName, dbVersion)
|
|
52
|
-
return await db.get(store, data) as T
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async dbGetAllByStore<T>(store: string, index?: string) {
|
|
56
|
-
const db = await openDB(dbName, dbVersion)
|
|
57
|
-
return await db.getAll(store) as T
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async dbAddObject<T>(store: string, data: any): Promise<boolean> {
|
|
61
|
-
try {
|
|
62
|
-
const db = await openDB(dbName, dbVersion)
|
|
63
|
-
await db.put(store, data)
|
|
64
|
-
return true
|
|
65
|
-
} catch (e) {
|
|
66
|
-
return false
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async dbRemoveObject<T>(store: string, data: any): Promise<T> {
|
|
71
|
-
const db = await openDB(dbName, dbVersion)
|
|
72
|
-
return await db.delete(store, data) as T
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/************************************* AUTH **************************************/
|
|
76
|
-
|
|
77
|
-
async dbSignIn(store: string, data: any) {
|
|
78
|
-
await this.iDb.put(store, data)
|
|
79
|
-
const _data = data as oUser
|
|
80
|
-
this.setLocalStorage(keyUserID, _data.id)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async dbSignOut() {
|
|
84
|
-
|
|
85
|
-
const k = this.getLocalUser()
|
|
86
|
-
if (!k) return
|
|
87
|
-
|
|
88
|
-
await this.iDb.delete(dbAuthStore, k)
|
|
89
|
-
this.removeLocalStorage(keyUserID)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async dbAuthorization() {
|
|
93
|
-
const k = this.getLocalUser()
|
|
94
|
-
if (k == null) return false
|
|
95
|
-
|
|
96
|
-
const db = await openDB(dbName, dbVersion)
|
|
97
|
-
// utils store = db.transaction(dbUsersStore).objectStore(dbUsersStore)
|
|
98
|
-
const auth = await db.get(dbAuthStore, k)
|
|
99
|
-
// utils auth = await store.get(k)
|
|
100
|
-
db.close()
|
|
101
|
-
|
|
102
|
-
if (!auth) return false
|
|
103
|
-
else return true
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async dbGetToken() {
|
|
107
|
-
const k = this.getLocalUser()
|
|
108
|
-
if (k == null) return ""
|
|
109
|
-
|
|
110
|
-
const db = await openDB(dbName, dbVersion)
|
|
111
|
-
// utils store = db.transaction(dbUsersStore).objectStore(dbUsersStore)
|
|
112
|
-
const auth = await db.get(dbAuthStore, k) as oUser
|
|
113
|
-
// utils auth = await store.get(k)
|
|
114
|
-
|
|
115
|
-
db.close()
|
|
116
|
-
return auth.access_token != "" ? auth.access_token : ""
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/******************************** Local Storage *************************************/
|
|
120
|
-
|
|
121
|
-
setLocalStorage(k: string, v: string) {
|
|
122
|
-
localStorage.setItem(k, v)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
getLocalStorage<T>(k: string) {
|
|
126
|
-
return localStorage.getItem(k) as T
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
removeLocalStorage(k: string) {
|
|
130
|
-
return localStorage.removeItem(k)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
getLocalUser(): string | null {
|
|
134
|
-
const k = localStorage.getItem(keyUserID)
|
|
135
|
-
return (k)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/********************************************************************************* **/
|
|
139
|
-
|
|
140
|
-
async getPlatformUser() {
|
|
141
|
-
const k = this.getLocalStorage<string>(keyUserID) as string
|
|
142
|
-
if (k == null) return ""
|
|
143
|
-
|
|
144
|
-
const db = await openDB(dbName, dbVersion)
|
|
145
|
-
// utils store = db.transaction(dbUsersStore).objectStore(dbUsersStore)
|
|
146
|
-
const auth = await db.get(dbAuthStore, k) as oUser
|
|
147
|
-
// utils auth = await store.get(k)
|
|
148
|
-
|
|
149
|
-
db.close()
|
|
150
|
-
return auth.name != "" ? auth.name : ""
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async getToken() {
|
|
154
|
-
const k = this.getLocalUser()
|
|
155
|
-
if (k == null) return ""
|
|
156
|
-
|
|
157
|
-
const db = await openDB(dbName, dbVersion)
|
|
158
|
-
// utils store = db.transaction(dbUsersStore).objectStore(dbUsersStore)
|
|
159
|
-
const auth = await db.get(dbAuthStore, k) as oUser
|
|
160
|
-
// utils auth = await store.get(k)
|
|
161
|
-
|
|
162
|
-
db.close()
|
|
163
|
-
return auth.access_token != "" ? auth.access_token : ""
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async addObject<T>(store: string, data: any): Promise<boolean> {
|
|
167
|
-
try {
|
|
168
|
-
const db = await openDB(dbName, dbVersion)
|
|
169
|
-
await db.put(store, data)
|
|
170
|
-
return true
|
|
171
|
-
} catch (e) {
|
|
172
|
-
return false
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async patchObject<T>(store: string, data: any): Promise<T> {
|
|
177
|
-
try {
|
|
178
|
-
const db = await openDB(dbName, dbVersion)
|
|
179
|
-
const txn = db.transaction(store, "readwrite")
|
|
180
|
-
const obj = txn.objectStore(store)
|
|
181
|
-
// const index = obj.index(keyPathCurp)
|
|
182
|
-
await obj.put(data)
|
|
183
|
-
return data as T
|
|
184
|
-
} catch (e) {
|
|
185
|
-
console.error(e)
|
|
186
|
-
return {} as T
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
async updateObjectByID<T>(store: string, id: string, data: T): Promise<boolean> {
|
|
191
|
-
try {
|
|
192
|
-
|
|
193
|
-
const db = await openDB(dbName, dbVersion)
|
|
194
|
-
const res = await db.get(store, id) as oClient
|
|
195
|
-
|
|
196
|
-
if (res != undefined) await this.removeObject(dbClientsStore, id)
|
|
197
|
-
|
|
198
|
-
return await this.addObject(store, data)
|
|
199
|
-
|
|
200
|
-
} catch (e) {
|
|
201
|
-
console.error("updateObjectByID Catch Error:", e)
|
|
202
|
-
return false
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
async upsertObjectById<T>(store: string, id: string, data: T) {
|
|
207
|
-
|
|
208
|
-
const db = await openDB(dbName, dbVersion)
|
|
209
|
-
const res = await db.get(store, id)
|
|
210
|
-
|
|
211
|
-
if (res) await this.removeObject<T>(store, id)
|
|
212
|
-
|
|
213
|
-
return await db.add(store, data)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
async removeObject<T>(store: string, data: any): Promise<T> {
|
|
217
|
-
const db = await openDB(dbName, dbVersion)
|
|
218
|
-
return await db.delete(store, data) as T
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
async deleteObjectByID<T>(store: string, id: string) {
|
|
222
|
-
try {
|
|
223
|
-
const db = await openDB(dbName, dbVersion)
|
|
224
|
-
const txn = db.transaction(store, "readwrite")
|
|
225
|
-
const obj = txn.objectStore(store)
|
|
226
|
-
const index = obj.index(keyPathId)
|
|
227
|
-
const va2 = index.openCursor(id)
|
|
228
|
-
va2.then(async cursor => {
|
|
229
|
-
while (cursor) {
|
|
230
|
-
cursor.delete();
|
|
231
|
-
cursor = await cursor.continue();
|
|
232
|
-
}
|
|
233
|
-
})
|
|
234
|
-
return va2
|
|
235
|
-
} catch (e) {
|
|
236
|
-
console.error(e)
|
|
237
|
-
return {} as T
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
async cleanAll<T>(store: string) {
|
|
242
|
-
const db = await openDB(dbName, dbVersion)
|
|
243
|
-
return await db.clear(store)
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
async getObject<T>(store: string, data: any): Promise<T> {
|
|
247
|
-
if (!data) return data
|
|
248
|
-
const db = await openDB(dbName, dbVersion)
|
|
249
|
-
return await db.get(store, data) as T
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
async addBuildByStore(store: string, data: any[]) {
|
|
253
|
-
for (const o of data) {
|
|
254
|
-
const exists = await this.getObject(store, o["id"])
|
|
255
|
-
if (!exists) await this.addObject(store, o)
|
|
256
|
-
else await this.updateObject(store, o)
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
async updateObject<T>(store: string, data: any) {
|
|
261
|
-
const db = await openDB(dbName, dbVersion)
|
|
262
|
-
await db.put(store, data)
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
async getAllByStore<T>(store: string, index?: string) {
|
|
266
|
-
const db = await openDB(dbName, dbVersion)
|
|
267
|
-
return await db.getAll(store) as T
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
async getAuthUser() {
|
|
271
|
-
const data = await this.getAllByStore<oUser[]>(dbAuthStore)
|
|
272
|
-
return data[0]
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
async getAuthName() {
|
|
276
|
-
const data = await this.getAuthUser()
|
|
277
|
-
return data.name
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
async getAuthUsername() {
|
|
281
|
-
const data = await this.getAuthUser()
|
|
282
|
-
return data.username
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
async saveDataLocally<T>(
|
|
286
|
-
contract: oContract,
|
|
287
|
-
client: oClient,
|
|
288
|
-
providerData: T,
|
|
289
|
-
): Promise<boolean> {
|
|
290
|
-
try {
|
|
291
|
-
await this.addObject(dbClientsStore, client)
|
|
292
|
-
await this.addObject(dbContractsStore, contract)
|
|
293
|
-
|
|
294
|
-
if (!providerData) return false
|
|
295
|
-
|
|
296
|
-
if (contract.financial.provider === eProvider.Conekta) {
|
|
297
|
-
await this.addObject(dbConektaClientsStore, providerData)
|
|
298
|
-
await this.addObject(dbConektaReferencesStore, providerData)
|
|
299
|
-
} else if (contract.financial.provider === eProvider.Passport) {
|
|
300
|
-
await this.addObject(dbPassportReferencesStore, providerData)
|
|
301
|
-
} else if (contract.financial.provider === eProvider.DynamiCore) {
|
|
302
|
-
await this.addObject(dbDynamicReferencesStore, providerData)
|
|
303
|
-
}
|
|
304
|
-
return true
|
|
305
|
-
} catch (e) {
|
|
306
|
-
console.error(e)
|
|
307
|
-
return false
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/******************** MERGE **************************************/
|
|
312
|
-
async getAllClientContracts(): Promise<tyClientContract[]> {
|
|
313
|
-
const clientContract: tyClientContract[] = []
|
|
314
|
-
const clients = await this.getAllByStore<oClient[]>(dbClientsStore)
|
|
315
|
-
if (clients.length == 0) return []
|
|
316
|
-
|
|
317
|
-
for (let client of clients) {
|
|
318
|
-
const contract = await this.getObject<oContract>(dbContractsStore, client.contract)
|
|
319
|
-
const e = {...client, ...contract}
|
|
320
|
-
// preserve the id value over concat models
|
|
321
|
-
e.id = client.id
|
|
322
|
-
e.status = client.status
|
|
323
|
-
clientContract.push(e)
|
|
324
|
-
}
|
|
325
|
-
return clientContract
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/******************** MERGE **************************************/
|
|
329
|
-
|
|
330
|
-
async dbGetAllClientContracts(): Promise<tyClientContract[]> {
|
|
331
|
-
const clientContract: tyClientContract[] = []
|
|
332
|
-
const clients = await this.dbGetAllByStore<oClient[]>(dbClientsStore)
|
|
333
|
-
if (clients.length == 0) return []
|
|
334
|
-
|
|
335
|
-
for (let client of clients) {
|
|
336
|
-
const contract = await this.dbGetObject<oContract>(dbContractsStore, client.contract)
|
|
337
|
-
const e = {...client, ...contract}
|
|
338
|
-
// preserve the id value over concat models
|
|
339
|
-
e.id = client.id
|
|
340
|
-
e.status = client.status
|
|
341
|
-
clientContract.push(e)
|
|
342
|
-
}
|
|
343
|
-
return clientContract
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/****************** BUSINESS INFO *************************************/
|
|
347
|
-
|
|
348
|
-
async getBusinessInfo(): Promise<oBusinessInfo | null> {
|
|
349
|
-
const config: oBusinessInfo[] = await this.dbGetAllByStore<oBusinessInfo[]>(dbBusinessInfo)
|
|
350
|
-
|
|
351
|
-
if (!config) return null
|
|
352
|
-
|
|
353
|
-
return config[0]
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/****************** BUSINESS CONFIG ************************************/
|
|
357
|
-
|
|
358
|
-
async getBusinessConfig(): Promise<oBusinessConfig | null> {
|
|
359
|
-
const config: oBusinessConfig[] = await this.dbGetAllByStore<oBusinessConfig[]>(dbBusinessConfig)
|
|
360
|
-
|
|
361
|
-
if (!config) return null
|
|
362
|
-
|
|
363
|
-
return config[0]
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
async updateBusinessConfig(config: oBusinessConfig) {
|
|
367
|
-
|
|
368
|
-
// config.version = "1.0"
|
|
369
|
-
await this.dbRemoveObject(dbBusinessConfig, "1.0")
|
|
370
|
-
await this.dbAddObject(dbBusinessConfig, config)
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
async updateBusinessInfo(config: oBusinessInfo) {
|
|
374
|
-
|
|
375
|
-
config.version = "v2024"
|
|
376
|
-
await this.dbRemoveObject(dbBusinessInfo, "v2024")
|
|
377
|
-
await this.dbAddObject(dbBusinessInfo, config)
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**************** NOTIFICATIONS *********************************/
|
|
381
|
-
|
|
382
|
-
async getLocalNotifications(): Promise<oNotification[] | null> {
|
|
383
|
-
const notifications: oNotification[] = await this.dbGetAllByStore<oNotification[]>(dbNotificationsStore)
|
|
384
|
-
if (!notifications) return null
|
|
385
|
-
return notifications
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
async updateNotifications(notifications: oNotification[]) {
|
|
389
|
-
for (const o of notifications) {
|
|
390
|
-
const exists = await this.dbGetObject(dbNotificationsStore, o.notification_id)
|
|
391
|
-
if (!exists) {
|
|
392
|
-
await this.dbAddObject(dbNotificationsStore, o)
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export interface oAddress {
|
|
2
|
-
street: string,
|
|
3
|
-
city: string,
|
|
4
|
-
neighbor: string,
|
|
5
|
-
zip: string,
|
|
6
|
-
ext: string,
|
|
7
|
-
int: string,
|
|
8
|
-
state: string,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const cAddress: oAddress = {
|
|
12
|
-
street: "",
|
|
13
|
-
city: "",
|
|
14
|
-
neighbor: "",
|
|
15
|
-
zip: "",
|
|
16
|
-
ext: "",
|
|
17
|
-
int: "",
|
|
18
|
-
state: ""
|
|
19
|
-
}
|