Skip to content

Instantly share code, notes, and snippets.

View stveljko012's full-sized avatar
💭
Kaizen

Veljko Stanojevic stveljko012

💭
Kaizen
View GitHub Profile
@stveljko012
stveljko012 / typeorm-crud.service.ts
Created February 16, 2023 15:29
The abstraction of the CRUD service
export abstract class TypeormCrudService<T> {
readonly logger = new Logger(TypeormCrudService.name);
protected constructor(private _repository: Repository<T>) {}
async find(options?: FindManyOptions<T>): Promise<T[]> {
return await this._repository.find(options);
}
async findOne(options: FindOneOptions<T>): Promise<T | null> {
@Component({
selector: 'app-vehicle-edit',
templateUrl: './vehicle-edit.component.html',
styleUrls: ['./vehicle-edit.component.scss']
})
export class VehicleEditComponent implements OnInit {
vehicleEditForm: VehicleEditForm = new VehicleEditForm();
constructor(private vehiclesService: VehiclesService) { }
export class VehicleEditForm extends FormGroup {
get id(): string {
return this.controls.id.value;
}
get brand(): string {
return this.controls.brand.value;
}
export class VehicleEditForm extends FormGroup {
selectedFutureYear$: Observable<number> = this.controls.year.valueChanges.pipe(
filter((value: number) => value > (new Date()).getFullYear())
);
constructor() {
super({
id: new FormControl(null, Validators.compose([Validators.required])),
brand: new FormControl(null, Validators.compose([Validators.required])),
ngOnInit(): void {
this.vehiclesService.get().subscribe((data: Vehicle) => this.vehicleEditForm.setVehicle(data));
}
export class VehicleEditForm extends FormGroup {
constructor() {
super({
id: new FormControl(null, Validators.compose([Validators.required])),
brand: new FormControl(null, Validators.compose([Validators.required])),
type: new FormControl(null, Validators.compose([Validators.required])),
class: new FormControl(null, Validators.compose([Validators.required])),
year: new FormControl(null, Validators.compose([Validators.required])),
});
export class VehicleEditForm extends FormGroup {
constructor() {
super({
id: new FormControl(null, Validators.compose([Validators.required])),
brand: new FormControl(null, Validators.compose([Validators.required])),
type: new FormControl(null, Validators.compose([Validators.required])),
class: new FormControl(null, Validators.compose([Validators.required])),
year: new FormControl(null, Validators.compose([Validators.required])),
});
@Component({
selector: 'app-vehicle-edit',
templateUrl: './vehicle-edit.component.html',
styleUrls: ['./vehicle-edit.component.scss']
})
export class VehicleEditComponent implements OnInit {
vehicleEditForm: FormGroup = new FormGroup({
id: new FormControl(null, Validators.compose([Validators.required])),
brand: new FormControl(null, Validators.compose([Validators.required])),
export class DevekeeComponent {
devekeeForm: FormGroup = new FormGroup({
firstName: new FormControl(null),
lastName: new FormControl(null)
});
}