update ORM, refactor models, add Page API endpoints

This commit is contained in:
garrettmills
2020-02-08 06:57:38 -06:00
parent 7f832c0d92
commit 26d6bf5721
8 changed files with 108 additions and 93 deletions

View File

@@ -1,8 +1,5 @@
const Model = require("flitter-orm/src/model/Model");
const { ObjectId } = require("mongodb");
//custom
const NodeData = require("./NodeData.model");
const uuid = require('uuid/v4');
/*
* Node Model
@@ -13,13 +10,17 @@ class Node extends Model {
static get schema() {
// Return a flitter-orm schema here.
return {
UUID: { type: String, default: () => uuid() },
Type: String,
Value: NodeData,
PageId: ObjectId,
CreatedAt: { type: Date, default: () => new Date() },
UpdatedAt: { type: Date, default: () => new Date() },
CreatedUserId: { type: ObjectId },
UpdateUserId: { type: ObjectId }
Value: {
Mode: {type: String, default: 'norm'},
Value: String,
},
PageId: String,
CreatedAt: { type: Date, default: () => new Date },
UpdatedAt: { type: Date, default: () => new Date },
CreatedUserId: String,
UpdateUserId: String
};
}

View File

@@ -1,21 +0,0 @@
const Model = require("flitter-orm/src/model/Model");
/*
* NodeData Model
* -------------------------------------------------------------
* Put some description here!
*/
class NodeData extends Model {
static get schema() {
// Return a flitter-orm schema here.
return {
// Will add
Mode: { type: String, default: "norm" }, //Select the value (norm = string)
Value: String
};
}
// Static and instance methods can go here
}
module.exports = exports = NodeData;

View File

@@ -1,5 +1,6 @@
const Model = require("flitter-orm/src/model/Model");
const { ObjectId } = require("mongodb");
const uuid = require('uuid/v4');
/*
* Page Model
@@ -13,17 +14,18 @@ class Page extends Model {
static get schema() {
// Return a flitter-orm schema here.
return {
UUID: {type: String, default: () => uuid()},
Name: String,
OrgUserId: ObjectId,
IsPublic: { type: Boolean, default: true },
IsVisibleInMenu: { type: Boolean, default: true },
ParentId: ObjectId,
NodeIds: [ObjectId],
CreatedAt: { type: Date, default: () => new Date() },
UpdatedAt: { type: Date, default: () => new Date() },
CreatedUserId: { type: ObjectId },
UpdateUserId: { type: ObjectId },
ChildPageIds: { type: ObjectId }
OrgUserId: String,
IsPublic: {type: Boolean, default: true},
IsVisibleInMenu: {type: Boolean, default: true},
ParentId: String,
NodeIds: [String],
CreatedAt: {type: Date, default: () => new Date},
UpdatedAt: {type: Date, default: () => new Date},
CreatedUserId: {type: String},
UpdateUserId: {type: String},
ChildPageIds: [String],
};
}
@@ -47,6 +49,10 @@ class Page extends Model {
return this.belongs_to_one(Parent, "ParentId", "_id")
}
accessible_by(user, mode = 'view') {
return user.can(`page:${this.UUID}:${mode}`)
}
}
module.exports = exports = Page;