@mongoosejs/studio 0.0.1 → 0.0.3

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.
Files changed (46) hide show
  1. package/backend/actions/Model/deleteDocument.js +31 -0
  2. package/backend/actions/Model/getDocument.js +11 -1
  3. package/backend/actions/Model/getDocuments.js +25 -4
  4. package/backend/actions/Model/index.js +1 -0
  5. package/backend/helpers/removeSpecifiedPaths.js +9 -0
  6. package/frontend/public/images/delete.svg +25 -0
  7. package/frontend/public/images/edit.svg +5 -0
  8. package/frontend/public/images/logo.svg +160 -0
  9. package/frontend/public/images/save.svg +21 -0
  10. package/frontend/public/images/success.png +0 -0
  11. package/frontend/public/index.html +1 -0
  12. package/frontend/public/style.css +38 -1
  13. package/frontend/public/vanillatoasts/vanillatoasts.css +125 -0
  14. package/frontend/src/api.js +6 -2
  15. package/frontend/src/document/document.css +4 -0
  16. package/frontend/src/document/document.html +6 -3
  17. package/frontend/src/document/document.js +25 -1
  18. package/frontend/src/edit-date/edit-date.html +3 -0
  19. package/frontend/src/edit-date/edit-date.js +9 -0
  20. package/frontend/src/edit-number/edit-number.html +3 -0
  21. package/frontend/src/edit-number/edit-number.js +20 -0
  22. package/frontend/src/export-query-results/export-query-results.js +6 -3
  23. package/frontend/src/index.js +3 -0
  24. package/frontend/src/list-default/list-default.css +0 -0
  25. package/frontend/src/list-default/list-default.html +6 -2
  26. package/frontend/src/list-default/list-default.js +30 -1
  27. package/frontend/src/list-string/list-string.css +4 -0
  28. package/frontend/src/list-string/list-string.html +4 -0
  29. package/frontend/src/list-string/list-string.js +43 -0
  30. package/frontend/src/list-subdocument/list-subdocument.html +1 -1
  31. package/frontend/src/list-subdocument/list-subdocument.js +4 -1
  32. package/frontend/src/modal/modal.css +8 -0
  33. package/frontend/src/models/models.css +8 -2
  34. package/frontend/src/models/models.html +11 -2
  35. package/frontend/src/models/models.js +40 -21
  36. package/frontend/src/navbar/navbar.css +3 -3
  37. package/frontend/src/navbar/navbar.html +2 -2
  38. package/mongoose.js +20 -0
  39. package/package.json +9 -7
  40. package/scripts/stratos.js +22 -0
  41. package/stargate.js +26 -0
  42. package/stratos.js +20 -0
  43. package/tv.js +20 -0
  44. package/zevo.js +20 -0
  45. package/frontend/public/app.js +0 -4012
  46. package/test.js +0 -264
package/test.js DELETED
@@ -1,264 +0,0 @@
1
- 'use strict';
2
-
3
- const express = require('express');
4
- const mongoose = require('mongoose');
5
-
6
- mongoose.connect('mongodb://localhost:27017/terravera_test');
7
-
8
- const cartItemSchema = new mongoose.Schema({
9
- _id: false,
10
- productId: { type: String, required: true },
11
- product: new mongoose.Schema({
12
- name: String,
13
- slug: String,
14
- price: Number,
15
- displayPrice: String,
16
- productDescription: String,
17
- color: String,
18
- image: String,
19
- suitableFor: [String],
20
- productLabel: String,
21
- sds: String,
22
- productLine: String,
23
- setupFee: Number,
24
- }),
25
- price: { type: Number, required: true },
26
- quantity: { type: Number, required: true },
27
- recurring: { type: String, enum: ['monthly'] },
28
- lease: { type: Boolean }
29
- });
30
-
31
- cartItemSchema.virtual('lineItemName').get(function lineItemName() {
32
- if (this.lease) {
33
- return `${this.product.name} (Lease)`;
34
- } else if (this.recurring) {
35
- const recurring = this.recurring.slice(0, 1).toUpperCase() + this.recurring.slice(1);
36
- return `${this.product.name} (${recurring})`;
37
- }
38
-
39
- return this.product.name;
40
- });
41
-
42
- const lineItemSchema = new mongoose.Schema({
43
- description: { type: String, required: true },
44
- price: { type: Number, required: true },
45
- quantity: { type: Number, required: true, min: 0 },
46
- total: {
47
- type: Number,
48
- required: true
49
- }, // price * quantity rounded to 2 decimal places
50
- waived: {
51
- type: Boolean,
52
- required: true,
53
- default: false
54
- },
55
- productId: {
56
- type: String
57
- },
58
- tags: [{
59
- type: String,
60
- enum: ['setup_fee', 'promo_code', 'sales_tax', 'lease']
61
- }]
62
- }, { id: false, toJSON: { virtuals: true }, toObject: { virtuals: true } });
63
-
64
- lineItemSchema.virtual('prettyTotal').get(function prettyTotal() {
65
- const total = this.total || 0;
66
- return this.total;
67
- });
68
-
69
- const cartSchema = new mongoose.Schema({
70
- items: [cartItemSchema],
71
- lineItems: [lineItemSchema],
72
- orderId: { type: mongoose.ObjectId, ref: 'Order' },
73
- stripePaymentIntentId: String,
74
- stripePaymentMethodId: String
75
- }, { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } });
76
-
77
- cartSchema.methods.applyPromoCode = function applyPromoCode(promoCode) {
78
- this.promoCodes.push(promoCode);
79
- if (promoCode.waivesTag != null) {
80
- for (const li of this.lineItems) {
81
- if (!li.tags.includes(promoCode.waivesTag)) {
82
- continue;
83
- }
84
- li.waived = true;
85
- }
86
- }
87
- if (promoCode.flatDiscount != null) {
88
- this.lineItems.push({
89
- description: promoCode.code,
90
- price: -promoCode.flatDiscount,
91
- quantity: 1,
92
- total: -promoCode.flatDiscount,
93
- tags: ['promo_code']
94
- });
95
- }
96
- if (promoCode.percentDiscount != null) {
97
- if (promoCode.discountOnProductIds != null) {
98
- const lineItems = this.lineItems.filter((li) => {
99
- if (promoCode.leaseOnly) {
100
- return promoCode.discountOnProductIds.indexOf(li.productId) > -1 && li.tags.includes('lease');
101
- }
102
- if (promoCode.purchaseOnly) {
103
- return promoCode.discountOnProductIds.indexOf(li.productId) > -1 && !li.tags.includes('lease');
104
- }
105
- return promoCode.discountOnProductIds.indexOf(li.productId) > -1;
106
- });
107
- if (lineItems.length) {
108
- for(let i = 0; i < lineItems.length; i++) {
109
- this.lineItems.push({
110
- description: promoCode.code,
111
- price: -(lineItems[i].total * promoCode.percentDiscount / 100).toFixed(2),
112
- quantity: 1,
113
- total: -(lineItems[i].total * promoCode.percentDiscount / 100).toFixed(2),
114
- tags: ['promo_code']
115
- });
116
- }
117
- }
118
- } else {
119
- this.lineItems.push({
120
- description: promoCode.code,
121
- price: -(this.totalWithoutTax * promoCode.percentDiscount / 100).toFixed(2),
122
- quantity: 1,
123
- total: -(this.totalWithoutTax * promoCode.percentDiscount / 100).toFixed(2),
124
- tags: ['promo_code']
125
- });
126
- }
127
- }
128
- if (promoCode.waivesProductsExceptIds != null && promoCode.waivesProductsExceptIds.length > 0) {
129
- let numWaived = 0;
130
-
131
- const promoCodeLineItem = {
132
- description: promoCode.code,
133
- price: 0,
134
- quantity: 1,
135
- total: 0,
136
- tags: ['promo_code']
137
- };
138
-
139
- for (const li of this.lineItems) {
140
- if (li.productId && !promoCode.waivesProductsExceptIds.includes(li.productId)) {
141
- const quantityToWaive = promoCode.maxWaivedProducts == null ?
142
- li.quantity :
143
- Math.min(promoCode.maxWaivedProducts - numWaived, li.quantity);
144
- const discount = +(li.price * quantityToWaive).toFixed(2);
145
- promoCodeLineItem.price = +(promoCodeLineItem.price - discount).toFixed(2);
146
- promoCodeLineItem.total = promoCodeLineItem.price;
147
- numWaived += quantityToWaive;
148
- }
149
- if (promoCode.maxWaivedProducts != null && numWaived >= promoCode.maxWaivedProducts) {
150
- break;
151
- }
152
- }
153
-
154
- if (promoCodeLineItem.total !== 0) {
155
- this.lineItems.push(promoCodeLineItem);
156
- }
157
- }
158
- };
159
-
160
- cartSchema.pre('save', function sortLineItems() {
161
- this.lineItems.sort((li1, li2) => {
162
- if (li1.productId != null && li2.productId == null) {
163
- return -1;
164
- }
165
- if (li1.productId == null && li2.productId != null) {
166
- return 1;
167
- }
168
- return 0;
169
- });
170
- });
171
-
172
- cartSchema.virtual('subtotal').get(function subtotal() {
173
- return this.lineItems.
174
- filter(li => li.productId != null).
175
- filter(li => !li.waived).
176
- reduce((sum, li) => {
177
- return +(sum + li.total).toFixed(2);
178
- }, 0);
179
- });
180
-
181
- cartSchema.virtual('promoDiscount').get(function promoDiscount() {
182
- return this.lineItems.
183
- filter(li => li.tags.includes('promo_code')).
184
- reduce((sum, li) => {
185
- return +(sum + li.total).toFixed(2);
186
- }, 0);
187
- });
188
-
189
- cartSchema.virtual('setupFee').get(function setupFee() {
190
- return this.lineItems.
191
- filter(li => li.tags.includes('setup_fee')).
192
- filter(li => !li.waived).
193
- reduce((total, li) => {
194
- return +(total + (li.total)).toFixed(2);
195
- }, 0);
196
- });
197
-
198
- cartSchema.virtual('salesTax').
199
- get(function salesTax() {
200
- return this.lineItems.
201
- filter(li => li.tags.includes('sales_tax')).
202
- filter(li => !li.waived).
203
- reduce((total, li) => {
204
- return +(total + (li.total)).toFixed(2);
205
- }, 0);
206
- }).
207
- set(function updateSalesTax(v) {
208
- const index = this.lineItems.findIndex(li => li.tags.includes('sales_tax'));
209
- if (index === -1) {
210
- this.lineItems.push({
211
- description: 'Sales Tax',
212
- price: v,
213
- total: v,
214
- quantity: 1,
215
- tags: ['sales_tax']
216
- });
217
- } else {
218
- this.lineItems[index].price = v;
219
- this.lineItems[index].total = v;
220
- this.lineItems[index].quantity = 1;
221
- }
222
- });
223
-
224
- cartSchema.virtual('totalWithoutTax').get(function totalWithoutTax() {
225
- const promoDiscount = this.promoDiscount || 0;
226
- const setupFee = this.setupFee || 0;
227
- return +(this.subtotal + promoDiscount + setupFee).toFixed(2);
228
- });
229
-
230
- cartSchema.virtual('total').get(function total() {
231
- const salesTax = this.salesTax || 0;
232
- return +(this.totalWithoutTax + salesTax).toFixed(2);
233
- });
234
-
235
- cartSchema.virtual('salesTaxLineItem').get(function salesTaxLineItem() {
236
- return this.lineItems.find(li => li.tags.includes('sales_tax'));
237
- });
238
-
239
- cartSchema.virtual('subtotalLineItem').get(function subtotalLineItem() {
240
- return {
241
- description: 'Subtotal',
242
- price: this.subtotal,
243
- quantity: 1,
244
- total: this.subtotal
245
- };
246
- });
247
-
248
- cartSchema.virtual('promoCodeLineItems').get(function promoCodeLineItems() {
249
- return this.lineItems.filter(li => li.tags.includes('promo_code'));
250
- });
251
-
252
- cartSchema.virtual('setupFeeLineItems').get(function setupFeeLineItems() {
253
- return this.lineItems.filter(li => li.tags.includes('setup_fee'));
254
- });
255
-
256
- const Cart = mongoose.model('Cart', cartSchema);
257
-
258
- module.exports = Cart;
259
-
260
- const app = express();
261
- app.use('/admin', require('./express')('/admin/api', null, { watch: true }));
262
-
263
- app.listen(5005);
264
- console.log('Listening on 5005');