53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
|
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;
|