Source: collections.js

/**
Define region collection

@memberof module:collection
@const {module:database.CollectionSpec} REGION_COL
@example
// samples of region correct with specification
var regionEn = {id: 'en', name: 'English'}
var regionVi = {id: 'vi', name: 'Vietnameses'}
*/
const REGION_COL = {
  name: 'region',
  schema: {
    autoIndexId: false,
    validator: {
      $and: [
        {id: {$type: 'string', $regex: /^[a-z]{2}$/}},
        {name: {$type: 'string', $regex: /^[a-zA-Z0-9 ]{1,16}$/}}
      ]
    }
  },
  indexing: {
    keys: {id: 1},
    options: {unique: true}
  }
}

/**
Define account collection

@memberof module:collection
@const {module:database.CollectionSpec} ACCOUNT_COL
@example
// sample of an account correct with specification
var acccount = {
  _id: '57d80fd6888ad399dece8f72',
  name: 'kevin leptons',
  issuer: 'google',
  subject: '1234567890',
  groups: ['root'],
  scheduler: {},
  scheduler: [],
  language: 'en'
}
*/
const ACCOUNT_COL = {
  name: 'account',
  schema: {
    validator: {
      $and: [
        // oauth 2 properties
        {name: {$type: 'string', $regex: /^[a-zA-Z0-9 .-]{1,32}$/}},
        {issuer: {$type: 'string'}},
        {subject: {$type: 'string'}},

        // authorize properties
        {$or: [
          {groups: {$elemMatch: {$type: 'string', $regex: /^[a-z0-9]{1,8}$/}}},
          {groups: {$eq: []}}
        ]},

        // // setting properties
        {$or: [
          {scheduler: {$type: 'object'}},
          {scheduler: {$eq: null}}
        ]},
        {$or: [
          {schedulers: {$elemMatch: {$type: 'object'}}},
          {schedulers: {$eq: []}}
        ]},
        {language: {$type: 'string', $regex: /^[a-z]{2}$/}}
      ]
    }
  },
  indexing: {
    keys: {name: 1},
    options: {unique: true}
  }
}

/**
Define scheduler collection

@memberof module:collection
@const {module:database.CollectionSpec} SCHEDULER_COL
@example
// sample of an scheduler correct with specification
var scheduler = {
    "_id": "57d80fd6888ad399dece8f72",
    "name": "office work",
    "tags": ["work", "company", "fulltime", "office"],
    "notes": "for guy who have busy work in office",
    "tasks": [
        {"start": "05:00", "action": "get up and run"},
        {"start": "06:00", "action": "standby"},
        {"start": "06:15", "action": "take a shower"},
        {"start": "06:30", "action": "have breakfast"},

        {"start": "07:00", "action": "go to company"},
        {"start": "07:45", "action": "prepare working"},
        {"start": "08:00", "action": "research and development"},
        {"start": "10:00", "action": "relax"},

        {"start": "12:00", "action": "have a lunch"},
        {"start": "13:00", "action": "research and development"},
        {"start": "15:00", "action": "realax"},
        {"start": "15:15", "action": "research and development"},
        {"start": "17:30", "action": "go to home"},

        {"start": "18:15", "action": "take a shower"},
        {"start": "18:30", "action": "have a dinner"},
        {"start": "21:30", "action": "sleep"}
    ]
}
*/
const SCHEDULER_COL = {
  name: 'scheduler',
  schema: {
    validator: {
      $and: [
        {'author.id': {$type: 'objectId'}},
        {'author.name': {$type: 'string', $regex: /^[a-zA-Z0-9 .-]{1,32}$/}},
        {name: {$type: 'string', $regex: /^[a-zA-Z0-9 .-]{1,32}$/}},
        {tags: {$elemMatch: {$type: 'string', $regex: /^[a-zA-Z0-9 .-]{1,16}$/}}},
        {tasks: {$elemMatch: {$type: 'object'}}},
        {'tasks.start': {$type: 'string', $regex: /^[0-2][0-3]:[0-5][0-9]$/}},
        {'tasks.name': {$type: 'string', $regex: /^[a-zA-Z0-9 .-]{1,16}$/}},
        {notes: {$type: 'string', $regex: /^.{0,1024}$/}}
      ]
    }
  },
  indexing: {
    keys: {name: 1},
    options: {unique: true}
  }
}

/**
Contains specification of collection in database

@exports collection
@author kevin leptons <kevin.leptons@gmail.com>
*/
module.exports = [REGION_COL, ACCOUNT_COL, SCHEDULER_COL]