Przeglądaj źródła

add permission check

asmer@controller 6 lat temu
rodzic
commit
58d56f56a1
1 zmienionych plików z 34 dodań i 0 usunięć
  1. 34 0
      permission_test.js

+ 34 - 0
permission_test.js

@@ -0,0 +1,34 @@
+const MongoClient = require("mongodb").MongoClient;
+const ObjectID    = require("mongodb").ObjectID;
+const mm          = require('./mm.js')
+const delay       = ms => new Promise(r => setTimeout(r.bind(ms), ms))
+ 
+;(async () => {
+    const mongoClient = new MongoClient("mongodb://localhost:27017/", { useNewUrlParser: true });
+    const client      = await mongoClient.connect()
+    const db          = client.db('mm')
+    const Savable     = mm(db).Savable
+    const SlicedSavable = mm(db).sliceSavable([ObjectID("5c9571219be797377361c65a"), 'user', 'admin'])
+    //const SlicedSavable = mm(db).sliceSavable([])
+    //
+
+    class Notebook extends SlicedSavable{
+        static get relations(){
+            return {
+                owner: "notebook"
+            }
+        }
+    }
+
+    class User extends SlicedSavable{
+        static get relations(){
+            return {
+                children: "parent",
+                parent: "children",
+                friends: "friends",
+                notebook: "owner",
+            }
+        }
+    }
+    Savable.addClass(Notebook)
+