@resolveio/server-lib 6.4.23-newrole → 7.0.0
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/collections/counter.collection.d.ts +0 -2
- package/collections/counter.collection.js +0 -14
- package/collections/counter.collection.js.map +1 -1
- package/collections/file.collection.d.ts +0 -2
- package/collections/file.collection.js +0 -14
- package/collections/file.collection.js.map +1 -1
- package/collections/user.collection.d.ts +0 -1
- package/collections/user.collection.js +32 -43
- package/collections/user.collection.js.map +1 -1
- package/fixtures/cron-jobs.js +0 -17
- package/fixtures/cron-jobs.js.map +1 -1
- package/http/auth.js +173 -20
- package/http/auth.js.map +1 -1
- package/http/home.js +37 -0
- package/http/home.js.map +1 -1
- package/index.d.ts +1 -4
- package/index.js +22 -71
- package/index.js.map +1 -1
- package/managers/method.manager.d.ts +0 -1
- package/managers/method.manager.js +2 -28
- package/managers/method.manager.js.map +1 -1
- package/managers/subscription.manager.d.ts +0 -3
- package/managers/subscription.manager.js +19 -142
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js.map +1 -1
- package/methods/cron-jobs.js +0 -68
- package/methods/cron-jobs.js.map +1 -1
- package/methods/support.d.ts +2 -0
- package/methods/support.js +439 -0
- package/methods/support.js.map +1 -0
- package/models/user.model.d.ts +14 -25
- package/models/user.model.js.map +1 -1
- package/package.json +1 -1
- package/publications/files.js +0 -31
- package/publications/files.js.map +1 -1
- package/publications/report-builder-libraries.js +3 -2
- package/publications/report-builder-libraries.js.map +1 -1
- package/server-app.d.ts +0 -4
- package/server-app.js +11 -71
- package/server-app.js.map +1 -1
- package/client-server-app.d.ts +0 -1
- package/client-server-app.js +0 -48
- package/client-server-app.js.map +0 -1
- package/collections/billing-logged-in-users.collection.d.ts +0 -7
- package/collections/billing-logged-in-users.collection.js +0 -75
- package/collections/billing-logged-in-users.collection.js.map +0 -1
- package/collections/support-ticket.collection.d.ts +0 -7
- package/collections/support-ticket.collection.js +0 -226
- package/collections/support-ticket.collection.js.map +0 -1
- package/managers/support.manager.d.ts +0 -22
- package/managers/support.manager.js +0 -329
- package/managers/support.manager.js.map +0 -1
- package/models/support-method.model.d.ts +0 -9
- package/models/support-method.model.js +0 -4
- package/models/support-method.model.js.map +0 -1
- package/publications/billing-logged-in-users.d.ts +0 -1
- package/publications/billing-logged-in-users.js +0 -65
- package/publications/billing-logged-in-users.js.map +0 -1
- package/publications/support-tickets.d.ts +0 -1
- package/publications/support-tickets.js +0 -203
- package/publications/support-tickets.js.map +0 -1
- package/support-methods/aws.d.ts +0 -2
- package/support-methods/aws.js +0 -279
- package/support-methods/aws.js.map +0 -1
- package/support-methods/collections.d.ts +0 -2
- package/support-methods/collections.js +0 -475
- package/support-methods/collections.js.map +0 -1
- package/support-methods/counters.d.ts +0 -2
- package/support-methods/counters.js +0 -192
- package/support-methods/counters.js.map +0 -1
- package/support-methods/support.d.ts +0 -2
- package/support-methods/support.js +0 -282
- package/support-methods/support.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function loadBillingLoggedInUsersPublications(subscriptionManager: any): void;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var simpl_schema_1 = require("simpl-schema");
|
|
4
|
-
var billing_logged_in_users_collection_1 = require("../collections/billing-logged-in-users.collection");
|
|
5
|
-
function loadBillingLoggedInUsersPublications(subscriptionManager) {
|
|
6
|
-
subscriptionManager.publications({
|
|
7
|
-
billingloggedinusers: {
|
|
8
|
-
function: function () {
|
|
9
|
-
return billing_logged_in_users_collection_1.BillingLoggedInUsers.find().sort({ date: -1 }).exec();
|
|
10
|
-
},
|
|
11
|
-
collections: ['billing-logged-in-users']
|
|
12
|
-
},
|
|
13
|
-
billingloggedinusersWithClientAndUserId: {
|
|
14
|
-
function: function (client, id_user) {
|
|
15
|
-
return billing_logged_in_users_collection_1.BillingLoggedInUsers.find({
|
|
16
|
-
$and: [
|
|
17
|
-
{ client: client },
|
|
18
|
-
{ id_user: id_user }
|
|
19
|
-
]
|
|
20
|
-
}).exec();
|
|
21
|
-
},
|
|
22
|
-
check: new simpl_schema_1.default({
|
|
23
|
-
client: {
|
|
24
|
-
type: String
|
|
25
|
-
},
|
|
26
|
-
id_user: {
|
|
27
|
-
type: String
|
|
28
|
-
}
|
|
29
|
-
}),
|
|
30
|
-
collections: ['billing-logged-in-users'],
|
|
31
|
-
fetchFunction: function (document, client, id_user) {
|
|
32
|
-
return document['id_user'] === id_user && document['client'] === client;
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
billingloggedinusersWithClientAndDates: {
|
|
36
|
-
function: function (client, date_start, date_end) {
|
|
37
|
-
return billing_logged_in_users_collection_1.BillingLoggedInUsers.find({
|
|
38
|
-
$and: [
|
|
39
|
-
{ client: client },
|
|
40
|
-
{ date: { $gte: date_start } },
|
|
41
|
-
{ date: { $lte: date_end } }
|
|
42
|
-
]
|
|
43
|
-
}).exec();
|
|
44
|
-
},
|
|
45
|
-
check: new simpl_schema_1.default({
|
|
46
|
-
client: {
|
|
47
|
-
type: String
|
|
48
|
-
},
|
|
49
|
-
date_start: {
|
|
50
|
-
type: Date
|
|
51
|
-
},
|
|
52
|
-
date_end: {
|
|
53
|
-
type: Date
|
|
54
|
-
}
|
|
55
|
-
}),
|
|
56
|
-
collections: ['billing-logged-in-users'],
|
|
57
|
-
fetchFunction: function (document, date_start, date_end) {
|
|
58
|
-
return document['date'].getTime() >= date_start && document['date'].getTime() <= date_end;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
exports.loadBillingLoggedInUsersPublications = loadBillingLoggedInUsersPublications;
|
|
64
|
-
|
|
65
|
-
//# sourceMappingURL=billing-logged-in-users.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/publications/billing-logged-in-users.ts"],"names":[],"mappings":";;AAAA,6CAAwC;AA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AI,EAAE,CAAC;YACX,CAAC;YACD,KAAK,EAAE,IAAI,sBAAY,CAAC;gBACvB,MAAM,EAAE;oBACP,IAAI,EAAE,MAAM;iBACZ;gBACD,UAAU,EAAE;oBACX,IAAI,EAAE,IAAI;iBACV;gBACD,QAAQ,EAAE;oBACT,IAAI,EAAE,IAAI;iBACV;aACD,CAAC;YACF,WAAW,EAAE,CAAC,yBAAyB,CAAC;YACxC,aAAa,EAAE,UAAC,QAAkB,EAAE,UAAgB,EAAE,QAAc;gBACnE,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,IAAI,UAAU,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,IAAI,QAAQ,CAAC;YAC3F,CAAC;SACD;KACD,CAAC,CAAC;AACJ,CAAC;AAzDD,oFAyDC","file":"billing-logged-in-users.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { Document } from 'mongoose';\nimport { BillingLoggedInUsers } from '../collections/billing-logged-in-users.collection';\n\nexport function loadBillingLoggedInUsersPublications(subscriptionManager) {\n\tsubscriptionManager.publications({\n\t\tbillingloggedinusers: {\n\t\t\tfunction: () => {\n\t\t\t\treturn BillingLoggedInUsers.find().sort({date: -1}).exec();\n\t\t\t},\n\t\t\tcollections: ['billing-logged-in-users']\n\t\t},\n\t\tbillingloggedinusersWithClientAndUserId: {\n\t\t\tfunction: (client: string, id_user: string) => {\n\t\t\t\treturn BillingLoggedInUsers.find({\n\t\t\t\t\t$and: [\n\t\t\t\t\t\t{client: client},\n\t\t\t\t\t\t{id_user: id_user}\n\t\t\t\t\t]\n\t\t\t\t}).exec();\n\t\t\t},\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tclient: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tid_user: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tcollections: ['billing-logged-in-users'],\n\t\t\tfetchFunction: (document: Document, client: string, id_user: string) => {\n\t\t\t\treturn document['id_user'] === id_user && document['client'] === client;\n\t\t\t}\n\t\t},\n\t\tbillingloggedinusersWithClientAndDates: {\n\t\t\tfunction: (client: string, date_start: Date, date_end: Date) => {\n\t\t\t\treturn BillingLoggedInUsers.find({\n\t\t\t\t\t$and: [\n\t\t\t\t\t\t{client: client},\n\t\t\t\t\t\t{date: {$gte: date_start}},\n\t\t\t\t\t\t{date: {$lte: date_end}}\n\t\t\t\t\t]\n\t\t\t\t}).exec();\n\t\t\t},\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tclient: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdate_start: {\n\t\t\t\t\ttype: Date\n\t\t\t\t},\n\t\t\t\tdate_end: {\n\t\t\t\t\ttype: Date\n\t\t\t\t}\n\t\t\t}),\n\t\t\tcollections: ['billing-logged-in-users'],\n\t\t\tfetchFunction: (document: Document, date_start: Date, date_end: Date) => {\n\t\t\t\treturn document['date'].getTime() >= date_start && document['date'].getTime() <= date_end;\n\t\t\t}\n\t\t}\n\t});\n}"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function loadSupportTicketPublications(subscriptionManager: any): void;
|
|
@@ -1,203 +0,0 @@
|
|
|
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 (_) 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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var support_ticket_collection_1 = require("../collections/support-ticket.collection");
|
|
40
|
-
var simpl_schema_1 = require("simpl-schema");
|
|
41
|
-
var pagination_model_1 = require("../models/pagination.model");
|
|
42
|
-
var index_1 = require("../index");
|
|
43
|
-
function loadSupportTicketPublications(subscriptionManager) {
|
|
44
|
-
var _this = this;
|
|
45
|
-
subscriptionManager.publications({
|
|
46
|
-
supporttickets: {
|
|
47
|
-
function: function () {
|
|
48
|
-
return support_ticket_collection_1.SupportTickets.find({ client: index_1.ResolveIOServer.getClientName() }).sort({ type: 1 }).exec();
|
|
49
|
-
},
|
|
50
|
-
collections: ['support-tickets'],
|
|
51
|
-
fetchFunction: function (document) {
|
|
52
|
-
return document['client'] === index_1.ResolveIOServer.getClientName() ? true : false;
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
supportticketWithId: {
|
|
56
|
-
function: function (id_support_ticket) {
|
|
57
|
-
return support_ticket_collection_1.SupportTickets.findById(id_support_ticket).exec();
|
|
58
|
-
},
|
|
59
|
-
check: new simpl_schema_1.default({
|
|
60
|
-
id_support_ticket: {
|
|
61
|
-
type: String
|
|
62
|
-
}
|
|
63
|
-
}),
|
|
64
|
-
collections: ['support-tickets'],
|
|
65
|
-
fetchFunction: function (document, id_support_ticket) {
|
|
66
|
-
return document._id === id_support_ticket;
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
supportticketDetails: {
|
|
70
|
-
function: function (id_support_ticket) {
|
|
71
|
-
return support_ticket_collection_1.SupportTickets.aggregate([
|
|
72
|
-
{
|
|
73
|
-
$match: { _id: id_support_ticket }
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
$lookup: {
|
|
77
|
-
from: 'files',
|
|
78
|
-
localField: 'files',
|
|
79
|
-
foreignField: '_id',
|
|
80
|
-
as: 'dbFiles'
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
]).exec();
|
|
84
|
-
},
|
|
85
|
-
check: new simpl_schema_1.default({
|
|
86
|
-
id_support_ticket: {
|
|
87
|
-
type: String
|
|
88
|
-
}
|
|
89
|
-
}),
|
|
90
|
-
collections: ['support-tickets', 'files'],
|
|
91
|
-
preFunction: function (id_support_ticket) { return __awaiter(_this, void 0, void 0, function () {
|
|
92
|
-
var support_ticket;
|
|
93
|
-
return __generator(this, function (_a) {
|
|
94
|
-
switch (_a.label) {
|
|
95
|
-
case 0: return [4 /*yield*/, support_ticket_collection_1.SupportTickets.findOne({ _id: id_support_ticket })];
|
|
96
|
-
case 1:
|
|
97
|
-
support_ticket = _a.sent();
|
|
98
|
-
if (!support_ticket) {
|
|
99
|
-
return [2 /*return*/, {
|
|
100
|
-
_id: '',
|
|
101
|
-
support_ticket: []
|
|
102
|
-
}];
|
|
103
|
-
}
|
|
104
|
-
return [2 /*return*/, {
|
|
105
|
-
_id: support_ticket._id,
|
|
106
|
-
files: support_ticket.files
|
|
107
|
-
}];
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}); },
|
|
111
|
-
fetchFunction: function (document, fetchData) {
|
|
112
|
-
return document._id === fetchData['_id'] ||
|
|
113
|
-
fetchData['files'].includes(document._id);
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
supportticketsWithOptions: {
|
|
117
|
-
function: function (options, search, filters) {
|
|
118
|
-
return support_ticket_collection_1.SupportTickets.find(searchQuery.call(_this, search, filters)).sort(options.sort).limit(options.limit).skip(options.skip).select(options.fields).exec();
|
|
119
|
-
},
|
|
120
|
-
check: new simpl_schema_1.default({
|
|
121
|
-
options: {
|
|
122
|
-
type: pagination_model_1.PaginationOptionsSchema
|
|
123
|
-
},
|
|
124
|
-
search: {
|
|
125
|
-
type: String,
|
|
126
|
-
optional: true
|
|
127
|
-
},
|
|
128
|
-
filters: {
|
|
129
|
-
type: Array,
|
|
130
|
-
optional: true
|
|
131
|
-
},
|
|
132
|
-
'filters.$': {
|
|
133
|
-
type: Object
|
|
134
|
-
},
|
|
135
|
-
'filters.$.prop': {
|
|
136
|
-
type: String
|
|
137
|
-
},
|
|
138
|
-
'filters.$.data': {
|
|
139
|
-
type: String
|
|
140
|
-
}
|
|
141
|
-
}),
|
|
142
|
-
collections: ['support-tickets']
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
exports.loadSupportTicketPublications = loadSupportTicketPublications;
|
|
147
|
-
function searchQuery(search, filters) {
|
|
148
|
-
if (!search && (!filters || !filters.length)) {
|
|
149
|
-
return {};
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
var searchObj_1 = {};
|
|
153
|
-
if (filters && filters.length) {
|
|
154
|
-
searchObj_1['$and'] = [];
|
|
155
|
-
filters.forEach(function (filter) {
|
|
156
|
-
var _a;
|
|
157
|
-
searchObj_1['$and'].push((_a = {}, _a[filter['prop']] = filter['data'], _a));
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
if (search) {
|
|
161
|
-
var searchRegEx = { '$regex': '.*' + (search || '') + '.*', '$options': 'i' };
|
|
162
|
-
if (searchObj_1['$and']) {
|
|
163
|
-
searchObj_1['$and'].push({
|
|
164
|
-
$or: [
|
|
165
|
-
{
|
|
166
|
-
support_ticket_number_string: searchRegEx
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
date_created_string: searchRegEx
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
status: searchRegEx
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
user_created: searchRegEx
|
|
176
|
-
}
|
|
177
|
-
]
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
searchObj_1 = {
|
|
182
|
-
$or: [
|
|
183
|
-
{
|
|
184
|
-
support_ticket_number_string: searchRegEx
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
date_created_string: searchRegEx
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
status: searchRegEx
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
user_created: searchRegEx
|
|
194
|
-
}
|
|
195
|
-
]
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return searchObj_1;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
//# sourceMappingURL=support-tickets.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/publications/support-tickets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sFAA0E;AAC1E,6CAAwC;AACxC,+DAAqE;AAErE,kCAA2C;AAE3C,SAAgB,6BAA6B,CAAC,mBAAmB;IAAjE,iBAgGC;IA/FA,mBAAmB,CAAC,YAAY,CAAC;QAChC,cAAc,EAAE;YACf,QAAQ,EAAE;gBACT,OAAO,0CAAc,CAAC,IAAI,CAAC,EAAC,MAAM,EAAE,uBAAe,CAAC,aAAa,EAAE,EAAC,CAAC,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,CAAC,EAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAC9F,CAAC;YACD,WAAW,EAAE,CAAC,iBAAiB,CAAC;YAChC,aAAa,EAAE,UAAC,QAAkB;gBACjC,OAAO,QAAQ,CAAC,QAAQ,CAAC,KAAK,uBAAe,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;YAC9E,CAAC;SACD;QACD,mBAAmB,EAAE;YACpB,QAAQ,EAAE,UAAC,iBAAyB;gBACnC,OAAO,0CAAc,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,IAAI,EAAE,CAAC;YAC1D,CAAC;YACD,KAAK,EAAE,IAAI,sBAAY,CAAC;gBACvB,iBAAiB,EAAE;oBAClB,IAAI,EAAE,MAAM;iBACZ;aACD,CAAC;YACF,WAAW,EAAE,CAAC,iBAAiB,CAAC;YAChC,aAAa,EAAE,UAAC,QAAkB,EAAE,iBAAyB;gBAC5D,OAAO,QAAQ,CAAC,GAAG,KAAK,iBAAiB,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C;SACH;QAED,IAAI,MAAM,EAAE;YACX,IAAM,WAAW,GAAG,EAAE,QAAQ,EAAE,IAAI,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC;YAEhF,IAAI,WAAS,CAAC,MAAM,CAAC,EAAE;gBACtB,WAAS,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;oBACtB,GAAG,EAAE;wBACJ;4BACC,4BAA4B,EAAE,WAAW;yBACzC;wBACD;4BACC,mBAAmB,EAAE,WAAW;yBAChC;wBACD;4BACC,MAAM,EAAE,WAAW;yBACnB;wBACD;4BACC,YAAY,EAAE,WAAW;yBACzB;qBACD;iBACD,CAAC,CAAC;aACH;iBACI;gBACJ,WAAS,GAAG;oBACX,GAAG,EAAE;wBACJ;4BACC,4BAA4B,EAAE,WAAW;yBACzC;wBACD;4BACC,mBAAmB,EAAE,WAAW;yBAChC;wBACD;4BACC,MAAM,EAAE,WAAW;yBACnB;wBACD;4BACC,YAAY,EAAE,WAAW;yBACzB;qBACD;iBACD,CAAC;aACF;SACD;QAED,OAAO,WAAS,CAAC;KACjB;AACF,CAAC","file":"support-tickets.js","sourcesContent":["import { SupportTickets } from '../collections/support-ticket.collection';\nimport SimpleSchema from 'simpl-schema';\nimport { PaginationOptionsSchema } from '../models/pagination.model';\nimport { Document } from 'mongoose';\nimport { ResolveIOServer } from '../index';\n\nexport function loadSupportTicketPublications(subscriptionManager) {\n\tsubscriptionManager.publications({\n\t\tsupporttickets: {\n\t\t\tfunction: () => {\n\t\t\t\treturn SupportTickets.find({client: ResolveIOServer.getClientName()}).sort({type: 1}).exec();\n\t\t\t},\n\t\t\tcollections: ['support-tickets'],\n\t\t\tfetchFunction: (document: Document) => {\n\t\t\t\treturn document['client'] === ResolveIOServer.getClientName() ? true : false;\n\t\t\t}\n\t\t},\n\t\tsupportticketWithId: {\n\t\t\tfunction: (id_support_ticket: string) => {\n\t\t\t\treturn SupportTickets.findById(id_support_ticket).exec();\n\t\t\t},\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_support_ticket: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tcollections: ['support-tickets'],\n\t\t\tfetchFunction: (document: Document, id_support_ticket: string) => {\n\t\t\t\treturn document._id === id_support_ticket;\n\t\t\t}\n\t\t},\n\t\tsupportticketDetails: {\n\t\t\tfunction: (id_support_ticket: string) => {\n\t\t\t\treturn SupportTickets.aggregate([\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {_id: id_support_ticket}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$lookup: {\n\t\t\t\t\t\t\tfrom: 'files',\n\t\t\t\t\t\t\tlocalField: 'files',\n\t\t\t\t\t\t\tforeignField: '_id',\n\t\t\t\t\t\t\tas: 'dbFiles'\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]).exec();\n\t\t\t},\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_support_ticket: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tcollections: ['support-tickets', 'files'],\n\t\t\tpreFunction: async (id_support_ticket: string) => {\n\t\t\t\tlet support_ticket = await SupportTickets.findOne({_id: id_support_ticket});\n\n\t\t\t\tif (!support_ticket) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t_id: '',\n\t\t\t\t\t\tsupport_ticket: []\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\t_id: support_ticket._id,\n\t\t\t\t\tfiles: support_ticket.files\n\t\t\t\t};\n\t\t\t},\n\t\t\tfetchFunction: (document: Document, fetchData: Object, ) => {\n\t\t\t\treturn document._id === fetchData['_id'] ||\n\t\t\t\t\tfetchData['files'].includes(document._id);\n\t\t\t}\n\t\t},\n\t\tsupportticketsWithOptions: {\n\t\t\tfunction: (options, search, filters) => {\n\t\t\t\treturn SupportTickets.find(searchQuery.call(this, search, filters)).sort(options.sort).limit(options.limit).skip(options.skip).select(options.fields).exec();\n\t\t\t},\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\toptions: {\n\t\t\t\t\ttype: PaginationOptionsSchema\n\t\t\t\t},\n\t\t\t\tsearch: {\n\t\t\t\t\ttype: String,\n\t\t\t\t\toptional: true\n\t\t\t\t},\n\t\t\t\tfilters: {\n\t\t\t\t\ttype: Array,\n\t\t\t\t\toptional: true\n\t\t\t\t},\n\t\t\t\t'filters.$': {\n\t\t\t\t\ttype: Object\n\t\t\t\t},\n\t\t\t\t'filters.$.prop': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\t'filters.$.data': {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tcollections: ['support-tickets']\n\t\t}\n\t});\n}\n\nfunction searchQuery(search?: string, filters?: Array<Object>): Object {\n\n\tif (!search && (!filters || !filters.length)) {\n\t\treturn {};\n\t}\n\telse {\n\t\tlet searchObj = {};\n\n\t\tif (filters && filters.length) {\n\t\t\tsearchObj['$and'] = [];\n\n\t\t\tfilters.forEach(filter => {\n\t\t\t\tsearchObj['$and'].push({[filter['prop']]: filter['data']});\n\t\t\t});\n\t\t}\n\t\t\n\t\tif (search) {\n\t\t\tconst searchRegEx = { '$regex': '.*' + (search || '') + '.*', '$options': 'i' };\n\n\t\t\tif (searchObj['$and']) {\n\t\t\t\tsearchObj['$and'].push({\n\t\t\t\t\t$or: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsupport_ticket_number_string: searchRegEx\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdate_created_string: searchRegEx\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: searchRegEx\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tuser_created: searchRegEx\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t});\n\t\t\t}\t\n\t\t\telse {\n\t\t\t\tsearchObj = {\n\t\t\t\t\t$or: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsupport_ticket_number_string: searchRegEx\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdate_created_string: searchRegEx\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: searchRegEx\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tuser_created: searchRegEx\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn searchObj; \n\t}\n}"]}
|
package/support-methods/aws.d.ts
DELETED
package/support-methods/aws.js
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
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 (_) 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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var file_collection_1 = require("../collections/file.collection");
|
|
40
|
-
var mongoose_1 = require("mongoose");
|
|
41
|
-
var simpl_schema_1 = require("simpl-schema");
|
|
42
|
-
var pdfCnt = 1000000;
|
|
43
|
-
function loadAWSMethods(supportManager) {
|
|
44
|
-
supportManager.supportMethods({
|
|
45
|
-
uploadFileAndSave: {
|
|
46
|
-
check: new simpl_schema_1.default({
|
|
47
|
-
fileName: {
|
|
48
|
-
type: String
|
|
49
|
-
},
|
|
50
|
-
fileData: {
|
|
51
|
-
type: String
|
|
52
|
-
},
|
|
53
|
-
fileSize: {
|
|
54
|
-
type: Number
|
|
55
|
-
},
|
|
56
|
-
fileOrder: {
|
|
57
|
-
type: Number
|
|
58
|
-
},
|
|
59
|
-
fileType: {
|
|
60
|
-
type: String
|
|
61
|
-
}
|
|
62
|
-
}),
|
|
63
|
-
function: function (fileName, fileData, fileSize, fileOrder, fileType) {
|
|
64
|
-
var that = this;
|
|
65
|
-
return new Promise(function (resolve, reject) {
|
|
66
|
-
if (fileName) {
|
|
67
|
-
var key_1 = 'uploads/' + Date.now() + '-' + (pdfCnt++) + '-' + fileName;
|
|
68
|
-
var newParams = { Bucket: that.serverConfig.AWSBUCKET, Key: key_1, Body: Buffer.from(fileData.replace('data:' + fileData.split(',')[0].split(':')[1].split(';')[0] + ';base64,', ''), 'base64'), ACL: 'private', ContentType: fileData.split(',')[0].split(':')[1].split(';')[0], ContentDisposition: 'inline' };
|
|
69
|
-
that.getAWS().upload(newParams, function (err, res) {
|
|
70
|
-
if (err) {
|
|
71
|
-
reject(err);
|
|
72
|
-
}
|
|
73
|
-
else if (res) {
|
|
74
|
-
file_collection_1.SupportFiles.create({
|
|
75
|
-
_id: mongoose_1.Types.ObjectId().toHexString(), __v: 0, name: fileName, size: fileSize, key: key_1, order: fileOrder, type: fileType
|
|
76
|
-
}).then(function (resFile) {
|
|
77
|
-
resolve(resFile);
|
|
78
|
-
}, function (errFile) { return reject(errFile); });
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
deleteFiles: {
|
|
86
|
-
check: new simpl_schema_1.default({
|
|
87
|
-
keys: {
|
|
88
|
-
type: Array
|
|
89
|
-
},
|
|
90
|
-
'keys.$': {
|
|
91
|
-
type: String
|
|
92
|
-
}
|
|
93
|
-
}),
|
|
94
|
-
function: function (keys) {
|
|
95
|
-
var _this = this;
|
|
96
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
97
|
-
var files, deleteCnt;
|
|
98
|
-
var _this = this;
|
|
99
|
-
return __generator(this, function (_a) {
|
|
100
|
-
switch (_a.label) {
|
|
101
|
-
case 0: return [4 /*yield*/, file_collection_1.SupportFiles.find({ key: { $in: keys } })];
|
|
102
|
-
case 1:
|
|
103
|
-
files = _a.sent();
|
|
104
|
-
deleteCnt = files.length;
|
|
105
|
-
files.forEach(function (file) {
|
|
106
|
-
file_collection_1.SupportFiles.deleteOne({ _id: file._id }).exec();
|
|
107
|
-
var delParams = { Bucket: _this.serverConfig.AWSBUCKET, Key: file.key };
|
|
108
|
-
_this.getAWS().deleteObject(delParams, function (err, res) {
|
|
109
|
-
if (err) {
|
|
110
|
-
reject(err);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
deleteCnt--;
|
|
114
|
-
if (!deleteCnt) {
|
|
115
|
-
resolve(res);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
return [2 /*return*/];
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}); });
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
deleteFile: {
|
|
127
|
-
check: new simpl_schema_1.default({
|
|
128
|
-
key: {
|
|
129
|
-
type: String
|
|
130
|
-
}
|
|
131
|
-
}),
|
|
132
|
-
function: function (key) {
|
|
133
|
-
var _this = this;
|
|
134
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
135
|
-
var file, delParams;
|
|
136
|
-
return __generator(this, function (_a) {
|
|
137
|
-
switch (_a.label) {
|
|
138
|
-
case 0: return [4 /*yield*/, file_collection_1.SupportFiles.findOne({ key: key })];
|
|
139
|
-
case 1:
|
|
140
|
-
file = _a.sent();
|
|
141
|
-
if (!file) {
|
|
142
|
-
reject('Could not find file');
|
|
143
|
-
}
|
|
144
|
-
file_collection_1.SupportFiles.deleteOne({ _id: file._id }).exec();
|
|
145
|
-
delParams = { Bucket: this.serverConfig['AWSBUCKET'], Key: key };
|
|
146
|
-
this.getAWS().deleteObject(delParams, function (err, res) {
|
|
147
|
-
if (err) {
|
|
148
|
-
reject(err);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
resolve(res);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
return [2 /*return*/];
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}); });
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
deleteFileWithId: {
|
|
161
|
-
check: new simpl_schema_1.default({
|
|
162
|
-
id_file: {
|
|
163
|
-
type: String
|
|
164
|
-
}
|
|
165
|
-
}),
|
|
166
|
-
function: function (id_file) {
|
|
167
|
-
var _this = this;
|
|
168
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
169
|
-
var file, delParams;
|
|
170
|
-
return __generator(this, function (_a) {
|
|
171
|
-
switch (_a.label) {
|
|
172
|
-
case 0: return [4 /*yield*/, file_collection_1.SupportFiles.findOne({ _id: id_file })];
|
|
173
|
-
case 1:
|
|
174
|
-
file = _a.sent();
|
|
175
|
-
if (!file) {
|
|
176
|
-
reject('Could not find file');
|
|
177
|
-
}
|
|
178
|
-
delParams = { Bucket: this.serverConfig['AWSBUCKET'], Key: file.key };
|
|
179
|
-
this.getAWS().deleteObject(delParams, function (err, res) {
|
|
180
|
-
if (err) {
|
|
181
|
-
reject(err);
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
resolve(res);
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
file_collection_1.SupportFiles.deleteOne({ _id: file._id }).exec();
|
|
188
|
-
return [2 /*return*/];
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
}); });
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
getSignedUrlWithId: {
|
|
195
|
-
check: new simpl_schema_1.default({
|
|
196
|
-
id_file: {
|
|
197
|
-
type: String
|
|
198
|
-
},
|
|
199
|
-
expires: {
|
|
200
|
-
type: Number
|
|
201
|
-
}
|
|
202
|
-
}),
|
|
203
|
-
function: function (id_file, expires) {
|
|
204
|
-
var _this = this;
|
|
205
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
206
|
-
var file, params;
|
|
207
|
-
return __generator(this, function (_a) {
|
|
208
|
-
switch (_a.label) {
|
|
209
|
-
case 0: return [4 /*yield*/, file_collection_1.SupportFiles.findOne({ _id: id_file })];
|
|
210
|
-
case 1:
|
|
211
|
-
file = _a.sent();
|
|
212
|
-
params = { Bucket: this.serverConfig.AWSBUCKET, Key: file.key, Expires: expires };
|
|
213
|
-
this.getAWS().getSignedUrl('getObject', params, function (err, res) {
|
|
214
|
-
if (err) {
|
|
215
|
-
reject(err);
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
resolve(res);
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
return [2 /*return*/];
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}); });
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
getSignedUrl: {
|
|
228
|
-
check: new simpl_schema_1.default({
|
|
229
|
-
key: {
|
|
230
|
-
type: String
|
|
231
|
-
},
|
|
232
|
-
expires: {
|
|
233
|
-
type: Number
|
|
234
|
-
}
|
|
235
|
-
}),
|
|
236
|
-
function: function (key, expires) {
|
|
237
|
-
var _this = this;
|
|
238
|
-
return new Promise(function (resolve, reject) {
|
|
239
|
-
var params = { Bucket: _this.serverConfig.AWSBUCKET, Key: key, Expires: expires };
|
|
240
|
-
_this.getAWS().getSignedUrl('getObject', params, function (err, res) {
|
|
241
|
-
if (err) {
|
|
242
|
-
reject(err);
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
resolve(res);
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
getSignedUrls: {
|
|
252
|
-
check: new simpl_schema_1.default({
|
|
253
|
-
keys: {
|
|
254
|
-
type: Array
|
|
255
|
-
},
|
|
256
|
-
'keys.$': {
|
|
257
|
-
type: String
|
|
258
|
-
},
|
|
259
|
-
expires: {
|
|
260
|
-
type: Number
|
|
261
|
-
}
|
|
262
|
-
}),
|
|
263
|
-
function: function (keys, expires) {
|
|
264
|
-
var _this = this;
|
|
265
|
-
return new Promise(function (resolve, reject) {
|
|
266
|
-
var res = [];
|
|
267
|
-
keys.forEach(function (key) {
|
|
268
|
-
var params = { Bucket: _this.serverConfig.AWSBUCKET, Key: key, Expires: expires };
|
|
269
|
-
res.push(_this.getAWS().getSignedUrl('getObject', params));
|
|
270
|
-
});
|
|
271
|
-
resolve(res);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
exports.loadAWSMethods = loadAWSMethods;
|
|
278
|
-
|
|
279
|
-
//# sourceMappingURL=aws.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/support-methods/aws.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kEAA8D;AAC9D,qCAAiC;AACjC,6CAAwC;AAGxC,IAAI,MAAM,GAAG,OAAO,CAAC;AAErB,SAAgB,cAAc,CAAC,cAA8B;IAC5D,cAAc,CAAC,cAAc,CAAC;QAC7B,iBAAiB,EAAE;YAClB,KAAK,EAAE,IAAI,sBAAY,CAAC;gBACvB,QAAQ,EAAE;oBACT,IAAI,EAAE,MAAM;iBACZ;gBACD,QAAQ,EAAE;oBACT,IAAI,EAAE,MAAM;iBACZ;gBACD,QAAQ,EAAE;oBACT,IAAI,EAAE,MAAM;iBACZ;gBACD,SAAS,EAAE;oBACV,IAAI,EAAE,MAAM;iBACZ;gBACD,QAAQ,EAAE;oBACT,IAAI,EAAE,MAAM;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,EAAE,MAAM;iBACZ;gBACD,OAAO,EAAE;oBACR,IAAI,EAAE,MAAM;iBACZ;aACD,CAAC;YACF,QAAQ,EAAE,UAAS,IAAc,EAAE,OAAe;gBAAxC,iBAYT;gBAXA,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;oBAClC,IAAI,GAAG,GAAG,EAAE,CAAC;oBAEb,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;wBACf,IAAI,MAAM,GAAG,EAAC,MAAM,EAAE,KAAI,CAAC,YAAY,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAC,CAAC;wBAE/E,GAAG,CAAC,IAAI,CAAC,KAAI,CAAC,MAAM,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;oBAC3D,CAAC,CAAC,CAAC;oBAEH,OAAO,CAAC,GAAG,CAAC,CAAC;gBACd,CAAC,CAAC,CAAC;YACJ,CAAC;SACD;KACD,CAAC,CAAC;AACJ,CAAC;AAvND,wCAuNC","file":"aws.js","sourcesContent":["import { SupportFiles } from '../collections/file.collection';\nimport { Types } from 'mongoose';\nimport SimpleSchema from 'simpl-schema';\nimport { SupportManager } from '../managers/support.manager';\n\nlet pdfCnt = 1000000;\n\nexport function loadAWSMethods(supportManager: SupportManager) {\n\tsupportManager.supportMethods({\n\t\tuploadFileAndSave: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tfileName: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tfileData: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tfileSize: {\n\t\t\t\t\ttype: Number\n\t\t\t\t},\n\t\t\t\tfileOrder: {\n\t\t\t\t\ttype: Number\n\t\t\t\t},\n\t\t\t\tfileType: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(fileName: string, fileData: string, fileSize: number, fileOrder: number, fileType: string) {\n\t\t\t\tlet that = this;\n\t\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t\tif (fileName) {\n\t\t\t\t\t\tlet key = 'uploads/' + Date.now() + '-' + (pdfCnt++) + '-' + fileName;\n\t\t\n\t\t\t\t\t\tlet newParams = {Bucket: that.serverConfig.AWSBUCKET, Key: key, Body: Buffer.from(fileData.replace('data:' + fileData.split(',')[0].split(':')[1].split(';')[0] + ';base64,', ''), 'base64'), ACL: 'private', ContentType: fileData.split(',')[0].split(':')[1].split(';')[0], ContentDisposition: 'inline'};\n\n\t\t\t\t\t\tthat.getAWS().upload(newParams, (err, res) => {\n\t\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if (res) {\n\t\t\t\t\t\t\t\tSupportFiles.create({\n\t\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(), __v: 0, name: fileName, size: fileSize, key: key, order: fileOrder, type: fileType\n\t\t\t\t\t\t\t\t}).then(resFile => {\n\t\t\t\t\t\t\t\t\tresolve(resFile);\n\t\t\t\t\t\t\t\t}, errFile => reject(errFile));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tdeleteFiles: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tkeys: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'keys.$': {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(keys: string[]) {\t\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet files = await SupportFiles.find({key: {$in: keys}});\n\t\t\n\t\t\t\t\tlet deleteCnt = files.length;\n\t\t\n\t\t\t\t\tfiles.forEach(file => {\n\t\t\t\t\t\tSupportFiles.deleteOne({_id: file._id}).exec();\n\t\t\n\t\t\t\t\t\tlet delParams = {Bucket: this.serverConfig.AWSBUCKET, Key: file.key};\n\t\t\t\n\t\t\t\t\t\tthis.getAWS().deleteObject(delParams, function(err, res) {\n\t\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tdeleteCnt--;\n\t\t\t\t\t\t\t\tif (!deleteCnt) {\n\t\t\t\t\t\t\t\t\tresolve(res);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tdeleteFile: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tkey: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(key: string) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\n\t\t\t\t\tlet file = await SupportFiles.findOne({key: key});\n\t\t\n\t\t\t\t\tif (!file) {\n\t\t\t\t\t\treject('Could not find file');\n\t\t\t\t\t}\n\t\t\n\t\t\t\t\tSupportFiles.deleteOne({_id: file._id}).exec();\n\t\t\n\t\t\t\t\tlet delParams = {Bucket: this.serverConfig['AWSBUCKET'], Key: key};\n\t\t\n\t\t\t\t\tthis.getAWS().deleteObject(delParams, function(err, res) {\n\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tresolve(res);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tdeleteFileWithId: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_file: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(id_file: string) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\n\t\t\t\t\tlet file = await SupportFiles.findOne({_id: id_file});\n\t\t\n\t\t\t\t\tif (!file) {\n\t\t\t\t\t\treject('Could not find file');\n\t\t\t\t\t}\n\t\t\n\t\t\t\t\tlet delParams = {Bucket: this.serverConfig['AWSBUCKET'], Key: file.key};\n\t\t\n\t\t\t\t\tthis.getAWS().deleteObject(delParams, function(err, res) {\n\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tresolve(res);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\tSupportFiles.deleteOne({_id: file._id}).exec();\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tgetSignedUrlWithId: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tid_file: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\texpires: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(id_file: string, expires: number) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet file = await SupportFiles.findOne({_id: id_file});\n\t\t\t\t\tlet params = {Bucket: this.serverConfig.AWSBUCKET, Key: file.key, Expires: expires};\n\n\t\t\t\t\tthis.getAWS().getSignedUrl('getObject', params, (err, res) => {\n\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tresolve(res);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tgetSignedUrl: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tkey: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\texpires: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(key: string, expires: number) {\n\t\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t\tlet params = {Bucket: this.serverConfig.AWSBUCKET, Key: key, Expires: expires};\n\n\t\t\t\t\tthis.getAWS().getSignedUrl('getObject', params, (err, res) => {\n\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tresolve(res);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tgetSignedUrls: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tkeys: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'keys.$': {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\texpires: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(keys: string[], expires: number) {\n\t\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t\tlet res = [];\n\n\t\t\t\t\tkeys.forEach(key => {\n\t\t\t\t\t\tlet params = {Bucket: this.serverConfig.AWSBUCKET, Key: key, Expires: expires};\n\n\t\t\t\t\t\tres.push(this.getAWS().getSignedUrl('getObject', params));\n\t\t\t\t\t});\n\n\t\t\t\t\tresolve(res);\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n}"]}
|