addio-admin-sdk 1.7.134 → 1.7.135
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/.env +6 -5
- package/dist/lib/Queue/index.d.ts +40 -0
- package/dist/lib/Queue/index.js +255 -0
- package/dist/lib/Queue/index.js.map +1 -0
- package/dist/lib/Space/index.d.ts +1 -2
- package/dist/lib/Space/index.js +3 -4
- package/dist/lib/Space/index.js.map +1 -1
- package/package.json +1 -1
package/.env
CHANGED
|
@@ -2,13 +2,14 @@ NEXT_PUBLIC_FIREBASE_CONFIG_API_KEY_DEV='AIzaSyBNtwzdIe2__HJD23S87RIbWbIqKQVtFiw
|
|
|
2
2
|
NEXT_PUBLIC_FIREBASE_CONFIG_API_KEY_PROD='AIzaSyDK6WQZkCrsMGunAPHn9KkdCGPky4hTgL4'
|
|
3
3
|
NEXT_PUBLIC_MESSAGING_SENDER_ID_DEV='188490998694'
|
|
4
4
|
NEXT_PUBLIC_MESSAGING_SENDER_ID_PROD='725873016982'
|
|
5
|
-
NEXT_PUBLIC_FIREBASE_APP_ID_DEV='1:188490998694:web:eecd719e7b18f38d272567'
|
|
6
5
|
NEXT_PUBLIC_FIREBASE_APP_ID_PROD='1:725873016982:web:9b1f6d77819909e19102b7'
|
|
6
|
+
NEXT_PUBLIC_FIREBASE_APP_ID_DEV='1:188490998694:web:eecd719e7b18f38d272567'
|
|
7
7
|
NEXT_PUBLIC_MEASUREMENT_ID_DEV='G-4BB66ZRTWZ'
|
|
8
8
|
NEXT_PUBLIC_MEASUREMENT_ID_PROD='G-BB8HHZ466R'
|
|
9
|
+
|
|
9
10
|
NEXT_PUBLIC_SERVICE_DATABASE_READ_PROVIDER=nobase
|
|
10
|
-
NEXT_PUBLIC_SERVICE_DATABASE_WRITE_PROVIDER=nobase
|
|
11
|
+
NEXT_PUBLIC_SERVICE_DATABASE_WRITE_PROVIDER=nobase
|
|
11
12
|
NEXT_PUBLIC_SERVICE_DATABASE_URL=https://db-test.addiocommerce.com/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
NEXT_PUBLIC_API_URL=https://api-test.addiocommerce.com/v1
|
|
14
|
+
NEXT_PUBLIC_SERVICE_DATABASE_TOKEN='337043a374-6f0be-5eb26-05be550631'
|
|
15
|
+
LOCAL_FIRESTORE=false
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import Space from '../Space';
|
|
2
|
+
export default class Queue {
|
|
3
|
+
private _space;
|
|
4
|
+
constructor(space: Space);
|
|
5
|
+
last: () => Promise<QueueItem>;
|
|
6
|
+
first: () => Promise<QueueItem>;
|
|
7
|
+
lastX: (numberOfReturnedItems: number) => Promise<QueueItem[]>;
|
|
8
|
+
firstX: (numberOfReturnedItems: number) => Promise<QueueItem[]>;
|
|
9
|
+
}
|
|
10
|
+
export declare enum QueueItemTypeEnum {
|
|
11
|
+
PRODUCT_CREATE = 0,
|
|
12
|
+
PRODUCT_UPDATE = 1,
|
|
13
|
+
PRODUCT_DELETE = 2,
|
|
14
|
+
INVENTORY_UPDATE = 3,
|
|
15
|
+
CLIENT_CREATE = 4,
|
|
16
|
+
CLIENT_UPDATE = 5,
|
|
17
|
+
CLIENT_DELETE = 6
|
|
18
|
+
}
|
|
19
|
+
export declare enum QueueExternalService {
|
|
20
|
+
QUICKBOOKS = 0,
|
|
21
|
+
SAGE = 1,
|
|
22
|
+
ACOMBA = 2
|
|
23
|
+
}
|
|
24
|
+
export declare enum QueueDirection {
|
|
25
|
+
FROM_OUTTER = 0,
|
|
26
|
+
TO_OUTTER = 1
|
|
27
|
+
}
|
|
28
|
+
export declare class QueueItem {
|
|
29
|
+
private _space;
|
|
30
|
+
private _type;
|
|
31
|
+
private _added_at;
|
|
32
|
+
private _id;
|
|
33
|
+
private _service;
|
|
34
|
+
private _direction;
|
|
35
|
+
private _details?;
|
|
36
|
+
private _progress;
|
|
37
|
+
constructor(space: Space, type: QueueItemTypeEnum, added_at: Date, id: string, service: QueueExternalService, direction: QueueDirection, rest: any);
|
|
38
|
+
private _triggerExec;
|
|
39
|
+
private _getOperation;
|
|
40
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
39
|
+
var t = {};
|
|
40
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
41
|
+
t[p] = s[p];
|
|
42
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
43
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
44
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
45
|
+
t[p[i]] = s[p[i]];
|
|
46
|
+
}
|
|
47
|
+
return t;
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.QueueItem = exports.QueueDirection = exports.QueueExternalService = exports.QueueItemTypeEnum = void 0;
|
|
54
|
+
var DatabaseService_1 = __importDefault(require("../../services/database/DatabaseService"));
|
|
55
|
+
var console_1 = require("../../utils/console");
|
|
56
|
+
var Product_1 = __importDefault(require("../Product"));
|
|
57
|
+
var Queue = (function () {
|
|
58
|
+
function Queue(space) {
|
|
59
|
+
var _this = this;
|
|
60
|
+
this.last = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
61
|
+
var lastReq, _a, type, added_at, id, service, direction, rest;
|
|
62
|
+
return __generator(this, function (_b) {
|
|
63
|
+
switch (_b.label) {
|
|
64
|
+
case 0:
|
|
65
|
+
if (!!!this._space)
|
|
66
|
+
throw new Error("Space must be defined");
|
|
67
|
+
return [4, DatabaseService_1.default.getDocuments(this._space.documents.queue(), {
|
|
68
|
+
orderBy: 'added_at',
|
|
69
|
+
order: 'desc',
|
|
70
|
+
limit: 1
|
|
71
|
+
})];
|
|
72
|
+
case 1:
|
|
73
|
+
lastReq = _b.sent();
|
|
74
|
+
if (lastReq.length == 0)
|
|
75
|
+
throw new Error("Can't access last, may be empty");
|
|
76
|
+
if (lastReq[0].exists || !!!lastReq[0].data)
|
|
77
|
+
throw new Error("Can't access last, may be empty");
|
|
78
|
+
_a = lastReq[0].data, type = _a.type, added_at = _a.added_at, id = _a.id, service = _a.service, direction = _a.direction, rest = __rest(_a, ["type", "added_at", "id", "service", "direction"]);
|
|
79
|
+
return [2, new QueueItem(this._space, type, added_at, id, service, direction, rest)];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}); };
|
|
83
|
+
this.first = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
84
|
+
var firstReq, _a, type, added_at, id, service, direction, rest;
|
|
85
|
+
return __generator(this, function (_b) {
|
|
86
|
+
switch (_b.label) {
|
|
87
|
+
case 0:
|
|
88
|
+
if (!!!this._space)
|
|
89
|
+
throw new Error("Space must be defined");
|
|
90
|
+
return [4, DatabaseService_1.default.getDocuments(this._space.documents.queue(), {
|
|
91
|
+
orderBy: 'added_at',
|
|
92
|
+
order: 'asc',
|
|
93
|
+
limit: 1
|
|
94
|
+
})];
|
|
95
|
+
case 1:
|
|
96
|
+
firstReq = _b.sent();
|
|
97
|
+
if (firstReq.length == 0)
|
|
98
|
+
throw new Error("Can't access first, may be empty");
|
|
99
|
+
if (firstReq[0].exists || !!!firstReq[0].data)
|
|
100
|
+
throw new Error("Can't access last, may be empty");
|
|
101
|
+
_a = firstReq[0].data, type = _a.type, added_at = _a.added_at, id = _a.id, service = _a.service, direction = _a.direction, rest = __rest(_a, ["type", "added_at", "id", "service", "direction"]);
|
|
102
|
+
return [2, new QueueItem(this._space, type, added_at, id, service, direction, rest)];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}); };
|
|
106
|
+
this.lastX = function (numberOfReturnedItems) { return __awaiter(_this, void 0, void 0, function () {
|
|
107
|
+
var lastReq;
|
|
108
|
+
var _this = this;
|
|
109
|
+
return __generator(this, function (_a) {
|
|
110
|
+
switch (_a.label) {
|
|
111
|
+
case 0:
|
|
112
|
+
if (!!!this._space)
|
|
113
|
+
throw new Error("Space must be defined");
|
|
114
|
+
return [4, DatabaseService_1.default.getDocuments(this._space.documents.queue(), {
|
|
115
|
+
orderBy: 'added_at',
|
|
116
|
+
order: 'desc',
|
|
117
|
+
limit: numberOfReturnedItems
|
|
118
|
+
})];
|
|
119
|
+
case 1:
|
|
120
|
+
lastReq = _a.sent();
|
|
121
|
+
if (lastReq.length == 0)
|
|
122
|
+
throw new Error("Can't access last, may be empty");
|
|
123
|
+
if (lastReq[0].exists || !!!lastReq[0].data)
|
|
124
|
+
throw new Error("Can't access last, may be empty");
|
|
125
|
+
return [2, lastReq.map(function (d) {
|
|
126
|
+
var _a = d.data, type = _a.type, added_at = _a.added_at, id = _a.id, service = _a.service, direction = _a.direction, rest = __rest(_a, ["type", "added_at", "id", "service", "direction"]);
|
|
127
|
+
return new QueueItem(_this._space, type, added_at, id, service, direction, rest);
|
|
128
|
+
})];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}); };
|
|
132
|
+
this.firstX = function (numberOfReturnedItems) { return __awaiter(_this, void 0, void 0, function () {
|
|
133
|
+
var firstReq;
|
|
134
|
+
var _this = this;
|
|
135
|
+
return __generator(this, function (_a) {
|
|
136
|
+
switch (_a.label) {
|
|
137
|
+
case 0:
|
|
138
|
+
if (!!!this._space)
|
|
139
|
+
throw new Error("Space must be defined");
|
|
140
|
+
return [4, DatabaseService_1.default.getDocuments(this._space.documents.queue(), {
|
|
141
|
+
orderBy: 'added_at',
|
|
142
|
+
order: 'asc',
|
|
143
|
+
limit: numberOfReturnedItems
|
|
144
|
+
})];
|
|
145
|
+
case 1:
|
|
146
|
+
firstReq = _a.sent();
|
|
147
|
+
if (firstReq.length == 0)
|
|
148
|
+
throw new Error("Can't access first, may be empty");
|
|
149
|
+
if (firstReq[0].exists || !!!firstReq[0].data)
|
|
150
|
+
throw new Error("Can't access last, may be empty");
|
|
151
|
+
return [2, firstReq.map(function (d) {
|
|
152
|
+
var _a = d.data, type = _a.type, added_at = _a.added_at, id = _a.id, service = _a.service, direction = _a.direction, rest = __rest(_a, ["type", "added_at", "id", "service", "direction"]);
|
|
153
|
+
return new QueueItem(_this._space, type, added_at, id, service, direction, rest);
|
|
154
|
+
})];
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}); };
|
|
158
|
+
this._space = space;
|
|
159
|
+
}
|
|
160
|
+
return Queue;
|
|
161
|
+
}());
|
|
162
|
+
exports.default = Queue;
|
|
163
|
+
var QueueItemTypeEnum;
|
|
164
|
+
(function (QueueItemTypeEnum) {
|
|
165
|
+
QueueItemTypeEnum[QueueItemTypeEnum["PRODUCT_CREATE"] = 0] = "PRODUCT_CREATE";
|
|
166
|
+
QueueItemTypeEnum[QueueItemTypeEnum["PRODUCT_UPDATE"] = 1] = "PRODUCT_UPDATE";
|
|
167
|
+
QueueItemTypeEnum[QueueItemTypeEnum["PRODUCT_DELETE"] = 2] = "PRODUCT_DELETE";
|
|
168
|
+
QueueItemTypeEnum[QueueItemTypeEnum["INVENTORY_UPDATE"] = 3] = "INVENTORY_UPDATE";
|
|
169
|
+
QueueItemTypeEnum[QueueItemTypeEnum["CLIENT_CREATE"] = 4] = "CLIENT_CREATE";
|
|
170
|
+
QueueItemTypeEnum[QueueItemTypeEnum["CLIENT_UPDATE"] = 5] = "CLIENT_UPDATE";
|
|
171
|
+
QueueItemTypeEnum[QueueItemTypeEnum["CLIENT_DELETE"] = 6] = "CLIENT_DELETE";
|
|
172
|
+
})(QueueItemTypeEnum = exports.QueueItemTypeEnum || (exports.QueueItemTypeEnum = {}));
|
|
173
|
+
var QueueExternalService;
|
|
174
|
+
(function (QueueExternalService) {
|
|
175
|
+
QueueExternalService[QueueExternalService["QUICKBOOKS"] = 0] = "QUICKBOOKS";
|
|
176
|
+
QueueExternalService[QueueExternalService["SAGE"] = 1] = "SAGE";
|
|
177
|
+
QueueExternalService[QueueExternalService["ACOMBA"] = 2] = "ACOMBA";
|
|
178
|
+
})(QueueExternalService = exports.QueueExternalService || (exports.QueueExternalService = {}));
|
|
179
|
+
var QueueDirection;
|
|
180
|
+
(function (QueueDirection) {
|
|
181
|
+
QueueDirection[QueueDirection["FROM_OUTTER"] = 0] = "FROM_OUTTER";
|
|
182
|
+
QueueDirection[QueueDirection["TO_OUTTER"] = 1] = "TO_OUTTER";
|
|
183
|
+
})(QueueDirection = exports.QueueDirection || (exports.QueueDirection = {}));
|
|
184
|
+
var QueueItem = (function () {
|
|
185
|
+
function QueueItem(space, type, added_at, id, service, direction, rest) {
|
|
186
|
+
var _this = this;
|
|
187
|
+
this._triggerExec = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
188
|
+
var operation, _a, _b, _c, _d, error_1;
|
|
189
|
+
return __generator(this, function (_e) {
|
|
190
|
+
switch (_e.label) {
|
|
191
|
+
case 0:
|
|
192
|
+
_e.trys.push([0, 5, , 6]);
|
|
193
|
+
operation = this._getOperation(this._type);
|
|
194
|
+
if (!!!!this._details) return [3, 2];
|
|
195
|
+
_a = this;
|
|
196
|
+
_b = _a._progress;
|
|
197
|
+
return [4, operation()];
|
|
198
|
+
case 1:
|
|
199
|
+
_a._progress = _b + _e.sent();
|
|
200
|
+
return [3, 4];
|
|
201
|
+
case 2:
|
|
202
|
+
_c = this;
|
|
203
|
+
_d = _c._progress;
|
|
204
|
+
return [4, operation(this._details)];
|
|
205
|
+
case 3:
|
|
206
|
+
_c._progress = _d + _e.sent();
|
|
207
|
+
_e.label = 4;
|
|
208
|
+
case 4: return [3, 6];
|
|
209
|
+
case 5:
|
|
210
|
+
error_1 = _e.sent();
|
|
211
|
+
(0, console_1.errorMessage)("Error while processing queue ".concat(error_1, " - ").concat(JSON.stringify(error_1)));
|
|
212
|
+
return [3, 6];
|
|
213
|
+
case 6: return [2];
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}); };
|
|
217
|
+
this._getOperation = function (type) { return __awaiter(_this, void 0, void 0, function () {
|
|
218
|
+
var _this = this;
|
|
219
|
+
return __generator(this, function (_a) {
|
|
220
|
+
switch (type) {
|
|
221
|
+
case QueueItemTypeEnum.CLIENT_CREATE:
|
|
222
|
+
case QueueItemTypeEnum.CLIENT_DELETE:
|
|
223
|
+
case QueueItemTypeEnum.CLIENT_UPDATE:
|
|
224
|
+
case QueueItemTypeEnum.PRODUCT_CREATE:
|
|
225
|
+
return [2, this._space.addProduct];
|
|
226
|
+
case QueueItemTypeEnum.PRODUCT_DELETE:
|
|
227
|
+
return [2, function () {
|
|
228
|
+
return new Product_1.default(_this._details, DatabaseService_1.default.asCollectionObject(_this._space.getRef().path, _this._space.getRef().id + '/products'), "External service ".concat(_this._service.toString())).delete;
|
|
229
|
+
}];
|
|
230
|
+
case QueueItemTypeEnum.PRODUCT_UPDATE:
|
|
231
|
+
return [2, function () {
|
|
232
|
+
return new Product_1.default({ id: _this._details.id }, DatabaseService_1.default.asCollectionObject(_this._space.getRef().path, _this._space.getRef().id + '/products'), "External service ".concat(_this._service.toString())).save;
|
|
233
|
+
}];
|
|
234
|
+
case QueueItemTypeEnum.INVENTORY_UPDATE:
|
|
235
|
+
default:
|
|
236
|
+
return [2, function () { }];
|
|
237
|
+
}
|
|
238
|
+
return [2];
|
|
239
|
+
});
|
|
240
|
+
}); };
|
|
241
|
+
this._space = space;
|
|
242
|
+
this._type = type;
|
|
243
|
+
this._added_at = added_at;
|
|
244
|
+
this._id = id;
|
|
245
|
+
this._service = service;
|
|
246
|
+
this._direction = direction;
|
|
247
|
+
this._details = rest;
|
|
248
|
+
this._progress = '';
|
|
249
|
+
if (direction === QueueDirection.FROM_OUTTER)
|
|
250
|
+
this._triggerExec();
|
|
251
|
+
}
|
|
252
|
+
return QueueItem;
|
|
253
|
+
}());
|
|
254
|
+
exports.QueueItem = QueueItem;
|
|
255
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/Queue/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4FAAqE;AACrE,+CAAkD;AAClD,uDAAgC;AAGhC;IAGC,eAAmB,KAAY;QAA/B,iBAEC;QAEM,SAAI,GAAG;;;;;wBACb,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM;4BAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;wBAE5C,WAAM,yBAAe,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE;gCACjF,OAAO,EAAE,UAAU;gCACnB,KAAK,EAAE,MAAM;gCACb,KAAK,EAAE,CAAC;6BACR,CAAC,EAAA;;wBAJI,OAAO,GAAG,SAId;wBAEF,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC;4BAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;wBAC3E,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI;4BAA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AAC,YAAY,EAAE,CAAA;IAClE,CAAC;IA0CF,gBAAC;AAAD,CAAC,AAvED,IAuEC;AAvEY,8BAAS"}
|
|
@@ -556,7 +556,6 @@ export default class Space {
|
|
|
556
556
|
* @param amount The amount to add or remove
|
|
557
557
|
* @param comment The reason for this change
|
|
558
558
|
* @param user The user doing the action
|
|
559
|
-
* @returns
|
|
560
559
|
*/
|
|
561
560
|
private _modifyStoreCredit;
|
|
562
561
|
private _getStoreCreditToUse;
|
|
@@ -760,7 +759,7 @@ export default class Space {
|
|
|
760
759
|
};
|
|
761
760
|
updateCustomerLastActivity: (customerId: string, user: string, date?: Date) => Promise<void>;
|
|
762
761
|
credits: {
|
|
763
|
-
modify: (customerId: string, creditSlug: string, amount: number, comment: string, user: string) => Promise<
|
|
762
|
+
modify: (customerId: string, creditSlug: string, amount: number, comment: string, user: string) => Promise<ICustomer['store_credits']>;
|
|
764
763
|
get: (customerId: string, creditSlug: string) => Promise<number>;
|
|
765
764
|
getHistory: (customerId: string, creditSlug: string) => Promise<IStoreCreditHistory[]>;
|
|
766
765
|
validate: (customerId: string, creditSlug: string, amount: number) => Promise<boolean>;
|
package/dist/lib/Space/index.js
CHANGED
|
@@ -4941,7 +4941,6 @@ class Space {
|
|
|
4941
4941
|
* @param amount The amount to add or remove
|
|
4942
4942
|
* @param comment The reason for this change
|
|
4943
4943
|
* @param user The user doing the action
|
|
4944
|
-
* @returns
|
|
4945
4944
|
*/
|
|
4946
4945
|
this._modifyStoreCredit = async (customerId, creditSlug, amount, comment, user) => {
|
|
4947
4946
|
if (!customerId)
|
|
@@ -4952,8 +4951,6 @@ class Space {
|
|
|
4952
4951
|
throw new Error('A comment is required');
|
|
4953
4952
|
if (!user)
|
|
4954
4953
|
throw new Error('The user doing the action is required');
|
|
4955
|
-
if (amount == 0)
|
|
4956
|
-
return true; // do nothing if amount is 0
|
|
4957
4954
|
const customerPath = DatabaseService_1.default.addToPath(this._space_ref.path, this._space_ref.id + '/customers');
|
|
4958
4955
|
const historyPath = DatabaseService_1.default.addToPath(this._space_ref.path, this._space_ref.id + '/store_credit_history');
|
|
4959
4956
|
// fetch the user document
|
|
@@ -4973,6 +4970,8 @@ class Space {
|
|
|
4973
4970
|
else {
|
|
4974
4971
|
credits[index] = Object.assign(Object.assign({}, credits[index]), { amount: credits[index].amount + amount });
|
|
4975
4972
|
}
|
|
4973
|
+
if (amount == 0)
|
|
4974
|
+
return credits; // do nothing, and return credit as-is if amount is 0
|
|
4976
4975
|
// create history
|
|
4977
4976
|
const history = {
|
|
4978
4977
|
amount: amount,
|
|
@@ -4988,7 +4987,7 @@ class Space {
|
|
|
4988
4987
|
// save the new amount
|
|
4989
4988
|
if (!(await DatabaseService_1.default.saveDocument(customerPath, customerId, 0, { store_credits: credits }, { merge: true })))
|
|
4990
4989
|
throw new Error('Unable to save new credit value');
|
|
4991
|
-
return
|
|
4990
|
+
return credits;
|
|
4992
4991
|
};
|
|
4993
4992
|
this._getStoreCreditToUse = () => {
|
|
4994
4993
|
const allCredits = this.data().store_credits || [];
|