Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sweep: allow to update the height of an already created rack (βœ“ Sandbox Passed) #109

Closed
13 changes: 13 additions & 0 deletions src/app/components/rack-parts/rack-detail-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ import {FormTypes} from "../../shared-interproject/components/@smart/mat-form-en

@Injectable()
export class RackDetailDataService extends SubManager {

updateRackHeight(newHeight: number): void {
const currentRackData = this.singleRackData$.value;
if (currentRackData) {
this.backend.update.rack({...currentRackData, height: newHeight}).subscribe({
next: updatedRack => {
this.singleRackData$.next(updatedRack);
this.snackBar.open('Rack height updated successfully', 'Close', { duration: 3000 });
},
error: () => this.snackBar.open('Failed to update rack height', 'Close', { duration: 3000 })
});
}
}
updateSingleRackData$ = new ReplaySubject<number>();
singleRackData$ = new BehaviorSubject<Rack | undefined>(undefined);
deleteRack$ = new Subject<RackMinimal>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { RackDetailDataService } from '../rack-detail-data.service';
changeDetection: ChangeDetectionStrategy.OnPush
})
export class RackDetailsComponent extends SubManager implements OnInit {
newHeight: number;
@Input() data: RackMinimal;

constructor(
Expand All @@ -28,3 +29,11 @@ export class RackDetailsComponent extends SubManager implements OnInit {


}
updateRackHeight(): void {
if (this.newHeight && this.data && this.data.id) {
this.backend.update.rack({ ...this.data, height: this.newHeight }).subscribe({
next: () => this.snackBar.open('Rack height updated successfully', 'Close', { duration: 3000 }),
error: () => this.snackBar.open('Failed to update rack height', 'Close', { duration: 3000 })
});
}
}
3 changes: 2 additions & 1 deletion src/app/features/backend/supabase.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,11 @@ export class SupabaseService {
);
// .pipe(tap(x => SharedConstants.showSuccessUpdate(this.snackBar)));
},
rack: (data: RackMinimal) => {
rack: (data: RackMinimal, height: number) => {
return rxFrom(
this.supabase.from(this.paths.racks)
.upsert({
height,
id: data.id,
authorid: data.author.id,
name: data.name,
Expand Down
Loading