umpires can be added to courts as umpires (removal also)
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CourtServiceJudgeService } from './court.service.judge.service';
|
||||
|
||||
describe('CourtServiceJudgeService', () => {
|
||||
let service: CourtServiceJudgeService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(CourtServiceJudgeService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { toSignal } from '@angular/core/rxjs-interop';
|
||||
import { CourtServiceJudge, db } from 'db';
|
||||
import { liveQuery } from 'dexie';
|
||||
import { from } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CourtServiceJudgeService {
|
||||
/**
|
||||
* All service judges (reactive)
|
||||
*/
|
||||
readonly umpires = toSignal(
|
||||
from(liveQuery(() => db.courtServiceJudges.orderBy('courtNo').toArray())),
|
||||
{ initialValue: [] }
|
||||
);
|
||||
|
||||
/**
|
||||
* Get by court number (reactive)
|
||||
*/
|
||||
getByCourtNo(courtNo: number) {
|
||||
return toSignal<CourtServiceJudge | undefined>(
|
||||
liveQuery(() =>
|
||||
db.courtServiceJudges.where('courtNo').equals(courtNo).first()
|
||||
),
|
||||
{ initialValue: undefined }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create / update
|
||||
*/
|
||||
async save(item: Omit<CourtServiceJudge, 'id'>): Promise<number> {
|
||||
return db.courtServiceJudges.add(item as CourtServiceJudge);
|
||||
}
|
||||
|
||||
async update(
|
||||
id: number,
|
||||
changes: Partial<CourtServiceJudge>
|
||||
): Promise<number> {
|
||||
return db.courtServiceJudges.update(id, changes);
|
||||
}
|
||||
|
||||
async delete(id: number): Promise<void> {
|
||||
await db.courtServiceJudges.delete(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CourtUmpireService } from './court.umpire.service';
|
||||
|
||||
describe('CourtUmpireService', () => {
|
||||
let service: CourtUmpireService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(CourtUmpireService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { toSignal } from '@angular/core/rxjs-interop';
|
||||
import { CourtUmpire, db } from 'db';
|
||||
import { liveQuery } from 'dexie';
|
||||
import { from } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CourtUmpireService {
|
||||
/**
|
||||
* All court umpires (reactive)
|
||||
*/
|
||||
readonly umpires = toSignal(
|
||||
from(liveQuery(() => db.courtUmpires.orderBy('courtNo').toArray())),
|
||||
{ initialValue: [] }
|
||||
);
|
||||
|
||||
/**
|
||||
* Get by court number (reactive single)
|
||||
*/
|
||||
getByCourtNo(courtNo: number) {
|
||||
return toSignal<CourtUmpire | undefined>(
|
||||
liveQuery(() => db.courtUmpires.where('courtNo').equals(courtNo).first()),
|
||||
{ initialValue: undefined }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create / update
|
||||
*/
|
||||
async save(item: Omit<CourtUmpire, 'id'>): Promise<number> {
|
||||
return db.courtUmpires.add(item as CourtUmpire);
|
||||
}
|
||||
|
||||
async update(id: number, changes: Partial<CourtUmpire>): Promise<number> {
|
||||
return db.courtUmpires.update(id, changes);
|
||||
}
|
||||
|
||||
async delete(id: number): Promise<void> {
|
||||
await db.courtUmpires.delete(id);
|
||||
}
|
||||
|
||||
async removeByUmpireId(umpireId: number): Promise<void> {
|
||||
const item = await db.courtUmpires
|
||||
.where('umpireId')
|
||||
.equals(umpireId)
|
||||
.first();
|
||||
|
||||
if (!item?.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
await db.courtUmpires.delete(item.id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user