summaryrefslogtreecommitdiffstats
path: root/models/orgUser.js
diff options
context:
space:
mode:
authorLauri Ojansivu <x@xet7.org>2019-07-15 23:23:09 +0300
committerLauri Ojansivu <x@xet7.org>2019-07-15 23:23:09 +0300
commit41950ba4de1f0028d4b34fc9a90899c288e87b90 (patch)
tree3649ca91f3e1ab99c5753d21f183939e432ce451 /models/orgUser.js
parent583f32e5c5233b1fe435dad23a95ee2872b7cc7c (diff)
downloadwekan-41950ba4de1f0028d4b34fc9a90899c288e87b90.tar.gz
wekan-41950ba4de1f0028d4b34fc9a90899c288e87b90.tar.bz2
wekan-41950ba4de1f0028d4b34fc9a90899c288e87b90.zip
Teams/Organizations part 3, in progress. Table: org_user, and indexes.
Thanks to xet7 ! Related #802
Diffstat (limited to 'models/orgUser.js')
-rw-r--r--models/orgUser.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/models/orgUser.js b/models/orgUser.js
new file mode 100644
index 00000000..42bd548c
--- /dev/null
+++ b/models/orgUser.js
@@ -0,0 +1,80 @@
+OrgUser = new Mongo.Collection('org_user');
+
+/**
+ * A Organization User in wekan
+ */
+OrgUser.attachSchema(
+ new SimpleSchema({
+ id: {
+ /**
+ * the organization user's id
+ */
+ type: Number,
+ optional: true,
+ // eslint-disable-next-line consistent-return
+ autoValue() {
+ if (this.isInsert && !this.isSet) {
+ return incrementCounter('counters', 'org_user_id', 1);
+ }
+ },
+ },
+ org_id: {
+ /**
+ * the organization id
+ */
+ type: Number,
+ optional: true,
+ },
+ user_id: {
+ /**
+ * the user id
+ */
+ type: Number,
+ optional: true,
+ },
+ role: {
+ /**
+ * the role of user
+ */
+ type: String,
+ optional: true,
+ max: 20,
+ },
+ createdAt: {
+ /**
+ * creation date of the organization user
+ */
+ type: Date,
+ // eslint-disable-next-line consistent-return
+ autoValue() {
+ if (this.isInsert) {
+ return new Date();
+ } else {
+ this.unset();
+ }
+ },
+ },
+ modifiedAt: {
+ type: Date,
+ denyUpdate: false,
+ // eslint-disable-next-line consistent-return
+ autoValue() {
+ if (this.isInsert || this.isUpsert || this.isUpdate) {
+ return new Date();
+ } else {
+ this.unset();
+ }
+ },
+ },
+ }),
+);
+
+if (Meteor.isServer) {
+ // Index for Organization User.
+ Meteor.startup(() => {
+ OrgUser._collection._ensureIndex({ org_id: -1 });
+ OrgUser._collection._ensureIndex({ org_id: -1, user_id: -1 });
+ });
+}
+
+export default OrgUser;