asmer@controller преди 5 години
родител
ревизия
30a0487cbe
променени са 3 файла, в които са добавени 32 реда и са изтрити 7 реда
  1. 8 1
      index.js
  2. 18 1
      models.js
  3. 6 5
      package-lock.json

+ 8 - 1
index.js

@@ -27,6 +27,8 @@ const upload  = require('multer')({ dest: uploadPath })
              likes: [Like]
              likesCount: Int
              incomings: [Direct]
+             followers: [User]
+             following: [User]
         }
 
         input UserInput {
@@ -34,6 +36,7 @@ const upload  = require('multer')({ dest: uploadPath })
              login: String
              nick : String
              avatar: ImageInput
+             following: [UserInput]
         }
 
         type Like {
@@ -174,6 +177,10 @@ const upload  = require('multer')({ dest: uploadPath })
     app.use(express.static('public'));
 
 
-    app.listen(4000, () => console.log('Express GraphQL Server Now Running On localhost:4000/graphql'));
+    let socketPath = "/home/asmer/node_hosts/hipstagram"
+    app.listen(socketPath, () => {
+        console.log('Express GraphQL Server Now Running On localhost:4000/graphql');
+        fs.chmodSync(socketPath, '777');
+    });
 })()
 

+ 18 - 1
models.js

@@ -14,15 +14,22 @@ module.exports = async (dbName='hipstagram') => {
                 //cached like count, which incremented and decremented
                 //
                 //following and followers array
+
             }
 
 
             static get relations(){ //don't needed due to ___owner in most cases
                 return {
                     avatar : "userAvatar",
-                    incomings: "to"
+                    incomings: "to",
+                    followers: ["following"],
+                    following: ["followers"],
                 }
             }
+
+            static get guestRelations(){
+                return ["followers"]
+            }
         }
         SlicedSavable.addClass(User)
 
@@ -60,6 +67,16 @@ module.exports = async (dbName='hipstagram') => {
 
             }
 
+            get likes(){
+                return (async () => {
+                    let result = []
+                    for (let like of SlicedSavable.m.Like.find({'post._id': this._id}, {limit: [100], sort: ['_id', 1]})){
+                        try {await like; result.push(like) } catch(e) {}
+                    }
+                    return result;
+                })()
+            }
+
 
             static get relations(){
                 return {

+ 6 - 5
package-lock.json

@@ -467,25 +467,26 @@
       }
     },
     "mm": {
-      "version": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git#fa47de9ee1e6cd432579a1fbcbf7811a92ee20b7",
+      "version": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git#f4aad46fcaf18d6f7cc79fc6335d5f9a68cda087",
       "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#8422b3e9e7e55923594e1095eea4a4ae2008187e",
+      "version": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm-graphql.git#56ee6226ac481eaa7869c6997006707c467d9f40",
       "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"
+        "jsonwebtoken": "^8.5.1",
+        "mm": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git"
       },
       "dependencies": {
         "mm": {
-          "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#fa47de9ee1e6cd432579a1fbcbf7811a92ee20b7",
+          "version": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git#f792da15d7a00091cd98840b352b6b526e2b57a1",
+          "from": "git+ssh://git@gitlab.a-level.com.ua:gitgod/mm.git",
           "requires": {
             "mongodb": "^3.2.2"
           }