2020-02-08 09:54:48 +00:00
|
|
|
const Model = require("flitter-orm/src/model/Model");
|
|
|
|
const { ObjectId } = require("mongodb");
|
2020-02-08 12:57:38 +00:00
|
|
|
const uuid = require('uuid/v4');
|
2020-02-08 09:54:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 {
|
2020-02-08 12:57:38 +00:00
|
|
|
UUID: {type: String, default: () => uuid()},
|
2020-02-08 09:54:48 +00:00
|
|
|
Name: String,
|
2020-02-08 12:57:38 +00:00
|
|
|
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],
|
2020-02-08 09:54:48 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
|
|
|
|
2020-02-08 12:57:38 +00:00
|
|
|
accessible_by(user, mode = 'view') {
|
|
|
|
return user.can(`page:${this.UUID}:${mode}`)
|
|
|
|
}
|
|
|
|
|
2020-02-08 09:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = Page;
|