Skip to content

Instantly share code, notes, and snippets.

@clayperez
Last active December 4, 2020 20:06
Show Gist options
  • Save clayperez/13f6ea593fe478b2dd5cd4fc640ec14b to your computer and use it in GitHub Desktop.
Save clayperez/13f6ea593fe478b2dd5cd4fc640ec14b to your computer and use it in GitHub Desktop.
Rhesus Model Setup
import { Model } from '@vuex-orm/core'
// FASTER UID
let count = 0
const myUid = () => ++count
export class Category extends Model {
static entity = 'categories'
static fields() {
return {
id: this.uid(() => myUid()),
displayName: this.attr(''),
relay: this.boolean(false),
categoryStartTime: this.number(0),
lapLimit: this.number(5),
mode: this.number(1),
entries: this.hasMany(Entry, 'category_id')
}
}
}
export class Entry extends Model {
static entity = 'entries'
static fields() {
return {
id: this.uid(() => myUid()),
category_id: this.attr(null),
team: this.attr(''),
starttime: this.number(0),
competitors: this.hasMany(Competitor, 'entry_id'),
segments: this.hasMany(Segment, 'entry_id')
}
}
}
export class Competitor extends Model {
static entity = 'competitors'
static fields() {
return {
id: this.uid(() => myUid()),
entry_id: this.attr(null),
first: this.attr(''),
last: this.attr(''),
bib: this.number(0)
}
}
}
export class Segment extends Model {
static entity = 'segments'
static fields() {
return {
id: this.uid(() => myUid()),
entry_id: this.attr(null),
bib: this.number(0),
lapStartTime: this.number(0),
lapEndTime: this.number(0),
sources: this.hasOne(TimeSource, 'segment_id')
}
}
}
export class TimeSource extends Model {
static entity = 'timeSources'
static fields() {
return {
id: this.uid(() => myUid()),
segment_id: this.attr(null),
method: this.attr(''),
db: this.number(0),
chip: this.number(0),
antenna: this.number(0),
readerTime: this.number(0),
readerName: this.attr('')
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment