condition.ts 940 B

1234567891011121314151617181920212223242526272829
  1. import { Schema } from 'mongoose';
  2. import { ICondition } from '../../../interfaces/condition';
  3. import { GrowiServiceType } from '../../../interfaces/growi-info';
  4. import { UserType } from '../../../interfaces/user-info';
  5. const conditionSchema = new Schema<ICondition>({
  6. user: {
  7. types: [{ type: String, enum: Object.values(UserType) }],
  8. daysSinceCreation: {
  9. moreThanOrEqualTo: { type: Number, min: 0 },
  10. lessThanOrEqualTo: {
  11. type: Number,
  12. min: 0,
  13. validate: [
  14. function(value) {
  15. return this.user.daysSinceCreation.moreThanOrEqualTo == null || this.user.daysSinceCreation.moreThanOrEqualTo <= value;
  16. }, 'daysSinceCreation.lessThanOrEqualTo must be greater than moreThanOrEqualTo',
  17. ],
  18. },
  19. },
  20. },
  21. growi: {
  22. types: [{ type: String, enum: Object.values(GrowiServiceType) }],
  23. versionRegExps: [String],
  24. },
  25. });
  26. export default conditionSchema;