Skip to content

Commit

Permalink
fix: Separate out patchModel to reduce duplication in model updates
Browse files Browse the repository at this point in the history
  • Loading branch information
romeonicholas committed Nov 29, 2023
1 parent f452815 commit d26dd6f
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions frontend/src/app/projects/models/service/model.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,38 @@ export class ModelService {
);
}

private patchModel(
projectSlug: string,
modelSlug: string,
patchData: PatchModel,
): Observable<Model> {
return this.http.patch<Model>(
`${this.base_url}${projectSlug}/models/${modelSlug}/`,
patchData,
);
}

updateModel(
projectSlug: string,
modelSlug: string,
patchModel: PatchModel,
): Observable<Model> {
return this.http
.patch<Model>(
`${this.base_url}${projectSlug}/models/${modelSlug}/`,
patchModel,
)
.pipe(
tap({
next: (model) => {
this.loadModels(projectSlug);
this._model.next(model);
},
}),
);
return this.patchModel(projectSlug, modelSlug, patchModel).pipe(
tap({
next: (model) => {
this.loadModels(projectSlug);
this._model.next(model);
},
}),
);
}

updateModels(
projectSlug: string,
modelUpdates: { modelSlug: string; patchModel: PatchModel }[],
): Observable<Model[]> {
const updateObservables = modelUpdates.map(({ modelSlug, patchModel }) =>
this.http.patch<Model>(
`${this.base_url}${projectSlug}/models/${modelSlug}/`,
patchModel,
),
this.patchModel(projectSlug, modelSlug, patchModel),
);

return forkJoin(updateObservables).pipe(
Expand Down

0 comments on commit d26dd6f

Please sign in to comment.