Merge pull request #482 from jdegand/eslint-backend-service

fix: better typing fake-db-service
This commit is contained in:
Laforge Thomas
2024-01-09 17:19:57 +01:00
committed by GitHub

View File

@@ -7,12 +7,14 @@ import { Injectable } from '@angular/core';
import { randNumber } from '@ngneat/falso'; import { randNumber } from '@ngneat/falso';
import { ComponentStore } from '@ngrx/component-store'; import { ComponentStore } from '@ngrx/component-store';
@Injectable({ providedIn: 'root' }) interface AppState {
export class FakeDBService extends ComponentStore<{
teachers: Teacher[]; teachers: Teacher[];
students: Student[]; students: Student[];
schools: School[]; schools: School[];
}> { }
@Injectable({ providedIn: 'root' })
export class FakeDBService extends ComponentStore<AppState> {
readonly teachers$ = this.select((state) => state.teachers); readonly teachers$ = this.select((state) => state.teachers);
readonly randomTeacher$ = this.select( readonly randomTeacher$ = this.select(
this.teachers$, this.teachers$,
@@ -35,33 +37,45 @@ export class FakeDBService extends ComponentStore<{
super({ teachers: [], students: [], schools: [] }); super({ teachers: [], students: [], schools: [] });
} }
addTeacher = this.updater((state, teacher: Teacher) => ({ addTeacher = this.updater(
...state, (state, teacher: Teacher): AppState => ({
teachers: [...state.teachers, teacher], ...state,
})); teachers: [...state.teachers, teacher],
}),
);
updateTeacher = this.updater((state, teacher: Teacher) => ({ updateTeacher = this.updater(
...state, (state, teacher: Teacher): AppState => ({
teachers: state.teachers.map((t) => (t.id === teacher.id ? teacher : t)), ...state,
})); teachers: state.teachers.map((t) => (t.id === teacher.id ? teacher : t)),
}),
);
addStudent = this.updater((state, student: Student) => ({ addStudent = this.updater(
...state, (state, student: Student): AppState => ({
students: [...state.students, student], ...state,
})); students: [...state.students, student],
}),
);
updateSudent = this.updater((state, student: Student) => ({ updateSudent = this.updater(
...state, (state, student: Student): AppState => ({
students: state.students.map((t) => (t.id === student.id ? student : t)), ...state,
})); students: state.students.map((t) => (t.id === student.id ? student : t)),
}),
);
addSchool = this.updater((state, school: School) => ({ addSchool = this.updater(
...state, (state, school: School): AppState => ({
schools: [...state.schools, school], ...state,
})); schools: [...state.schools, school],
}),
);
updateSchool = this.updater((state, school: School) => ({ updateSchool = this.updater(
...state, (state, school: School): AppState => ({
schools: state.schools.map((t) => (t.id === school.id ? school : t)), ...state,
})); schools: state.schools.map((t) => (t.id === school.id ? school : t)),
}),
);
} }