Mock repository update

This commit is contained in:
nemunaire 2022-09-04 23:54:10 +02:00
commit 8d9245f1b1
3 changed files with 33 additions and 3 deletions

View file

@ -33,7 +33,7 @@
}, (error) => {
submitInProgress = false;
ToastsStore.addErrorToast({
msg: "Une erreur s'est produite durant l'envoi de votre clef : " + error,
msg: "Une erreur s'est produite durant la création de la liaison au dépôt : " + error,
});
});
}
@ -59,7 +59,7 @@
type="button"
class="btn btn-outline-info float-end mb-1"
disable={submitInProgress || readonly}
on:click={() => repo.delete().then(() => { refresh_repo_work() })}
on:click={() => repo.retrieveWork().then(() => { refresh_repo_work() }, (error) => ToastsStore.addErrorToast({msg: "Une erreur s'est produite : " + error}))}
>
Mettre à jour
</button>
@ -67,7 +67,7 @@
type="button"
class="btn btn-outline-danger float-end mt-1"
disable={submitInProgress || readonly}
on:click={() => repo.delete().then(() => { refresh_repo_work() })}
on:click={() => repo.delete().then(() => { refresh_repo_work() }, (error) => ToastsStore.addErrorToast({msg: "Une erreur s'est produite durant la suppression du lien : " + error}))}
>
Supprimer cette liaison
</button>

View file

@ -25,6 +25,20 @@ export class WorkRepository {
}
}
async retrieveWork() {
const res = await fetch(`api/repositories/${this.id}/trigger`, {
method: 'POST',
headers: {'Accept': 'application/json'}
});
if (res.status == 200) {
const data = await res.json();
this.update(data);
return data;
} else {
throw new Error((await res.json()).errmsg);
}
}
async save() {
const res = await fetch(this.id?`api/repositories/${this.id}`:'api/repositories', {
method: this.id?'PUT':'POST',