task #20 Added models for Node and Page.
This commit is contained in:
parent
b3f10bdaa8
commit
db24c79c15
5
.gitignore
vendored
5
.gitignore
vendored
@ -91,3 +91,8 @@ typings/
|
||||
|
||||
www*
|
||||
www/**
|
||||
|
||||
|
||||
### VScode stuff ###
|
||||
.vscode*
|
||||
.vscode/**
|
33
app/models/api/Node.model.js
Normal file
33
app/models/api/Node.model.js
Normal 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;
|
21
app/models/api/NodeData.model.js
Normal file
21
app/models/api/NodeData.model.js
Normal 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;
|
52
app/models/api/Page.model.js
Normal file
52
app/models/api/Page.model.js
Normal 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;
|
Loading…
Reference in New Issue
Block a user