quar 1.2.0 → 1.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quar",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "This will load all Mongoose models from the folder and start a local web UI to Create, view, update, and delete documents.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -100,12 +100,9 @@ async function loadDocuments() {
100
100
  data.documents.forEach((doc, index) => {
101
101
  const wrapper = document.createElement('div');
102
102
  const divDocument = document.createElement('div');
103
- wrapper.innerHTML += `<div class="top-container"><button class="editDocument" onclick="toggleEditMode('${doc._id}')">Edit</button></div>`;
104
103
  divDocument.innerHTML += Object.entries(doc).map(([key, value]) => renderData(key, value, index)).join('');
105
- wrapper.innerHTML += `<textarea class="json-data hidden" id="${doc._id}-json-data" oninput="autoResize(this)">${JSON.stringify(doc, null, 2)}</textarea>`
106
104
 
107
105
  divDocument.classList.add('document');
108
- divDocument.id = `${doc._id}-html-data`;
109
106
 
110
107
  wrapper.appendChild(divDocument);
111
108
  wrapper.innerHTML += `<div class="document-actions"><button class="updateDocument" onclick="updateDocument(${index})">Update</button><button class="deleteDocument" onclick="deleteDoc('${modelName}', '${doc._id}')">Delete</button></div>`;
@@ -191,7 +188,6 @@ document.addEventListener('click', function (e) {
191
188
  function setNestedValue(obj, path, value, parentDataType) {
192
189
  const keys = path.split(".");
193
190
  let current = obj;
194
- console.log(value)
195
191
 
196
192
  keys.forEach((key, index) => {
197
193
  if (index === keys.length - 1) {
@@ -243,8 +239,6 @@ async function updateDocument(index) {
243
239
 
244
240
  updatedDoc = { ...updatedDoc, ...updatedDoc[""] }
245
241
 
246
- console.log(updatedDoc)
247
-
248
242
  const res = await fetch(`/update/${currentModelName}/${id}`, {
249
243
  method: "PUT",
250
244
  headers: { "Content-Type": "application/json" },
@@ -356,9 +350,4 @@ async function refreshSideBar() {
356
350
  } catch (error) {
357
351
  showModal('error', 'Error Occurred!', error.message || 'Something went wrong, please try again.');
358
352
  }
359
- }
360
-
361
- function autoResize(textarea) {
362
- textarea.style.height = 'auto'; // Reset the height
363
- textarea.style.height = textarea.scrollHeight + 'px'; // Set to scrollHeight
364
353
  }
package/server.js CHANGED
@@ -2,7 +2,7 @@ import express from 'express';
2
2
  import mongoose from 'mongoose';
3
3
  import path from "path"
4
4
  import loadModels from './utils/loadModels.js';
5
- import seedUsers from './seeds/user.seed.js';
5
+
6
6
  const app = express();
7
7
  const PORT = 8319;
8
8
 
@@ -1,71 +0,0 @@
1
- import mongoose from 'mongoose';
2
-
3
- const PlanetSchema = new mongoose.Schema({
4
- name: String,
5
- description: String,
6
- });
7
-
8
- const userSchema = new mongoose.Schema({
9
- // String types
10
- name: String,
11
- email: { type: String, required: true, unique: true },
12
- password: { type: String, required: true },
13
-
14
- // Number types
15
- age: Number,
16
- score: { type: Number, default: 0 },
17
-
18
- // Date types
19
- birthDate: Date,
20
- createdAt: { type: Date, default: Date.now },
21
-
22
- // Boolean type
23
- isActive: { type: Boolean, default: true },
24
-
25
- // Array types
26
- interests: [String],
27
- scores: [Number],
28
-
29
- planet: { type: PlanetSchema, required: true },
30
-
31
- // Nested object
32
- address: {
33
- street: String,
34
- city: String,
35
- country: String,
36
- zipCode: String
37
- },
38
-
39
- // ObjectId reference
40
- friends: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }],
41
-
42
- // Mixed type (any data)
43
- additionalInfo: mongoose.Schema.Types.Mixed,
44
-
45
- // Buffer type (for binary data)
46
- profilePicture: Buffer,
47
-
48
- // Map type
49
- metadata: {
50
- type: Map,
51
- of: String
52
- }
53
- });
54
-
55
- // Add indexes
56
- userSchema.index({ email: 1 });
57
- userSchema.index({ name: 1, age: -1 });
58
-
59
- // Add a virtual property
60
- userSchema.virtual('fullName').get(function () {
61
- return `${this.firstName} ${this.lastName}`;
62
- });
63
-
64
- // Add an instance method
65
- userSchema.methods.getAge = function () {
66
- return Math.floor((Date.now() - this.birthDate.getTime()) / 31557600000);
67
- };
68
-
69
- const User = mongoose.model('User', userSchema);
70
-
71
- export default User;
@@ -1,68 +0,0 @@
1
- import User from '../models/user.model.js';
2
-
3
- ;(async function seedUsers() {
4
- try {
5
- // Clear existing users
6
- await User.deleteMany({});
7
-
8
- // Create two users
9
- const user1 = await User.create({
10
- firstName: 'John',
11
- lastName: 'Doe',
12
- email: 'john.doe@example.com',
13
- password: 'password123',
14
- birthDate: new Date('1990-01-15'),
15
- isActive: true,
16
- interests: ['reading', 'hiking', 'photography'],
17
- scores: [85, 92, 78],
18
- planet: {
19
- name: 'Earth',
20
- description: 'Our home planet'
21
- },
22
- address: {
23
- street: '123 Main St',
24
- city: 'Boston',
25
- country: 'USA',
26
- zipCode: '02108'
27
- },
28
- metadata: new Map([
29
- ['occupation', 'Software Engineer'],
30
- ['department', 'Engineering']
31
- ])
32
- });
33
-
34
- const user2 = await User.create({
35
- firstName: 'Jane',
36
- lastName: 'Smith',
37
- email: 'jane.smith@example.com',
38
- password: 'password456',
39
- birthDate: new Date('1988-06-22'),
40
- isActive: true,
41
- interests: ['painting', 'music', 'travel'],
42
- scores: [95, 88, 90],
43
- planet: {
44
- name: 'Mars',
45
- description: 'The red planet'
46
- },
47
- address: {
48
- street: '456 Park Ave',
49
- city: 'New York',
50
- country: 'USA',
51
- zipCode: '10022'
52
- },
53
- metadata: new Map([
54
- ['occupation', 'Product Manager'],
55
- ['department', 'Product']
56
- ])
57
- });
58
-
59
- console.log('Users seeded successfully');
60
- return [user1, user2];
61
- } catch (error) {
62
- console.error('Error seeding users:', error);
63
- throw error;
64
- }
65
- })();
66
-
67
- export default 1;
68
-