Ivan Asmer 4 年 前
コミット
d259c84e3e
3 ファイル変更27 行追加50 行削除
  1. 1 0
      index.js
  2. 19 9
      models.js
  3. 7 41
      package-lock.json

+ 1 - 0
index.js

@@ -150,6 +150,7 @@ const upload  = require('multer')({ dest: uploadPath })
 
     app.post('/upload', upload.single('photo'), async (req, res, next) => {
         let decoded;
+        console.log('wtf')
         if (decoded = jwtCheck(req, jwtSecret)){
             console.log('SOME UPLOAD', decoded, req.file)
 

+ 19 - 9
models.js

@@ -46,20 +46,21 @@ module.exports = async (dbName='hipstagram') => {
                 //TODO: calc likes count by getter (no two-way relation for this to avoid overflow on many Kilos of likes
                 //cached like count, which incremented and decremented
                 //
-                //
 
-                this.comments = this.comments instanceof Array ? 
-                                                this.comments  : this.comments ? [] : [this.comments]
             }
 
             static get relations(){
                 return {
-                    images: "posts",
+                    images: ["posts"],
                     comments: "post",
                     directs: "post",
-                    collections: "posts"
+                    collections: ["posts"]
                 }
             }
+
+            static get guestRelations(){
+                return ["comments", "directs"]
+            }
         }
         SlicedSavable.addClass(Post)
 
@@ -90,10 +91,11 @@ module.exports = async (dbName='hipstagram') => {
             static get relations(){
                 return {
                     userAvatar: "avatar", //if it is ava
-                    posts: "images",      //if in post: m2m with posts
+                    posts: ["images"],      //if in post: m2m with posts
                     directs: "image",     //if in direct: m2o with directs
                 }
             }
+
         }
         SlicedSavable.addClass(Image)
 
@@ -106,11 +108,15 @@ module.exports = async (dbName='hipstagram') => {
 
             static get relations(){
                 return {
-                    post: "comments",
+                    post: ["comments"],
                     answers: "answerTo",
-                    answerTo: "answers",
+                    answerTo: ["answers"],
                 }
             }
+
+            static get guestRelations(){
+                return ["answers"]
+            }
         }
         SlicedSavable.addClass(Comment)
 
@@ -123,10 +129,14 @@ module.exports = async (dbName='hipstagram') => {
             static get relations(){
                 return {
                     to: "incomings",
-                    attach: "directs",
+                    attach: ["directs"],
                     likes: "entity",
                 }
             }
+
+            static get guestRelations(){
+                return ["to", "likes"]
+            }
         }
         SlicedSavable.addClass(Direct)
 

+ 7 - 41
package-lock.json

@@ -425,12 +425,6 @@
       "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
       "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
     },
-    "memory-pager": {
-      "version": "1.5.0",
-      "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
-      "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==",
-      "optional": true
-    },
     "merge-descriptors": {
       "version": "1.0.1",
       "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
@@ -473,41 +467,31 @@
       }
     },
     "mm": {
-      "version": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git#dbedfd651d76b2f118c11e7f9a259f6b01245e69",
+      "version": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git#fa47de9ee1e6cd432579a1fbcbf7811a92ee20b7",
       "from": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git",
       "requires": {
         "mongodb": "^3.2.2"
       }
     },
     "mm-graphql": {
-      "version": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm-graphql.git#5d23ded7be133e4989c2a0776be6eafe68c78247",
+      "version": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm-graphql.git#8422b3e9e7e55923594e1095eea4a4ae2008187e",
       "from": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm-graphql.git",
       "requires": {
         "express": "^4.17.1",
         "express-graphql": "^0.9.0",
         "graphql": "^14.4.2",
         "jsonwebtoken": "^8.5.1",
-        "mm": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git#dbedfd651d76b2f118c11e7f9a259f6b01245e69"
+        "mm": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git#fa47de9ee1e6cd432579a1fbcbf7811a92ee20b7"
       }
     },
     "mongodb": {
-      "version": "3.2.7",
-      "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.2.7.tgz",
-      "integrity": "sha512-2YdWrdf1PJgxcCrT1tWoL6nHuk6hCxhddAAaEh8QJL231ci4+P9FLyqopbTm2Z2sAU6mhCri+wd9r1hOcHdoMw==",
-      "requires": {
-        "mongodb-core": "3.2.7",
-        "safe-buffer": "^5.1.2"
-      }
-    },
-    "mongodb-core": {
-      "version": "3.2.7",
-      "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.2.7.tgz",
-      "integrity": "sha512-WypKdLxFNPOH/Jy6i9z47IjG2wIldA54iDZBmHMINcgKOUcWJh8og+Wix76oGd7EyYkHJKssQ2FAOw5Su/n4XQ==",
+      "version": "3.3.2",
+      "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.3.2.tgz",
+      "integrity": "sha512-fqJt3iywelk4yKu/lfwQg163Bjpo5zDKhXiohycvon4iQHbrfflSAz9AIlRE6496Pm/dQKQK5bMigdVo2s6gBg==",
       "requires": {
         "bson": "^1.1.1",
         "require_optional": "^1.0.1",
-        "safe-buffer": "^5.1.2",
-        "saslprep": "^1.0.0"
+        "safe-buffer": "^5.1.2"
       }
     },
     "ms": {
@@ -628,15 +612,6 @@
       "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
       "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
     },
-    "saslprep": {
-      "version": "1.0.3",
-      "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz",
-      "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==",
-      "optional": true,
-      "requires": {
-        "sparse-bitfield": "^3.0.3"
-      }
-    },
     "semver": {
       "version": "5.7.0",
       "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz",
@@ -685,15 +660,6 @@
       "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
       "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
     },
-    "sparse-bitfield": {
-      "version": "3.0.3",
-      "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
-      "integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=",
-      "optional": true,
-      "requires": {
-        "memory-pager": "^1.0.2"
-      }
-    },
     "statuses": {
       "version": "1.5.0",
       "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",