mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
34 schema files wrote the same two autoValue functions out by hand, 65 times in five spellings: createdAt set on insert and $setOnInsert on upsert, unset otherwise; modifiedAt set on every write. They are now createdAtAutoValue and modifiedAtAutoValue in models/lib/schemaTimestamps.js, named by each field as `autoValue: createdAtAutoValue`. models/settings.js, which may not use import statements, requires them. Schemas whose rule differs keep their own: changeHistory keeps a createdAt the caller set, and listSyncCredentials' updatedAt does not unset. tests/schemaTimestamps runs both functions in SimpleSchema's insert, upsert, update and validation contexts, and fails when a schema writes either one out by hand again. Thanks to xet7 !
63 lines
1.2 KiB
JavaScript
63 lines
1.2 KiB
JavaScript
import { Mongo } from 'meteor/mongo';
|
|
import { incrementCounter } from './counters';
|
|
import { createdAtAutoValue, modifiedAtAutoValue } from '/models/lib/schemaTimestamps';
|
|
const { SimpleSchema } = require('/imports/simpleSchema');
|
|
|
|
const OrgUser = new Mongo.Collection('orgUser');
|
|
|
|
/**
|
|
* 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('orgUserId', 1);
|
|
}
|
|
},
|
|
},
|
|
orgId: {
|
|
/**
|
|
* the organization id
|
|
*/
|
|
type: Number,
|
|
optional: true,
|
|
},
|
|
userId: {
|
|
/**
|
|
* 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,
|
|
autoValue: createdAtAutoValue,
|
|
},
|
|
modifiedAt: {
|
|
type: Date,
|
|
autoValue: modifiedAtAutoValue,
|
|
},
|
|
}),
|
|
);
|
|
|
|
export default OrgUser;
|