File size: 1,572 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Entity } from './entity.ts'
import { GraphQL } from './graphql.ts'
import {
  randDate,
  randInt,
  randPickOne,
  randSample,
  randString,
  randTimeZone,
} from './rand.ts'

type RotationType = 'daily' | 'weekly' | 'hourly'

export type RotationParams = {
  name: string
  description: string
  timeZone: string
  type: RotationType
  shiftLength: number
  start: string
  userIDs: string[]
}

export class Rotation extends Entity {
  constructor(gql: GraphQL, id: string) {
    super(gql, 'rotation', id)
  }

  static randParams(gql: GraphQL): RotationParams {
    return {
      name: randString(50),
      description: randString(128),
      timeZone: randTimeZone(),
      type: randPickOne(['daily', 'weekly', 'hourly']),
      shiftLength: randInt(1, 24),
      start: randDate().toISOString(),
      userIDs: randSample(gql.users, 20).map((u) => u.id),
    }
  }

  public get timeZone(): string {
    return this.getField('timeZone') as string
  }

  public set timeZone(value: string) {
    this.setField('timeZone', value)
  }

  public get type(): RotationType {
    return this.getField('type') as RotationType
  }

  public set type(value: RotationType) {
    this.setField('type', value, 'RotationType')
  }

  public get shiftLength(): number {
    return this.getField('shiftLength') as number
  }

  public set shiftLength(value: number) {
    this.setField('shiftLength', value)
  }

  public get start(): string {
    return this.getField('start') as string
  }

  public set start(value: string) {
    this.setField('start', value)
  }
}