@ozdao/prometheus-framework 0.2.82 → 0.2.83
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/credentials.schema-B-KD_ozQ.js +9 -0
- package/dist/credentials.schema-C9dmNy7o.mjs +10 -0
- package/dist/orders.server.js +592 -0
- package/dist/orders.server.mjs +593 -0
- package/dist/organizations.server.js +4 -3
- package/dist/organizations.server.mjs +2 -1
- package/dist/profile.schema-24ZpZQJe.mjs +25 -0
- package/dist/profile.schema-CkOhhf37.js +24 -0
- package/dist/prometheus-framework/src/modules/chats/components/blocks/ChatMessage.vue.cjs +1 -0
- package/dist/prometheus-framework/src/modules/chats/components/blocks/ChatMessage.vue.js +28 -0
- package/dist/prometheus-framework/src/modules/chats/components/pages/ChatPage.vue.cjs +1 -0
- package/dist/prometheus-framework/src/modules/chats/components/pages/ChatPage.vue.js +26 -0
- package/dist/prometheus-framework/src/modules/chats/components/pages/ChatPage.vue2.cjs +1 -0
- package/dist/prometheus-framework/src/modules/chats/components/pages/ChatPage.vue2.js +1 -0
- package/dist/prometheus-framework/src/modules/chats/components/sections/ChatWindow.vue.cjs +1 -0
- package/dist/prometheus-framework/src/modules/chats/components/sections/ChatWindow.vue.js +77 -0
- package/dist/prometheus-framework/src/modules/chats/components/sections/ChatWindow.vue2.cjs +1 -0
- package/dist/prometheus-framework/src/modules/chats/components/sections/ChatWindow.vue2.js +1 -0
- package/dist/prometheus-framework/src/modules/chats/store/chat.store.cjs +1 -0
- package/dist/prometheus-framework/src/modules/chats/store/chat.store.js +40 -0
- package/dist/prometheus-framework/src/modules/community/components/pages/CreateBlogPost.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/community/components/pages/CreateBlogPost.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/constructor/components/elements/Textarea.vue.cjs +1 -5
- package/dist/prometheus-framework/src/modules/constructor/components/elements/Textarea.vue.js +0 -66
- package/dist/prometheus-framework/src/modules/constructor/components/elements/Textarea.vue2.cjs +5 -1
- package/dist/prometheus-framework/src/modules/constructor/components/elements/Textarea.vue2.js +66 -0
- package/dist/prometheus-framework/src/modules/constructor/components/sections/Constructor.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/constructor/components/sections/Constructor.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/events/components/pages/EditEvent.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/events/components/pages/EditEvent.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/icons/navigation/IconCheckmark.vue.cjs +1 -0
- package/dist/prometheus-framework/src/modules/icons/navigation/IconCheckmark.vue.js +29 -0
- package/dist/prometheus-framework/src/modules/icons/placeholders/PlaceholderChat.vue.cjs +1 -0
- package/dist/prometheus-framework/src/modules/icons/placeholders/PlaceholderChat.vue.js +30 -0
- package/dist/prometheus-framework/src/modules/orders/components/blocks/CardOrder.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/orders/components/blocks/CardOrder.vue.js +121 -1
- package/dist/prometheus-framework/src/modules/orders/components/blocks/CardOrder.vue2.cjs +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/blocks/CardOrder.vue2.js +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/blocks/StatusHistory.vue.cjs +3 -0
- package/dist/prometheus-framework/src/modules/orders/components/blocks/StatusHistory.vue.js +92 -0
- package/dist/prometheus-framework/src/modules/orders/components/pages/Order.vue.cjs +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/pages/Order.vue.js +202 -0
- package/dist/prometheus-framework/src/modules/orders/components/pages/Order.vue2.cjs +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/pages/Order.vue2.js +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/pages/OrderCreate.vue.cjs +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/pages/OrderCreate.vue.js +127 -0
- package/dist/prometheus-framework/src/modules/orders/components/pages/OrderCreate.vue2.cjs +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/pages/OrderCreate.vue2.js +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/pages/Orders.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/orders/components/pages/Orders.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/orders/components/partials/ShopCart.vue.cjs +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/partials/ShopCart.vue.js +89 -0
- package/dist/prometheus-framework/src/modules/orders/components/partials/ShopCart.vue2.cjs +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/partials/ShopCart.vue2.js +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/sections/AskToLogin.vue.cjs +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/sections/AskToLogin.vue.js +24 -0
- package/dist/prometheus-framework/src/modules/orders/components/sections/EmptyState.vue.cjs +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/sections/EmptyState.vue.js +13 -0
- package/dist/prometheus-framework/src/modules/orders/components/sections/Succes.vue.cjs +1 -0
- package/dist/prometheus-framework/src/modules/orders/components/sections/Succes.vue.js +25 -0
- package/dist/prometheus-framework/src/modules/orders/orders.client.cjs +1 -0
- package/dist/prometheus-framework/src/modules/orders/orders.client.js +56 -0
- package/dist/prometheus-framework/src/modules/orders/router/orders.router.cjs +1 -0
- package/dist/prometheus-framework/src/modules/orders/router/orders.router.js +58 -0
- package/dist/prometheus-framework/src/modules/orders/store/shopcart.cjs +1 -1
- package/dist/prometheus-framework/src/modules/orders/store/shopcart.js +5 -1
- package/dist/style.css +1 -1
- package/dist/users.server.js +7 -27
- package/dist/users.server.mjs +5 -25
- package/package.json +1 -1
- package/src/modules/chats/components/blocks/ChatMessage.vue +1 -1
- package/src/modules/orders/models/application.model.js +25 -25
- package/src/modules/orders/models/testimonial.model.js +22 -23
- package/src/modules/orders/orders.server.js +4 -0
@@ -0,0 +1,592 @@
|
|
1
|
+
"use strict";
|
2
|
+
const _commonjsHelpers = require("./_commonjsHelpers-DHfMLFPC.js");
|
3
|
+
const ownership_schema = require("./ownership.schema-DN0SlQL6.js");
|
4
|
+
const profile_schema = require("./profile.schema-CkOhhf37.js");
|
5
|
+
const credentials_schema = require("./credentials.schema-B-KD_ozQ.js");
|
6
|
+
const mailing = require("./mailing-BX0q8DIs.js");
|
7
|
+
const queryProcessor = require("./queryProcessor-DRMo_GWK.js");
|
8
|
+
const index = require("./index-BCCiEK_u.js");
|
9
|
+
const require$$0 = require("node-cache");
|
10
|
+
const applyOwnershipSchema$1 = ownership_schema.ownership_schema;
|
11
|
+
var order_model = (db) => {
|
12
|
+
const OrderSchema = new db.mongoose.Schema({
|
13
|
+
customer: {
|
14
|
+
type: {
|
15
|
+
type: String,
|
16
|
+
required: true
|
17
|
+
},
|
18
|
+
target: {
|
19
|
+
type: db.mongoose.Schema.Types.ObjectId,
|
20
|
+
refPath: "customer.type",
|
21
|
+
required: true
|
22
|
+
}
|
23
|
+
},
|
24
|
+
positions: {
|
25
|
+
type: Array
|
26
|
+
},
|
27
|
+
referralCode: {
|
28
|
+
type: String
|
29
|
+
},
|
30
|
+
status: {
|
31
|
+
type: String
|
32
|
+
},
|
33
|
+
status_history: [{
|
34
|
+
status: {
|
35
|
+
type: String,
|
36
|
+
trim: true
|
37
|
+
},
|
38
|
+
changedBy: {
|
39
|
+
type: db.mongoose.Schema.Types.ObjectId,
|
40
|
+
ref: "User"
|
41
|
+
},
|
42
|
+
timestamp: {
|
43
|
+
type: Date,
|
44
|
+
default: Date.now
|
45
|
+
},
|
46
|
+
comment: {
|
47
|
+
type: String,
|
48
|
+
trim: true
|
49
|
+
}
|
50
|
+
}],
|
51
|
+
comment: {
|
52
|
+
type: String,
|
53
|
+
trim: true
|
54
|
+
},
|
55
|
+
payment: {
|
56
|
+
type: {
|
57
|
+
type: String,
|
58
|
+
trim: true
|
59
|
+
},
|
60
|
+
status: {
|
61
|
+
type: String,
|
62
|
+
trim: true
|
63
|
+
}
|
64
|
+
},
|
65
|
+
delivery: {
|
66
|
+
type: {
|
67
|
+
type: String,
|
68
|
+
trim: true
|
69
|
+
},
|
70
|
+
address: {
|
71
|
+
type: String,
|
72
|
+
trim: true
|
73
|
+
},
|
74
|
+
status: {
|
75
|
+
type: String,
|
76
|
+
trim: true
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}, {
|
80
|
+
timestamps: {
|
81
|
+
currentTime: () => Date.now()
|
82
|
+
}
|
83
|
+
});
|
84
|
+
applyOwnershipSchema$1(OrderSchema, db);
|
85
|
+
const Order = db.mongoose.model("Order", OrderSchema);
|
86
|
+
return Order;
|
87
|
+
};
|
88
|
+
const applyOwnershipSchema = ownership_schema.ownership_schema;
|
89
|
+
const applyProfileSchema = profile_schema.profile_schema;
|
90
|
+
const applyCredentialsSchema = credentials_schema.credentials_schema;
|
91
|
+
var customer_model = (db) => {
|
92
|
+
const CustomerSchema = new db.mongoose.Schema({
|
93
|
+
identity: {
|
94
|
+
type: {
|
95
|
+
type: String,
|
96
|
+
enum: ["Visitor", "User", "Organization"],
|
97
|
+
required: true
|
98
|
+
},
|
99
|
+
target: {
|
100
|
+
type: db.mongoose.Schema.Types.ObjectId,
|
101
|
+
refPath: "target.type"
|
102
|
+
}
|
103
|
+
},
|
104
|
+
referral: {
|
105
|
+
code: {
|
106
|
+
type: String
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}, {
|
110
|
+
timestamps: {
|
111
|
+
currentTime: () => Date.now()
|
112
|
+
}
|
113
|
+
});
|
114
|
+
applyCredentialsSchema(CustomerSchema);
|
115
|
+
applyProfileSchema(CustomerSchema);
|
116
|
+
applyOwnershipSchema(CustomerSchema, db);
|
117
|
+
CustomerSchema.index({
|
118
|
+
owner: 1,
|
119
|
+
email: 1
|
120
|
+
}, {
|
121
|
+
unique: true,
|
122
|
+
partialFilterExpression: {
|
123
|
+
email: { $exists: true, $ne: "" }
|
124
|
+
}
|
125
|
+
});
|
126
|
+
CustomerSchema.index({
|
127
|
+
owner: 1,
|
128
|
+
phone: 1
|
129
|
+
}, {
|
130
|
+
unique: true,
|
131
|
+
partialFilterExpression: {
|
132
|
+
phone: { $exists: true, $ne: "" }
|
133
|
+
}
|
134
|
+
});
|
135
|
+
CustomerSchema.index({
|
136
|
+
owner: 1,
|
137
|
+
identity: 1
|
138
|
+
}, {
|
139
|
+
unique: true,
|
140
|
+
partialFilterExpression: {
|
141
|
+
identity: { $exists: true, $ne: "" }
|
142
|
+
}
|
143
|
+
});
|
144
|
+
const Customer = db.mongoose.model("Customer", CustomerSchema);
|
145
|
+
return Customer;
|
146
|
+
};
|
147
|
+
var testimonial_model = (db) => {
|
148
|
+
const testimonialSchema = new db.mongoose.Schema({
|
149
|
+
source: {
|
150
|
+
type: String
|
151
|
+
},
|
152
|
+
author: {
|
153
|
+
type: Schema.Types.ObjectId,
|
154
|
+
ref: "User",
|
155
|
+
required: true
|
156
|
+
},
|
157
|
+
rating: {
|
158
|
+
type: String,
|
159
|
+
required: true
|
160
|
+
},
|
161
|
+
description: {
|
162
|
+
type: String,
|
163
|
+
required: true
|
164
|
+
}
|
165
|
+
});
|
166
|
+
const Testimonial = db.mongoose.model("Testimonial", testimonialSchema);
|
167
|
+
return Testimonial;
|
168
|
+
};
|
169
|
+
var application_model = (db) => {
|
170
|
+
const ApplicationSchema = new db.mongoose.Schema({
|
171
|
+
status: {
|
172
|
+
type: String,
|
173
|
+
default: "created"
|
174
|
+
},
|
175
|
+
type: {
|
176
|
+
type: String,
|
177
|
+
default: "newsletter"
|
178
|
+
},
|
179
|
+
contacts: {
|
180
|
+
name: {
|
181
|
+
type: String
|
182
|
+
},
|
183
|
+
phone: {
|
184
|
+
type: String
|
185
|
+
},
|
186
|
+
email: {
|
187
|
+
type: String
|
188
|
+
}
|
189
|
+
}
|
190
|
+
}, {
|
191
|
+
timestamps: { currentTime: () => Date.now() }
|
192
|
+
});
|
193
|
+
const Application = db.mongoose.model("Application", ApplicationSchema);
|
194
|
+
return Application;
|
195
|
+
};
|
196
|
+
const { sendChatMessageTelegram } = mailing.mailing;
|
197
|
+
const queryProcessorGlobals = queryProcessor.queryProcessor;
|
198
|
+
function formatPositions(positions) {
|
199
|
+
return positions.map((pos) => `🔹 ${pos.name} - Price: $${pos.price}, Quantity: ${pos.quantity}`).join("\n");
|
200
|
+
}
|
201
|
+
function formatOrderMessage(order) {
|
202
|
+
return `
|
203
|
+
🆕 New Order Received!
|
204
|
+
👤 Customer: ${order.customer?.name} (${order.customer?.phone?.number ? order.customer?.phone?.number : "No phone"})
|
205
|
+
💬 Messenger: ${order.customer?.messenger ? order.customer?.messenger?.type + " " + order.customer?.messenger?.value : "None"}
|
206
|
+
🏢 Organization: ${order.organization}
|
207
|
+
📦 Positions:
|
208
|
+
${formatPositions(order.positions)}
|
209
|
+
📝 Comment: ${order.comment ? order.comment : "No comment"}
|
210
|
+
💳 Payment: ${order.payment?.type}
|
211
|
+
🚚 Delivery: ${order.delivery?.type} to ${order.delivery?.address}
|
212
|
+
📌 Status: ${order.status}
|
213
|
+
🧑 Agent: ${order.referralCode}
|
214
|
+
`;
|
215
|
+
}
|
216
|
+
function initializeOrder(orderData, userId) {
|
217
|
+
orderData.status = "created";
|
218
|
+
orderData.status_history = orderData.status_history || [];
|
219
|
+
orderData.status_history.push({
|
220
|
+
status: orderData.status,
|
221
|
+
changedBy: userId,
|
222
|
+
timestamp: /* @__PURE__ */ new Date(),
|
223
|
+
comment: ""
|
224
|
+
});
|
225
|
+
}
|
226
|
+
async function findOrCreateCustomer(Customer, customerInfo, orderOwner, visitor) {
|
227
|
+
let searchCriteria = {};
|
228
|
+
if (customerInfo.phone) {
|
229
|
+
searchCriteria.phone = customerInfo.phone;
|
230
|
+
}
|
231
|
+
if (customerInfo.email) {
|
232
|
+
searchCriteria.email = customerInfo.email;
|
233
|
+
}
|
234
|
+
let customer = null;
|
235
|
+
if (Object.keys(searchCriteria).length > 0) {
|
236
|
+
customer = await Customer.findOne({ $or: [searchCriteria] });
|
237
|
+
}
|
238
|
+
if (!customer) {
|
239
|
+
const newCustomerData = {
|
240
|
+
...customerInfo,
|
241
|
+
owner: orderOwner,
|
242
|
+
creator: customerInfo.creator || { type: "Visitor", target: visitor || orderOwner.target },
|
243
|
+
identity: customerInfo.indentity || { type: "Visitor", target: visitor || orderOwner.target }
|
244
|
+
};
|
245
|
+
customer = await Customer.create(newCustomerData);
|
246
|
+
}
|
247
|
+
return customer;
|
248
|
+
}
|
249
|
+
async function sendOrderMessage(orderData) {
|
250
|
+
try {
|
251
|
+
const formattedMessage = formatOrderMessage(orderData);
|
252
|
+
await sendChatMessageTelegram(process.env.TELEGRAM_BOT_USERS.split(","), formattedMessage);
|
253
|
+
} catch (err) {
|
254
|
+
console.error(err);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
const controllerFactory$1 = (db) => {
|
258
|
+
const Order = db.order;
|
259
|
+
const Customer = db.customer;
|
260
|
+
const create = async (req, res) => {
|
261
|
+
const orderData = req.body;
|
262
|
+
const userId = req.userId;
|
263
|
+
initializeOrder(orderData, userId);
|
264
|
+
try {
|
265
|
+
if (!orderData.customer.target) {
|
266
|
+
let customer = await findOrCreateCustomer(Customer, orderData.customer, orderData.owner, orderData.visitor);
|
267
|
+
orderData.customer = { type: "Customer", target: customer._id };
|
268
|
+
if (!orderData.creator?.target) {
|
269
|
+
orderData.creator = { type: "Customer", target: customer._id };
|
270
|
+
}
|
271
|
+
}
|
272
|
+
await sendOrderMessage(orderData);
|
273
|
+
const order = await Order.create(orderData);
|
274
|
+
res.status(201).send(order);
|
275
|
+
} catch (err) {
|
276
|
+
console.error(err);
|
277
|
+
res.status(500).send({ errorCode: "CREATE_ORDER_FAILED", message: "Error occurred while creating the order.", error: err });
|
278
|
+
}
|
279
|
+
};
|
280
|
+
const read = async (req, res) => {
|
281
|
+
stages = [
|
282
|
+
...queryProcessorGlobals.getBasicOptions(
|
283
|
+
req.query
|
284
|
+
),
|
285
|
+
// For customer
|
286
|
+
{
|
287
|
+
$lookup: {
|
288
|
+
from: "customers",
|
289
|
+
localField: "customer.target",
|
290
|
+
foreignField: "_id",
|
291
|
+
as: "customerTarget"
|
292
|
+
}
|
293
|
+
},
|
294
|
+
{
|
295
|
+
$addFields: {
|
296
|
+
"customer.target": { $arrayElemAt: ["$customerTarget", 0] }
|
297
|
+
}
|
298
|
+
},
|
299
|
+
// For creator
|
300
|
+
queryProcessorGlobals.getCreatorUserLookupStage(),
|
301
|
+
queryProcessorGlobals.getCreatorOrganizationLookupStage(),
|
302
|
+
queryProcessorGlobals.getCreatorCustomerLookupStage(),
|
303
|
+
// For owner
|
304
|
+
queryProcessorGlobals.getOwnerUserLookupStage(),
|
305
|
+
queryProcessorGlobals.getOwnerOrganizationLookupStage(),
|
306
|
+
queryProcessorGlobals.getAddFieldsCreatorOwnerStage(),
|
307
|
+
// Pagination
|
308
|
+
...queryProcessorGlobals.getSortingOptions(
|
309
|
+
req.query.sortParam,
|
310
|
+
req.query.sortOrder
|
311
|
+
),
|
312
|
+
...queryProcessorGlobals.getPaginationOptions(
|
313
|
+
req.query.skip,
|
314
|
+
req.query.limit
|
315
|
+
)
|
316
|
+
];
|
317
|
+
try {
|
318
|
+
const orders = await Order.aggregate(stages);
|
319
|
+
if (!orders) {
|
320
|
+
return res.status(404).send({ errorCode: "ORDER_NOT_FOUND", message: "Orders not found." });
|
321
|
+
}
|
322
|
+
res.status(200).send(orders);
|
323
|
+
} catch (err) {
|
324
|
+
console.log(err);
|
325
|
+
res.status(500).send({ errorCode: "GET_ORDERS_FAILED", message: "Error occurred while fetching orders.", error: err });
|
326
|
+
}
|
327
|
+
};
|
328
|
+
const update = async (req, res) => {
|
329
|
+
const order = await Order.findById(new db.mongoose.Schema.Types.ObjectId(req.body._id));
|
330
|
+
if (!order) {
|
331
|
+
return res.status(404).send({ errorCode: "ORDER_NOT_FOUND", message: "Order not found." });
|
332
|
+
}
|
333
|
+
if (req.body.status && req.body.status !== order.status) {
|
334
|
+
order.status = req.body.status;
|
335
|
+
order.status_history.push({
|
336
|
+
status: req.body.status,
|
337
|
+
changedBy: req.userId,
|
338
|
+
timestamp: /* @__PURE__ */ new Date(),
|
339
|
+
comment: ""
|
340
|
+
});
|
341
|
+
}
|
342
|
+
try {
|
343
|
+
await order.save();
|
344
|
+
res.status(200).send(order);
|
345
|
+
} catch (err) {
|
346
|
+
res.status(500).send({ errorCode: "UPDATE_ORDER_FAILED", message: "Error occurred while updating the order.", error: err });
|
347
|
+
}
|
348
|
+
};
|
349
|
+
const changePaymentStatus = async (req, res) => {
|
350
|
+
try {
|
351
|
+
const order = await Order.findOneAndUpdate(
|
352
|
+
{ _id: req.params._id },
|
353
|
+
{ status: "Оплачен", payment: { type: "Наличные", status: "Оплачено" } },
|
354
|
+
{ new: true }
|
355
|
+
).exec();
|
356
|
+
if (!order) {
|
357
|
+
return res.status(404).send({ errorCode: "PAYMENT_STATUS_CHANGE_FAILED", message: "Failed to change the payment status." });
|
358
|
+
}
|
359
|
+
res.status(200).send(order);
|
360
|
+
} catch (err) {
|
361
|
+
res.status(500).send({ errorCode: "CHANGE_PAYMENT_STATUS_FAILED", message: "Error occurred while changing the payment status.", error: err });
|
362
|
+
}
|
363
|
+
};
|
364
|
+
const deleteOrder = async (req, res) => {
|
365
|
+
try {
|
366
|
+
const order = await Order.findOneAndDelete({ _id: req.params._id }).exec();
|
367
|
+
if (!order) {
|
368
|
+
return res.status(404).send({ errorCode: "ORDER_DELETE_FAILED", message: "Failed to delete the order." });
|
369
|
+
}
|
370
|
+
res.status(200).send(order);
|
371
|
+
} catch (err) {
|
372
|
+
res.status(500).send({ errorCode: "DELETE_ORDER_FAILED", message: "Error occurred while deleting the order.", error: err });
|
373
|
+
}
|
374
|
+
};
|
375
|
+
return {
|
376
|
+
create,
|
377
|
+
read,
|
378
|
+
update,
|
379
|
+
changePaymentStatus,
|
380
|
+
deleteOrder
|
381
|
+
};
|
382
|
+
};
|
383
|
+
var orders_controller = controllerFactory$1;
|
384
|
+
const controllerFactory = orders_controller;
|
385
|
+
const middlewareFactory = index.server;
|
386
|
+
var orders_routes = function(app, db, origins, publicPath) {
|
387
|
+
const controller = controllerFactory(db);
|
388
|
+
const middleware = middlewareFactory(db);
|
389
|
+
app.post(
|
390
|
+
"/api/orders/create",
|
391
|
+
controller.create
|
392
|
+
);
|
393
|
+
app.get(
|
394
|
+
"/api/orders/read",
|
395
|
+
controller.read
|
396
|
+
);
|
397
|
+
app.post(
|
398
|
+
"/api/orders/update",
|
399
|
+
[
|
400
|
+
middleware.authJwt.verifyToken
|
401
|
+
],
|
402
|
+
controller.update
|
403
|
+
);
|
404
|
+
app.post(
|
405
|
+
"/api/orders/delete",
|
406
|
+
controller.deleteOrder
|
407
|
+
);
|
408
|
+
};
|
409
|
+
const NodeCache = require$$0;
|
410
|
+
const stdTTL = 60 * 5;
|
411
|
+
class Cache {
|
412
|
+
constructor(ttlSeconds = stdTTL) {
|
413
|
+
this.cache = new NodeCache({ stdTTL: ttlSeconds });
|
414
|
+
}
|
415
|
+
async get(key) {
|
416
|
+
return this.cache.get(key);
|
417
|
+
}
|
418
|
+
async set(key, value) {
|
419
|
+
return this.cache.set(key, value);
|
420
|
+
}
|
421
|
+
async del(keys) {
|
422
|
+
return this.cache.del(keys);
|
423
|
+
}
|
424
|
+
async flush() {
|
425
|
+
this.cache.flushAll();
|
426
|
+
}
|
427
|
+
}
|
428
|
+
var globals_cashe = Cache;
|
429
|
+
let Logger$1 = class Logger {
|
430
|
+
static logModel = null;
|
431
|
+
constructor(db) {
|
432
|
+
if (!Logger.logModel) {
|
433
|
+
const logSchema = new db.mongoose.Schema({
|
434
|
+
timestamp: { type: Date, default: Date.now },
|
435
|
+
level: String,
|
436
|
+
message: String
|
437
|
+
}, { versionKey: false });
|
438
|
+
Logger.logModel = db.mongoose.model("Log", logSchema);
|
439
|
+
}
|
440
|
+
this.LogModel = Logger.logModel;
|
441
|
+
}
|
442
|
+
async log(level, message) {
|
443
|
+
const logEntry = new Logger.logModel({
|
444
|
+
level,
|
445
|
+
message
|
446
|
+
});
|
447
|
+
try {
|
448
|
+
await logEntry.save();
|
449
|
+
console.info(`Logged: ${level} - ${message}`);
|
450
|
+
} catch (err) {
|
451
|
+
console.error("Logging error:", err);
|
452
|
+
}
|
453
|
+
}
|
454
|
+
// Удобные методы для различных уровней логирования
|
455
|
+
async info(message) {
|
456
|
+
await this.log("info", message);
|
457
|
+
}
|
458
|
+
async error(message) {
|
459
|
+
await this.log("error", message);
|
460
|
+
}
|
461
|
+
};
|
462
|
+
var globals_logger = Logger$1;
|
463
|
+
const globalsQuery = queryProcessor.queryProcessor;
|
464
|
+
const Cashe = globals_cashe;
|
465
|
+
const Logger2 = globals_logger;
|
466
|
+
let CRUD$1 = class CRUD {
|
467
|
+
constructor(basePath, app, db, model) {
|
468
|
+
this.model = model;
|
469
|
+
this.cache = new Cashe();
|
470
|
+
this.logger = new Logger2(db);
|
471
|
+
this.app = app;
|
472
|
+
this.basePath = basePath;
|
473
|
+
this.registerRoutes();
|
474
|
+
}
|
475
|
+
registerRoutes() {
|
476
|
+
this.app.post(`${this.basePath}/create`, this.create.bind(this));
|
477
|
+
this.app.get(`${this.basePath}/read`, this.read.bind(this));
|
478
|
+
this.app.put(`${this.basePath}/update`, this.update.bind(this));
|
479
|
+
this.app.delete(`${this.basePath}/delete`, this.delete.bind(this));
|
480
|
+
}
|
481
|
+
async create(req, res) {
|
482
|
+
try {
|
483
|
+
const createdData = await this.model.create(req.body);
|
484
|
+
await this.cache.flush();
|
485
|
+
res.status(201).json(createdData);
|
486
|
+
} catch (error) {
|
487
|
+
console.log(error);
|
488
|
+
this.logger.error("Ошибка создания данных", error);
|
489
|
+
res.status(500).json({ error: error.message });
|
490
|
+
}
|
491
|
+
}
|
492
|
+
async read(req, res) {
|
493
|
+
try {
|
494
|
+
let stages2 = [];
|
495
|
+
stages2 = [
|
496
|
+
...globalsQuery.getBasicOptions(
|
497
|
+
req.query
|
498
|
+
),
|
499
|
+
// For creator
|
500
|
+
globalsQuery.getCreatorUserLookupStage(),
|
501
|
+
globalsQuery.getCreatorOrganizationLookupStage(),
|
502
|
+
// For owner
|
503
|
+
globalsQuery.getOwnerUserLookupStage(),
|
504
|
+
globalsQuery.getOwnerOrganizationLookupStage(),
|
505
|
+
globalsQuery.getAddFieldsCreatorOwnerStage(),
|
506
|
+
// Pagination
|
507
|
+
...globalsQuery.getSortingOptions(
|
508
|
+
req.query.sortParam,
|
509
|
+
req.query.sortOrder
|
510
|
+
),
|
511
|
+
...globalsQuery.getPaginationOptions(
|
512
|
+
req.query.skip,
|
513
|
+
req.query.limit
|
514
|
+
),
|
515
|
+
globalsQuery.removeTempPropeties()
|
516
|
+
];
|
517
|
+
const cacheKey = JSON.stringify({ stages: stages2 });
|
518
|
+
let data = await this.cache.get(cacheKey);
|
519
|
+
if (!data) {
|
520
|
+
data = await this.model.aggregate(stages2).exec();
|
521
|
+
await this.cache.set(cacheKey, data);
|
522
|
+
}
|
523
|
+
res.json(data);
|
524
|
+
} catch (error) {
|
525
|
+
this.logger.error(error);
|
526
|
+
res.status(500).json({ error: error.message });
|
527
|
+
}
|
528
|
+
}
|
529
|
+
async update(req, res) {
|
530
|
+
try {
|
531
|
+
const updatedData = await this.model.findOneAndUpdate(
|
532
|
+
{ _id: req.body._id },
|
533
|
+
req.body,
|
534
|
+
{ new: true, runValidators: true }
|
535
|
+
);
|
536
|
+
if (!updatedData) {
|
537
|
+
throw new Error("Документ не найден.");
|
538
|
+
}
|
539
|
+
await this.cache.flush();
|
540
|
+
res.json(updatedData);
|
541
|
+
} catch (error) {
|
542
|
+
this.logger.error("Ошибка обновления данных", error);
|
543
|
+
res.status(404).json({ error: error.message });
|
544
|
+
}
|
545
|
+
}
|
546
|
+
async delete(req, res) {
|
547
|
+
try {
|
548
|
+
const deletedData = await this.model.findOneAndDelete({ _id: req.body._id });
|
549
|
+
if (!deletedData) {
|
550
|
+
throw new Error("Документ не найден.");
|
551
|
+
}
|
552
|
+
await this.cache.flush();
|
553
|
+
res.status(204).send();
|
554
|
+
} catch (error) {
|
555
|
+
this.logger.error("Ошибка удаления данных", error);
|
556
|
+
res.status(404).json({ error: error.message });
|
557
|
+
}
|
558
|
+
}
|
559
|
+
};
|
560
|
+
var globals_crud = CRUD$1;
|
561
|
+
const ModelOrder = order_model;
|
562
|
+
const ModelCustomer = customer_model;
|
563
|
+
const ModelTestimonial = testimonial_model;
|
564
|
+
const ModelApplication = application_model;
|
565
|
+
const RoutesOrder = orders_routes;
|
566
|
+
const FactoryOrder = orders_controller;
|
567
|
+
const CRUD2 = globals_crud;
|
568
|
+
function initializeOrders(app, db, origins, publicPath) {
|
569
|
+
db.order = ModelOrder(db);
|
570
|
+
db.customer = ModelCustomer(db);
|
571
|
+
db.testimonial = ModelTestimonial(db);
|
572
|
+
db.application = ModelApplication(db);
|
573
|
+
if (app) {
|
574
|
+
RoutesOrder(app, db);
|
575
|
+
}
|
576
|
+
new CRUD2("/api/customers", app, db, db.customer);
|
577
|
+
}
|
578
|
+
var orders_server = {
|
579
|
+
initialize: initializeOrders,
|
580
|
+
models: {
|
581
|
+
ModelOrder,
|
582
|
+
ModelCustomer
|
583
|
+
},
|
584
|
+
routes: {
|
585
|
+
RoutesOrder
|
586
|
+
},
|
587
|
+
controllers: {
|
588
|
+
FactoryOrder
|
589
|
+
}
|
590
|
+
};
|
591
|
+
const orders_server$1 = /* @__PURE__ */ _commonjsHelpers.getDefaultExportFromCjs(orders_server);
|
592
|
+
module.exports = orders_server$1;
|