task #20 Added models for Node and Page.

This commit is contained in:
Thomas Atkins 2020-02-08 03:54:48 -06:00
parent b3f10bdaa8
commit db24c79c15
4 changed files with 111 additions and 0 deletions

5
.gitignore vendored
View File

@ -91,3 +91,8 @@ typings/
www*
www/**
### VScode stuff ###
.vscode*
.vscode/**

View File

@ -0,0 +1,33 @@
const Model = require("flitter-orm/src/model/Model");
const { ObjectId } = require("mongodb");
//custom
const NodeData = require("./NodeData.model");
/*
* Node Model
* -------------------------------------------------------------
* Put some description here!
*/
class Node extends Model {
static get schema() {
// Return a flitter-orm schema here.
return {
Type: String,
Value: NodeData,
PageId: ObjectId,
CreatedAt: { type: Date, default: () => new Date() },
UpdatedAt: { type: Date, default: () => new Date() },
CreatedUserId: { type: ObjectId },
UpdateUserId: { type: ObjectId }
};
}
// Static and instance methods can go here
get page() {
const Page = this.model.get("api:Page")
return this.belongs_to_one(Page, "PageId", "_id")
}
}
module.exports = exports = Node;

View File

@ -0,0 +1,21 @@
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

@ -0,0 +1,52 @@
const Model = require("flitter-orm/src/model/Model");
const { ObjectId } = require("mongodb");
/*
* Page Model
* -------------------------------------------------------------
* Put some description here!
*/
class Page extends Model {
static get services() {
return [...super.services, "models"];
}
static get schema() {
// Return a flitter-orm schema here.
return {
Name: String,
OrgUserId: ObjectId,
IsPublic: Boolean,
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 }
};
}
// Static and instance methods can go here
get user() {
const User = this.models.get("auth:User");
return this.belongs_to_one(User, "OrgUserId", "_id");
}
get nodes() {
const Node = this.models.get("api:Node");
return this.has_many(Node, "NodeIds", "_id");
}
get childPages() {
const Page = this.models.get("api:Page")
return this.has_many(Page, "ChildPageIds", "_id")
}
get parent() {
const Parent = this.models.get("api:Page")
return this.belongs_to_one(Parent, "ParentId", "_id")
}
}
module.exports = exports = Page;